Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

perlkhan 77

by perlkhan77 (Acolyte)
on Apr 22, 2009 at 11:14 UTC ( [id://759243]=perlquestion: print w/replies, xml ) Need Help??

perlkhan77 has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: perlkhan 77
by dHarry (Abbot) on Apr 22, 2009 at 11:45 UTC

    Your code is full of mistakes/"sins". If you want to work with fasta files please take a look at fasta on CPAN. It might be a better idea to use an existing module to work with fasta files than to roll your own.

    Some general comments:

    • check for the success of open, don't assume everything is fine.
    • use the the 3-arg form of open, see open.
    • put use strict; and use warnings; in your code. It would catch most of the errors in your script.

Re: perlkhan 77
by marto (Cardinal) on Apr 22, 2009 at 11:19 UTC

    Where is the question? You have just posted some Perl code, no description of the problem, your input or your output.

    The question title is just your user name, and not descriptive of your problem, and your closing code tag should be </code> and not <code>.

    Please read Writeup Formatting Tips and How do I post a question effectively?.

    Martin

Re: perlkhan 77
by apl (Monsignor) on Apr 22, 2009 at 12:06 UTC
    In addition to the earlier comments, I'd suggest changing (as an example)
    $count_G = ( $seq =~ tr/G//); $ratio_G = ($count_G/$len); # print "\n$ratio_G\n";
    to
    $ratio_G = Calculate( 'G' );
    Writing the sub Calculate is left as an exercise to the reader. The advantages are you
    • get rid of all of the temporary $count_* variables
    • remove duplicated code
    • make future changes (e.g. you want percentage rather than ratio) more centralized
    • make the intentions of your code much clearer
      sub Passref { my ( $define, $seq, $count, $outfh ) = @_; chomp($define); my $len = length($$seq); my %count = ( Miss => 0+( $$seq =~ m/^YCWLPHQIMTNKSRVADEGF/ig ) ); # YCWLPHQIMTNKSRVADEGF doesn't appear in test file my %ratio = ( Miss => 0+( $count{Miss} / $len ) ); for my $letter (qw[ E D A V R S K N T M I Q H P L W C Y F ]) { $count{$letter} = ( $$seq =~ m/$letter/g ); $ratio{$letter} = $count{$letter} / $len; } print {$outfh} join "\t", $define, $len, @ratio{qw[ E D A V R S K N T M I Q H P L W C Y F Miss ]}, "\n"; }
        For count you need
        $count{$letter} = ()= $$seq =~ m/$letter/g;
Re: perlkhan 77
by perliff (Monk) on Apr 24, 2009 at 07:47 UTC
    People have raised several issues in your code already, I will not repeat them, but will add some more that may be of help. You are much better off using Bioperl to read fasta files. You will be able to do much more and easily with bioperl. And as another gentle piece of advice is to learn ( say from this site or the Bioperl site ) on how to format your code so it doesnt look like its being pressed against a wall. People like to see lean code... but not lean in the way you have here...
    ----------------------

    "with perl on my side"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://759243]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-03-19 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found