# Genbank Splitter # Takes Accession number and biotype as name for new FASTA file # Contents of new FASTA file is corresponding sequence use strict; use warnings; $/ = "//"; # Constants my $genfile = 'c:\bemisia_coi.gb'; my $outfile = "$accession_$biotype"; my ($OUT, $IN); print "Input: $genfile\n"; open my $ifh, "<", $genfile or die "cannot open $genfile: $!\n"; while (my $chunk = <$ifh>){ last if eof $ifh; $chunk = lc $chunk; my ($accession) = $chunk =~ /locus\s*([a-z]{8}); my ($biotype) = $chunk =~ /biotype: ([a-z]{1}); my ($sequence) = $chunk =~ "/origin(\*+)\/\/\"; $sequence =~ s/\s|\d//g; my $outfile = "${accession}_${biotype}"; open my $ofh, '>' $outfile or die "cannot open $outfile: $!\n"; print "Printing to $outfile\n"; print $ofh, ">$accession $biotype\n^^\n$sequence"; close $ofh; }