'我'的问题

时间:2016-03-20 13:22:40

标签: perl bioinformatics

我有一个程序旨在从多线程中拉出线并通过THREADER运行它们:

#¡/usr/bin/perl
use warnings;
use strict;
use File::Temp qw(tempfile);

my $filename = 'unchar_prot';   #open file
open (my $fh, '<:encoding(UTF-8)', $filename)
    or die "Error - cannot open file";

my %id2seq = (); #create a hash
my $seq_id = '';
while (my $line = <$fh>) {
    chomp $line;
    if ($line =~ /^>(.+)/) { #Find lines starting in >
        $seq_id = $1;
    } else {
        $id2seq{$seq_id} .= $line; #Store seq and ID on hash
    }
}

open(my $outfile, '>', 'out.txt') or die
close (my $outfile)

while (my ($seq_id, $seq) = each %id2seq) { #Call key and value from hash 
    my ($temp_fh, $prot) = tempfile ("tempXXXX", SUFFIX => '.seq'); #create a temporary file
    print $temp_fh ">$seq_id\n$seq\n"; #print the 2 lines to the temp file 
    my ($out_fh, $out) = tempfile("outXXXX", SUFFIX => '.txt'); # create a temporary outfile 
    system ('nohup threader -p $temp_fh $out_fh cdc6.lst &'); #call threader 
    open($outfile, '>>', 'out.txt');
    print $outfile "$out_fh"; # append the content of the temp out to the main outfile
} 

当我尝试运行它时,我的“我的”会出现很多问题:

  

“my”变量$ outfile在testfile4.pl第22行的同一语句中屏蔽了之前的声明。

     

“my”变量$ seq_id在testfile4.pl第24行掩盖了同一范围内的早期声明。

     

“my”变量$ temp_fh在testfile4.pl第26行的同一语句中屏蔽了先前的声明。

     

“my”变量$ seq_id在testfile4.pl第26行的同一语句中屏蔽了先前的声明。

     

“my”变量$ seq在testfile4.pl第26行的同一语句中屏蔽了先前的声明。

     

testfile4.pl第24行的语法错误,靠近“){”

     

testfile4.pl第31行的语法错误,靠近“}”

     

由于编译错误,testfile4.pl的执行中止。

有谁知道这里发生了什么?我怎样才能让它运行?

PS我知道这可能有很多其他问题。我是一个非常初学者,我不需要它整洁或高效,我只需要它工作。

1 个答案:

答案 0 :(得分:3)

作为提示 - 任何时候你都会遇到这样的错误,它通常是 ,因为你错过了一个分号或一个小括号。

就像在这一行:

open(my $outfile, '>', 'out.txt') or die
close (my $outfile)

你需要一个semilcolon。您还需要my,因为您已将$outfile声明为open语句的一部分。

当然,打开之后立即关闭它也没有多大意义。

(另外 - 在shebang线上!发生了什么?)

还有一些其他奇怪的事情发生在这里。喜欢:

print $outfile "$out_fh"; # append the content of the temp out to the main outfile

我认为这不会做你想要的。因为$out_fh是文件句柄,所以您将打印“GLOB(0xDEADBEEF)”或类似内容。

相关问题