title: get sequence length from each different organism - genbank file
body: <p>I'd like to get the max, min and average length from a genbank file containing different organisms types, I'd like to get this for every organism. </p>
  
  <p>Example:</p>
  
  <pre><code>Organism: Homo sapiens
  average length = 160 
  shortest length = 20 | id of shortest seq
  longest length = 500 | id of longest seq
  
  Organism: Caenorhabditis elegans
  average length = 140 
  shortest length = 40 | id of shortest seq
  longest length = 300 | id of longest seq
  </code></pre>
  
  <p>I managed to get the lengths but I can't separate them by organism</p>
  
  <pre><code>use strict;
  use warnings;
  
  print "enter file path: ";
  my $filename = &lt;&gt;;
  chomp ($filename);
  open(IN, $filename) or die "\n error opening file \n;/\n";
  
  $/ = "//";
  
  my %organisms ;
  while (my $block = &lt;IN&gt;)  {
      next if $block =~ /^\s*\n\s*$/;
      my ($definition , $sequence) = split "ORIGIN", $block; 
  
      my $accession; 
      $definition =~ m/(ACCESSION.+[0-9])/x
          ? $accession = $1
          : die "No ACCESSION";
  
      my $organism;
      $definition =~ m/(ORGANISM\s+.+\n)/x
          ? $organism = $1
          : die "No ORGANISM";
  
  
      $sequence =~ s/[\d\n\s\t\/]//g;
      $organisms{ $sequence } = [ $organism, $accession ];
      }
  
  my $sum = 0;
  foreach my $sequence( keys %organisms) {
  
      my $current_len = length($sequence);
           $sum += $current_len;
  };
  my $number_seqs = scalar keys %organisms;
  my $average = ($sum / $number_seqs);
  print "average length = $average \n";
  
  my @sorted_keys = sort { length $a  &lt;=&gt;  length $b } keys %organisms ;
  my $shortest = $sorted_keys[0];
  my $longest  = $sorted_keys[-1];
  my $short = length $shortest;
  my $long = length $longest;
  my $short_id = $organisms{$shortest}-&gt;[1];
  my $long_id = $organisms{$longest}-&gt;[1];
  my $short_type = $organisms{$shortest}-&gt;[0];
  my $long_type = $organisms{$longest}-&gt;[0];
  
  print "shortest length = $short | $short_id | $short_type\n";
  print "longest length = $long | $long_id | $long_type\n";
  
  
  exit;
  </code></pre>
  
  <p>Which part should I change to print the lengths for each organism?</p>
  
  <p>input example:</p>
  
  <pre><code>LOCUS       NM_001112            40 bp    mRNA    linear   PRI 20-AP
  DEFINITION  Homo sapiens transcript variant 5, mRNA.
  ACCESSION   NM_001112
  KEYWORDS    RefSeq.
  SOURCE      Homo sapiens (human)
    ORGANISM  Homo sapiens
  ORIGIN      
          1 actgggcggc ccttagaccc
         //
  LOCUS       NM_854               212 bp    mRNA    linear   PRI 20-AP
  DEFINITION  Homo sapiens transcript variant 1, mRNA.
  ACCESSION   NM_854
  KEYWORDS    RefSeq.
  SOURCE      Homo sapiens (human)
    ORGANISM  Homo sapiens
  ORIGIN      
          1 gggcaaaag aagcaggtca cacagcctgt ttcctgtttt caaacgggga acttagaaag
  
  //
  LOCUS       AW057463                 469 bp    mRNA    linear   EST 29-SE
  DEFINITION  ca03d09.x1 C elegans fem3 Q23 S1 Caenorhabditis elegans cDNA 3'
  ACCESSION   AW057463
  VERSION     AW057463.1  GI:5933102
  DBLINK      BioSample: LIBEST_002392
  KEYWORDS    EST.
  SOURCE      Caenorhabditis elegans
    ORGANISM  Caenorhabditis elegans
  ORIGIN      
          1 ttttactcaa aactatctat ccaagttaat cagtagtgtt agttctagtt aagttattaa
         61 ggcgcacggt ctgtctcctt gcttcttctc tttgtatccc ctttctcctt tttcaaaact
        121 tcactttcat caataattgg ttctttagaa tacagttttc caatttccac gtactctctt
        181 ctcttccgat ccttgtcaaa ctttttcttc gggagctcat cttctggaac tactttcaca
  //
  LOCUS       AW04463                 259 bp    mRNA    linear   EST 14-SE
  DEFINITION  ca02d86.x1 C elegans fem6 S12 Q3 Caenorhabditis elegans cDNA 3'
  ACCESSION   AW04463
  VERSION     AW04463.1  GI:90872
  DBLINK      BioSample: LIBEST_004372
  KEYWORDS    EST.
  SOURCE      Caenorhabditis elegans
    ORGANISM  Caenorhabditis elegans
  ORIGIN      
        241 tttttcgatg gaaccaaacg ggaacgagtt ggcttttcca ccaaaagatt agcgtactcc
        301 gaactgtatt tccccttctt tttcttttca agaggaacat tttctcgttg agtatcatcg
        361 tcctccaaac tttgttgagt agtcatggac tgggtccgag agaattcaac ggtaggcatg
        421 gaacctttgc tcttgtcgtc gtttgccttt ggtgcctttc ccttttgaa
  //
  </code></pre>