这是一个 perl 脚本,它采用制表符分隔的输出文件并输出三个不同的文本文件,也是制表符分隔的。SO 上的另一个用户帮助我纠正了一个错误,该错误在输出文件的每一行末尾创建了额外的空白。但是,我希望输出逗号分隔的文本。当我替换print $Afile join( ",", @ADD) , "\n";
而不是 print $Afile join( "\t", @ADD) , "\n";
在输出文件的每一行末尾得到两个尾随逗号时。这些是从哪里来的?
#!/usr/bin/perl
use strict; use warnings;
die "usage: [ imputed genotype.file ]\n" unless @ARGV == 1;
open my $Afile, ">$imputed" . "_ADD.txt" or die $!;
open my $Dfile, ">$imputed" . "_DOM.txt" or die $!;
open my $Ifile, ">$imputed" . "_IMP.txt" or die $!;
<>; #skip header
while(<>){
chomp;
my @entries = split( '\t', $_ );
my @ADD = ();
my @DOM = ();
my @IMP = ();
push( @ADD, $entries[ 0 ], $entries[ 1 ], $entries[ 2 ]);
push( @DOM, $entries[ 0 ], $entries[ 1 ], $entries[ 2 ]);
push( @IMP, $entries[ 0 ], $entries[ 1 ], $entries[ 2 ]);
for ( my $i = 3; $i < scalar @entries - 1 ; $i+=3 ) { ### for each entry per line
push( @ADD, $entries[ $i ] );
push( @DOM, $entries[ $i + 1 ] );
$entries[ $i + 2 ] =~ s/^NA$//;
push( @IMP, $entries[ $i + 2 ] );
}
print $Afile join( "\t", @ADD) , "\n";
print $Dfile join( "\t", @DOM) , "\n";
print $Ifile join( "\t", @IMP) , "\n";
} ### for loop
close $Afile;
close $Dfile;
close $Ifile;