#!/usr/bin/perl -w #decided to have input file entered in command line #####INPUT Name of multiple seq file, open file and assign IN filehandle ############# unless(@ARGV==1) {die "please provide file name in command line \n this file should contain multiple sequences in fasta format \n\n";} $filename=$ARGV[0]; open(IN, "< $filename") or die "cannot open $filename:$!"; ################################################## $/="\n>" ; #defines new end of line ######################## $flag=0; #flag0 : first sequence read while (defined ($line=)){ # read through file seq by seq ie untill a \n> occurrs chomp ($line); # removes "\n>" from end of sequence ############ $line =~ m/gi\|(\d+)\|/; #match gi|number capture number in $1 $outname = "gi_$1.sfa"; # make useful name for outfile print "\n\nproposed outname: $outname\n"; #print outname to screen :) print "sequence ", $flag+1 ,":\n"; #open(OUT, ">$outname")||die "cannot open: $!"; #open file fith $outname and assign handle OUT if ($flag > 0) {print '>'}; #first seq already has > !!!!!!!!!!! print "$line\n\n"; #print to screen only, else uncomment above and add file handle to print $flag++; #print "$line"; #print to screen #print OUT "$line"; #print to OUT } close(IN); #close(OUT);