的最後一行我用的不同文件中的代碼此相同的比特幾次通過時的程序沒有問題:打開文件只返回文件
#if the info is part of a file
if($proteinIn =~ m/\.txt$/i){
my $input_file = catfile('..', dataset => $proteinIn);
open my $protein_file, '<', $input_file
or die "couldn't open '$input_file': $!";
while (my $protLine = <$protein_file>) {
print $protLine."\n";
$protLine =~ s/\s+\z//; # remove all trailing space
$protein{$protLine} = 1;
}
close $protein_file;
}
當含有這種
Q5KDZ7_CRYNJ
Q2U9C0_ASPOR
Q2U048_ASPOR
G2Q3M9_THIHA
G2QAZ2_THIHA
文件中讀取
打印語句「print $ protLine。」\ n「;」只打印最後一行。在這種情況下:
G2QAZ2_THIHA
的這個我在程序的其它示例讀取文件的每一行給出
foreach my $tempFile(@fileList){
my $input_file = catfile('..', dataset => $tempFile);
open my $ps_file, '<', $input_file
or die "couldn't open '$input_file': $!";
while (my $line = <$ps_file>) {
$line =~ s/\s+\z//; # remove all trailing space
my @curLine = split /\t/, $line;
<the rest of the program>
這段代碼打開的文件包含如下行:
>sp|Q6GZX4|001R_FRG3G Putative transcription factor 001R OS=Frog virus 3 (isolate Goorha) GN=FV3-001R PE=4 SV=1 MAFSAEDVLKEYDRRRRMEALLLSLYYPNDRKLLDYKEWSPPRVQVECPKAPVEWNNPPSEKGLIVGHFSGIKYKGEKAQASEVDVNKMCCWVSKFKDAMRRYQGIQTCKIPGKVLSDLDAKIKAYNLTVEGVEGFVRYSRVTKQHVAAFLKELRHSKQYENVNLIHYILTDKRVDIQHLEKDLVKDFKALVESAHRMRQGHMINVKYILYQLLKKHGHGPDGPDILTVKTGSKGVLYDDSFRKIYTDLGWKFTPL FRG3G
爲什麼代碼的第一個例子只打印文件的最後一行?
編輯:回覆評論說,問題在代碼上游;幸運的是,我的問題是問題的代碼之前開始所以這裏的一切附近
運行代碼時,我用命令「perl的regProt.pl‘’‘truePool.txt’‘uniprot_sprot.dat’,‘真菌’
#!/usr/bin/env perl
use strict;
use File::Spec::Functions qw(catfile);
#use warnings;
#@author David Dziak
#A program for quick regex functions on uniprot data to test protein signatures
#my $max = 325783;
#my $cur = 0;
my $annotation;
my $fingerprint = $ARGV[0];
unless($fingerprint){
$fingerprint = "[GASRK][KRVSG][RKVI][KRVI]x[ASCR]x[AST]x(0,45)[GATF]xxx[VLI]N[GKND]x(11,12)[RKL]x(16,18)[NDA]x(6)[GS]GGx(10)[AG][LIVM][GAS][KR][GASN][VLI]";#prosite s9
#$fingerprint = "[GS]Gx(2)[GSA][QK]x(2)[SA]x(3)[GSA]x[GSTAV][KR][GSALVD][LIFV]";#prosite s9
#$fingerprint = "[STDNQ]G[KRNQMHSI]x(6)[LIVM]x(4)[LIVMC][GSD]x(2)[LFI][GAS][DE][FYM]x(2)[ST]";#prosite s19
#$fingerprint = "[RKHN][KSTR]X(3)[AVSCR]X(6)GXGX(0,23)X(25)GGGX(2)[GAS][QRKS]X(0,50)X(20)[APS]RX(5)[VSTA]XR";#s9
#$fingerprint = "[GAR][RKHG][RKHNT][KSTR]X(3)[AVSCR][RASTHKQLP]X(5)[GPSTND]X[GPSTKDQ]X(4)[NDVGIT]X(0,60)G[GS]GX(2)[GSA][QRS]X(0,70)[QTRA][FWYETK][STAVH][KY][RK]";#s9
#$fingerprint = "[RGWCKT]X(5)PX(3)[GARDENS]X(4)[VIL][HYF]XGX(7)[LIVMP]X(7)x[LFI][GASR][DEA][FYME]";#s19
}
$annotation .= $fingerprint;
#protein name to search
my $proteinIn = $ARGV[1];
my %protein;
#if the info is part of a file
if($proteinIn =~ m/\.txt$/i){
my $input_file = catfile('..', dataset => $proteinIn);
什麼是catfile? – squiguy 2013-02-14 18:34:22
你的例子工作正常,在你顯示的代碼之前必須有別的東西。或者你讀了一個不同的文件。 – 2013-02-14 18:37:27
@squiguy:catfile大概來自File :: Spec :: Functions – ysth 2013-02-14 18:45:45