- 论坛徽章:
- 0
|
谢谢huang6894和欧阳西风两位的帮忙。我努力看了点书,自己把我之前写的修改了下,现在可以准确运行了,也得到了希望的结果。可能我的程序不是最简洁最好的,但是毕竟它可以运行了。
贴出来,希望有同样困惑的人可以借鉴下,也请指导我如何提高代码写作水平。
#!/usr/bin/perl -w
use strict;
use warnings;
#welcome words
print "\n######Dear, ";
print " Welcome you to use this code!\n";
print " Please give me your feedback after using.######\n\n\n";
my $inputfile="file a";
unless (open (GET_ID,$inputfile)){
print STDERR "Cann\'t open \"$inputfile\"\n";
exit;
}
my @id1 = ();
my @id2 = ();
@id1=<GET_ID>;
foreach my $fileid (@id1){
$fileid=~ s/^\s*|\s*$//g;
push @id2, $fileid;
}
close GET_ID;
my $proteinfile="file b";
unless (open(GET_PROTEIN, $proteinfile)){
print "Could not open the file $proteinfile!\n";
}
#reset line seperator '$/' to '>' read in each set of genes one by one
$/= ">";
while (<GET_PROTEIN>){
my $protein_ID='';
my $protein_sequence='';
if ($_=~/^>/){
next;}
if ($_=~/(.*)\n/){
$protein_ID=$1;
}
$_=~s/^[^\n]+\n//;
$protein_sequence=$_;
$protein_sequence=~s/>$//;
$protein_sequence=~ s/\s*//g;
foreach my $ID (@id2){
if ($ID eq $protein_ID){
my $data=">$protein_ID\n$protein_sequence\n";
my $outputfile = 'test.output';
open (OUTPUT,">>$outputfile");
print OUTPUT "$data\n";
close OUTPUT;
print "$ID\n";
}
}
}
close GET_PROTEIN;
exit; |
|