Perl编译错误

Perl编译错误,perl,csv,bioinformatics,strict,Perl,Csv,Bioinformatics,Strict,抱歉,如果这看起来很明显,但我对Perl和编程相当陌生,我已经工作了一个多星期,无法完成它。 我的想法很简单。我有一个.csv,其中第一列有名字,第二列有一个从-1到1的数字,第三列有一个位置。然后是另一个文件,我在其中获得了名称(行以>)和信息,每行80个字符 我想做的是保留第一个文件的名称行,并获取从-20到+60的“位置”。但我不能让它工作,我已经到了不知道该去哪里的地步 use strict; #read file line by line use war

抱歉,如果这看起来很明显,但我对Perl和编程相当陌生,我已经工作了一个多星期,无法完成它。 我的想法很简单。我有一个.csv,其中第一列有名字,第二列有一个从-1到1的数字,第三列有一个位置。然后是另一个文件,我在其中获得了名称(行以>)和信息,每行80个字符

我想做的是保留第一个文件的名称行,并获取从-20到+60的“位置”。但我不能让它工作,我已经到了不知道该去哪里的地步

use strict;                 #read file line by line
use warnings;
my $outputfile = "Output1.txt";
my $filename = "InputP.txt";
my $inputfasta = "Inputfasta.txt";
open my $fh, '<', $filename or die "Couldn't open '$filename'";
open my $fh2, '>', $outputfile or die "Couldn't create '$outputfile'";
open my $fh3, '<', $inputfasta or die "Couldn't open '$inputfasta'";
my $Psequence = 0;
my $seqname = 0;

while (my $line = <$fh>) {
chomp $line;
my $length = index ($line, ",");
$seqname = substr ($line, 0, $length);  

my $length2 = index ($line, ",", $length);
my $score = substr ($line, $length +1, $length2);   

my $length3 = index ($line, ",", $length2);
my $position = substr ($line, $length2 +1, $length3);   

#print $fh2 "$seqname"."\t"."$score"."\t"."$position"."\n";  }

my $Rlength2 = index ($score, ",");
my $Rscore = substr ($score, 0, $Rlength2);
#print "$Rscore"."\n";}
        while (my $linea = <$fh3>){  #same order.

            chomp $linea;
                if ($linea=~/^>(.+)/) { 
                    print $fh3 "\n"."$linea"."\n"; }
                else { $linea =~ /^\s*(.*)\s*$/;
                    chomp $linea;
                    print $fh3 "$linea". "\n"; }   
                    }
                if ($Rscore >= 0.5){
                    $Psequence = substr ($linea, -20, 81); 
                    print "$seqname"."\n"."$Psequence";}
        }
使用严格#逐行读取文件
使用警告;
my$outputfile=“Output1.txt”;
我的$filename=“InputP.txt”;
my$inputfasta=“inputfasta.txt”;

打开my$fh,“从CSV创建一个散列,其中键是名称,值是位置

use Text::CSV_XS qw( );

my %pos_by_name;
{
   open(my $fh, '<', $input_qfn)
      or die("Can't open $input_qfn: $!\n");

   my $csv = Text::CSV_XS->new({ auto_diag => 1, binary => 1 });
   while (my $row = $csv_in->getline($fh)) {
      $pos_by_name{ $row->[0] } = $row->[2];
   }
}
open(my $fh, '<', $fasta_qfn)
   or die("Can't open $fasta_qfn: $!\n");

while (<$fh>) {
   chomp;
   my ($name) = /^>(.*)/
      or next;

   my $pos = $pos_by_name{$name};
   if (!defined($pos)) {
      die("Can't find position for $name\n");
   }

   ... Do something with $name and $pos ...
}
使用Text::CSV_XS qw();
我的%pos\u by\u name;
{

打开(my$fh),请学习正确缩进代码。然后错误会更明显:

while (my $linea = <$fh3>){  #same order.
    chomp $linea;
    if ($linea =~ /^>(.+)/) { 
        print $fh3 "\n$linea\n";
    } else {
        # Commented out as it does nothing.
        # $linea =~ /^\s*(.*)\s*$/;
        # chomp $linea;
        print $fh3 "$linea\n";
    }   
}

if ($Rscore >= 0.5){
    $Psequence = substr $linea, -20, 81; 
    print "$seqname\n$Psequence";
}
while(my$linea=){#相同顺序。
咀嚼$linea;
如果($linea=~/^>(.+)/){
打印$fh3“\n$linea\n”;
}否则{
#注释掉了,因为它什么也不做。
#$linea=~/^\s*(.*)\s*$/;
#咀嚼$linea;
打印$fh3“$linea\n”;
}   
}
如果($Rscore>=0.5){
$P序列=子序列$linea,-20,81;
打印“$seqname\n$Psequence”;
}

$linea
仅存在于while循环中,但您也可以尝试在下面的段落中使用它。循环结束时,变量将消失。

Perl::Tidy可能对他有帮助。