- 論壇徽章:
- 0
|
謝謝huang6894和歐陽西風(fēng)兩位的幫忙。我努力看了點(diǎn)書,自己把我之前寫的修改了下,現(xiàn)在可以準(zhǔn)確運(yùn)行了,也得到了希望的結(jié)果?赡芪业某绦虿皇亲詈啙嵶詈玫,但是畢竟它可以運(yùn)行了。
貼出來,希望有同樣困惑的人可以借鑒下,也請指導(dǎo)我如何提高代碼寫作水平。
#!/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; |
|