【发布时间】:2015-06-24 12:55:14
【问题描述】:
对不起,如果这看起来很明显,但我在 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";}
}
【问题讨论】:
标签: perl csv bioinformatics strict