perl multi fasta file match, and extract the first sequence matches the file

If that target, and a plurality fasta file list of file names, file names match the list contains out and extracting a first sequence of files merged into fa.

The perl implemented using, and usage code is as follows:

image

  1 #!/usr/bin/perl -w
  2 use strict;
  3 
  4 sub usage{
  5 	die "usage:perl $0 <fa.list> <Fasta_Dir> <merged.fa>\n",unless(@ARGV==3);
  6 }
  7 usage();
  8 
  9 open LIST,"$ARGV[0]";
 10 open F,"$ARGV[1]";
 11 open OU,">$ARGV[2]";
 12 
 13 my @listName=<LIST>;
 14 
 15 my @files=glob("$ARGV[1]/*.faa");
 16 my $matchNum=0;
 17 
 18 foreach my $k(@files){
 19 	my $fileName=(split /\//,$k)[-1];
 20 	if(grep /^$fileName$/,@listName){
 21 		$matchNum+=1;
 22 		open EACH,"$ARGV[1]/$fileName";
 23 		$/=">";
 24 		<EACH>;
 25 		while(<EACH>){
 26 			chomp;
 27 			my @info=split /\n/,$_;
 28 			my $seqID=shift @info;
 29 			my $seq=join "",@info;
 30 			print OU ">$seqID\n$seq\n";
 31 			last;
 32 		}
 33 		$/="\n";
 34 	}
 35 }
 36 
 37 print "match: $matchNum files,and merge completed!\n";
 38 
 39 close LIST;
 40 close F;

Guess you like

Origin www.cnblogs.com/mmtinfo/p/12113036.html