Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: PROTEIN FILE help me pleaseee

by Kenosis (Priest)
on Jan 30, 2013 at 16:59 UTC ( #1016101=note: print w/replies, xml ) Need Help??

in reply to PROTEIN FILE help me pleaseee

You've been given excellent suggestions (!):

  • choroba shows the three-argument open, including using lexically-scoped variables (don't use global variables for file opens).
  • 2teez shows a crucial first step: always use strict; use warnings;
  • pvaldes imparted a hint on counting the number of "F"s in the sequence

Not to confuse matters here, but for your future reference (since you appear to be on a bioinformatics path), consider becoming well acquainted with Bio::SeqIO and its set of related modules.

Just as there are well-developed modules to parse HTML, XML, and CSV files, Bio::SeqIO lives to do the same for Fasta and other such formats.

For example, to retrieve and process each sequence within a Fasta file, you can do the following:

use strict; use warnings; use Bio::SeqIO; print "Please type the file name of the protein sequence data: "; chomp( my $proteinfilename = <STDIN> ); print "\n"; my $fastaIN = Bio::SeqIO->new( -file => $proteinfilename, -format => ' +Fasta' ); while ( my $seq = $fastaIN->next_seq() ) { print $seq->seq, "\n"; }

Each sequence in the Fasta file is accessible using the $seq->seq notation. The first part before the arrow operator is the sequence object; the part after the arrow operator is the method. These methods are covered in detail in the Bio::Seq module's documentation. In the example above, the sequence is printed, but a character count could be done there, too.

Hope this helps!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1016101]
and the grasshoppers chirp...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2018-06-21 00:06 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.