Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Issues regarding for loops and recursion

by Corion (Patriarch)
on Jan 09, 2023 at 12:44 UTC ( [id://11149456]=note: print w/replies, xml ) Need Help??


in reply to Issues regarding for loops and recursion

Hi Nickmofoe, and welcome to Perl!

if ($_=~m/^ATOM\s+\d+\s+\w+\s+\w+\s+\w+\d+\s+(\S+)\s+(\S+)\s+(\S+)/){

Here you match against $_, but it was never set. Did you want to match against $seq? I'm not sure.

Some general stylistic things:

open (IN, '6U9D.pdb.txt');

You should check whether opening the file actually succeeded:

my $filename = '6U9D.pdb.txt'; open (IN, $filename) or die "Couldn't open '$filename': $!";

You should use the strict pragma. This requires you to declare all variables but on the upside, it allows Perl to tell you about typos in your variable names.

When assigning the %amino_acid_conversion, you could use newlines to make the code a bit more readable:

%amino_acid_conversion = ( ALA=>'A', TYR=>'Y', MET=>'M', LEU=>'L', CYS=>'C', GLY=>'G', ARG=>'R', ASN=>'N', ASP=>'D', GLN=>'Q', GLU=>'E', HIS=>'H', TRP=>'W', LYS=>'K', PHE=>'F', PRO=>'P', SER=>'S', THR=>'T', ILE=>'I', VAL=>'V' );

Replies are listed 'Best First'.
Re^2: Issues regarding for loops and recursion
by hippo (Bishop) on Jan 09, 2023 at 13:32 UTC
    When assigning the %amino_acid_conversion, you could use newlines to make the code a bit more readable

    Completely agree. I'd go even further and put whitespace around the fat commas and with so many entries I would sort by either key or value to make it easier to spot misses/dupes/typos.

    %amino_acid_conversion = ( ALA => 'A', ARG => 'R', ASN => 'N', ASP => 'D', CYS => 'C', GLN => 'Q', GLU => 'E', GLY => 'G', HIS => 'H', ILE => 'I', LEU => 'L', LYS => 'K', MET => 'M', PHE => 'F', PRO => 'P', SER => 'S', THR => 'T', TRP => 'W', TYR => 'Y', VAL => 'V' );

    🦛

Re^2: Issues regarding for loops and recursion
by Fletch (Bishop) on Jan 09, 2023 at 17:53 UTC

    Another initialization readability trick is to use YAML in a HEREDOC which gets you (IMHO) less "noise" to initializing data:

    use YAML::XS qw( Load ); my %conversions = %{Load(<<'EOT')}; --- ALA: A TYR: Y MET: M ... EOT

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (7)
As of 2024-04-23 12:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found