Walter的学习笔记 2019-12-28
目标如题,有多个fasta文件和一个文件名列表,将文件名列表中包含的文件匹配出来并提取第一条序列合并成一个fa文件。
这个采用perl实现,用法和代码如下:
#!/usr/bin/perl -w use strict; sub usage{ die "usage:perl $0 <fa.list> <Fasta_Dir> <merged.fa>\n",unless(@ARGV==3); } usage(); open LIST,"$ARGV[0]"; open F,"$ARGV[1]"; open OU,">$ARGV[2]"; my @listName=<LIST>; my @files=glob("$ARGV[1]/*.faa"); my $matchNum=0; foreach my $k(@files){ my $fileName=(split /\//,$k)[-1]; if(grep /^$fileName$/,@listName){ $matchNum+=1; open EACH,"$ARGV[1]/$fileName"; $/=">"; <EACH>; while(<EACH>){ chomp; my @info=split /\n/,$_; my $seqID=shift @info; my $seq=join "",@info; print OU ">$seqID\n$seq\n"; last; } $/="\n"; } } print "match: $matchNum files,and merge completed!\n"; close LIST; close F;