#!/usr/bin/perl -w
use strict;

my $filename = "Swissprot.dat";
my @accnr;
my $countonly = 0;

# Loop until the @ARGV array is empty
while ( @ARGV ) {
   my $arg = shift @ARGV;
   if ( $arg eq "-f" ) {
      $filename = shift @ARGV;
   }
   elsif ( $arg eq "-c" ) {
      $countonly = 1;
   }
   else {
      push @accnr, $arg;
   }
}

my $mode = '<';
if ( $filename =~ /\.gz$/ ) {
   $filename = "zcat $filename";
   $mode = '-|';
}

foreach my $acc ( @accnr ) {
   open my $SPROTFILE, $mode, $filename or die "could not open $filename";
   my $seq = sprotseq($SPROTFILE, $acc);
   if ( $countonly ) {
      print "Number of amino acids in $acc is ", length($seq), "\n";
   } else {
      print "The sequence of $acc is\n$seq\n";
   }
   close $SPROTFILE;
}
