#!usr/bin/perl
######################################################################
#
#Ian Odell
#Search fasta file for seq with max duplicates
#
######################################################################

use strict;
use warnings;
use Bio::SeqIO;

my $inputfilename = "2_type1unique_notaligned.fasta";

my $in  = Bio::SeqIO->new(-file => $inputfilename);

my $maxname;
my $maxnumber;
my $dupnum;
my $id;
while ( my $seq = $in->next_seq() ) {
  $id = $seq->id;
  #print "$id\n";
  $dupnum = substr($id, rindex($id, '_')+1);
  #print "$dupnum\n";
  if ($dupnum > $maxnumber){
    $maxnumber = $dupnum;
    $maxname = $id;
  }
}
print "$maxname\n$maxnumber\n";

#rindex(STRING, SUBSTRING, POSITION) -- Returns the position of the last occurrence of SUBSTRING in STRING at or after POSITION. If you don't specify POSITION, the search starts at the end of STRING

#substr(STRING, OFFSET, LENGTH) -- Returns a portion of STRING as determined by the OFFSET and LENGTH parameters. If LENGTH is not specified, then everything from OFFSET to the end of STRING is returned. A negative OFFSET can be used to start from the right side of STRING
