CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions:
newbie urgent trouble

 



Nieljk
New User

May 7, 2002, 8:47 PM

Post #1 of 2 (3785 views)
newbie urgent trouble Can't Post

Mad
i have a program to hand in on friday and it's causing me trouble, i'm a uni student, the following pice of code should take a file of FASTA format i.e.
>a header line like this | and data lines underneath
rkfjsnrevkjnaesveiw
weciywubecuyweij
rkmwefkpwewcewe
i need to ignore the header line, then create a newline wherever there is a r or a k as long as they are not followed by a p, it's for protein analysis, my current code is:
sub perform_a_protein_digest {

open (FILE, $filename)
or die "File in storage could not be opened, check to see if it exists";


@peps = <FILE>;
print "$filename\n\n";
print @peps;
$peps = join( '', @peps);
$peps =~ s/\s//g;

unless ($peps =~ m/ kr | kp | KR | KP /){
$peps =~ s/r\/r\n//g;
}

@peps = split( '',$peps);
print @peps;
print "Please enter the name of the file you wish to write the results to:\n\n";
$writefile = <STDIN>;
chomp $writefile;
open (OPENFILE, ">$writefile"); # OPENS A FILE TO BR WRITTEN TOO.
print OPENFILE @peps;
close(OPENFILE); #CLOSES THE FILE THAT WAS WRITTEN TOO

}#ENDS THE SUBROUTINE FOR PERFORMING A PROTEIN DIGEST

any help would be greatly appreciated, i really reall need it, if you can get hold of me on MSN messenger my email is nieljk@hotmail.com, if you want me on ICQ my number is 159508070, thanksUnsure


fashimpaur
User

May 9, 2002, 7:28 AM

Post #2 of 2 (3774 views)
Re: [Nieljk] newbie urgent trouble [In reply to] Can't Post

Nieljk,

Here is my solution:


Code
    

# YOUR CODE :


#open (FILE, $filename)
#or die "File in storage could not be opened, check to see if it exists";
#
#
#@peps = <FILE>;
#print "$filename\n\n";
#print @peps;
#$peps = join( '', @peps);
#$peps =~ s/\s//g;
#
#unless ($peps =~ m/ kr | kp | KR | KP /){
#$peps =~ s/r\/r\n//g;
#}

# Modify your code to look like this:

# uncomment next 2 lines
#sub perform_a_protein_digest {
#open (FILE, $filename) or die "File in storage could not be opened, check to see if it exists";

# comment out next line
@peps = <DATA>;

# uncomment next 2 lines
#@peps = <FILE>;
#close FILE;

print "$filename\n\n";
print @peps;
$peps = join( '', @peps);
$peps =~ s/\s//g;

$peps =~ s/(k|r)(?!p)/\n/gi;

print $peps;

# These lines were unnecessary
#@peps = split( '',$peps);
#print @peps;

# uncomment next block for use in your subroutine
#print "Please enter the name of the file you wish to write the results to:\n\n";
#$writefile = <STDIN>;
#chomp $writefile;
#open (OPENFILE, ">$writefile"); # OPENS A FILE TO BR WRITTEN TOO.
#print OPENFILE @peps;
#close(OPENFILE); #CLOSES THE FILE THAT WAS WRITTEN TOO
#print "File Saved Successfully!\n";
#}

__DATA__

rkfjsnrevkjnaesveiw
weciywubecuyweij
rkmwefkpwewcewe

Added Output Here:


Quote


rkfjsnrevkjnaesveiw
weciywubecuyweij
rkmwefkpwewcewe





fjsn
ev
jnaesveiwweciywubecuyweij

mwefkpwewcewe


Also, fixed regex. First solution display was from wrong copy of test script.
This one works.

Let me know if I misunderstood the requirements.
Dennis

$a="c323745335d3221214b364d545".
"a362532582521254c3640504c3729".
"2f493759214b3635554c3040606a0",
print unpack"u*",pack "h*",$a,"\n\n";


(This post was edited by fashimpaur on May 9, 2002, 8:12 AM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives