【发布时间】:2012-02-01 21:21:05
【问题描述】:
一个像这样的文本文件作为查询文件:
fooLONGcite
GetmoreDATA
stringMATCH
GOODthing
另一个像这样的文本文件作为主题文件:
sometingfooLONGcite
anyotherfooLONGcite
matchGetmoreDATA
GETGOODthing
brotherGETDATA
CITEMORETHING
TOOLONGSTUFFETC
预期的结果是从主题文件中获取匹配的字符串,然后打印出来。所以,输出应该是:
sometingfooLONGcite
anyotherfooLONGcite
matchGetmoreDATA
GETGOODthing
这是我的 perl 脚本。但它不起作用。你能帮我找出问题所在吗?谢谢。
#!/usr/bin/perl
use strict;
# to check the command line option
if($#ARGV<0){
printf("Usage: \n <tag> <seq> <outfile>\n");
exit 1;
}
# to open the given infile file
open(tag, $ARGV[0]) or die "Cannot open the file $ARGV[0]";
open(seq, $ARGV[1]) or die "Cannot open the file $ARGV[1]";
my %seqhash = ();
my $tag_id;
my $tag_seq;
my $seq_id;
my $seq_seq;
my $seq;
my $i = 0;
print "Processing cds seq\n";
#check the seq file
while(<seq>){
my @line = split;
if($i != 0){
$seqhash{$seq_seq} = $seq;
$seq = "";
print "$seq_seq\n";
}
$seq_seq = $line[0];
$i++;
}
while(<tag>){
my @tagline = split;
$tag_seq = $tagline[0];
$seq = $seqhash{$seq_seq};
#print "$tag_seq\n";
print "$seq\n";
#print output ">$id\n$seq\n";
}
#print "Ending of Processing gff\n";
close(tag);
close(seq);
【问题讨论】:
标签: perl pattern-matching