Hi List,

I have been trying to follow one of code indentation guidelines from
wikipedia, but I have some questions that I can find answers, I would
appreciate if someone could help me or point me towards better references.


So here is something I have been working on:

-------------------------------Code------------------------------------------------

use strict;

my $seqnum = 0;
my @seq;
my @seqheader;
my @targets;
my $index = 0;
my $index1 = -1;

#Here we open the filehandle TARGETS to connect to the file containing the
names of the sequences we want to find.

open(TARGETS, "<$ARGV[0]");

@targets = <TARGETS>;

#Just printing the sequences we are looking for.

print "We are looking for:\n";

foreach (@targets)
{
    print "\n$_";
}

As I understand I am supposed to align the start curly brace opening the
loop with the one closing, so I did it here. My first question is: should I
everything from now on be indented forward or should be aligned to the left?

close (TARGETS);

#Here we use the subroutine readFasta to read the FASTA file and store the
names in the array @seqheader and the sequences in the array @seq.

readFasta($ARGV[1]);

print "\nThere are $seqnum sequences in FASTA file\n";

print "\nWe found:\n\n";

#Here is where we interate the @seqheader array looking for the names we
wanted

The second question is the same as the first really: when I start a second
loop, should I indent it even further to the right?

foreach my $seqheaders(@seqheader)
{
    $index1 = $index1 + 1;
    if (grep {$seqheaders =~ /$_/} @targets)
      {
         print "$seqheaders\n";
         print "$seq[$index1]\n";
         $index = $index + 1;

      }
    next;
}



sub readFasta
{
    my $line;
    my $first;
    if (@ARGV == 0){
      die "No FASTA file specified.\n"
    }
    open(FILE, "<@_[0]");
    $seqnum = 0;
    $first = 0;
    while (defined($line = <FILE>))
    {
        chomp($line);
        if ($line =~ /^>/)
        {
          $seqheader[$seqnum] = $line;
          $seqnum = $seqnum + 1;
          if ($first == 0)
          {
                $first = 1;
          }
            next;
        }
        if ($first == 0){

                  die "Not a standard FASTA file. Stop.\n";
                         }

            $seq[$seqnum - 1] = $seq[$seqnum - 1] .$line;
    }
    close(FILE);
}




-- 
"Education is not to be used to promote obscurantism." - Theodonius
Dobzhansky.

"Gracias a la vida que me ha dado tanto
Me ha dado el sonido y el abecedario
Con él, las palabras que pienso y declaro
Madre, amigo, hermano
Y luz alumbrando la ruta del alma del que estoy amando

Gracias a la vida que me ha dado tanto
Me ha dado la marcha de mis pies cansados
Con ellos anduve ciudades y charcos
Playas y desiertos, montañas y llanos
Y la casa tuya, tu calle y tu patio"

Violeta Parra - Gracias a la Vida

Tiago S. F. Hori
PhD Candidate - Ocean Science Center-Memorial University of Newfoundland

Reply via email to