Perl DD。但是这把事情搞砸了。你可以对行中的每个元素都使用join(“\t”,…),对每行使用join(“\n”,…),或者在行的末尾用“\n”一行一行地打印输出。我还是不明白。你能把你的想法嵌入到上面的代码中吗?push(@ADD,$entries[$i])

Perl DD。但是这把事情搞砸了。你可以对行中的每个元素都使用join(“\t”,…),对每行使用join(“\n”,…),或者在行的末尾用“\n”一行一行地打印输出。我还是不明白。你能把你的想法嵌入到上面的代码中吗?push(@ADD,$entries[$i]),perl,excel,vim,whitespace,text-parsing,Perl,Excel,Vim,Whitespace,Text Parsing,DD。但是这把事情搞砸了。你可以对行中的每个元素都使用join(“\t”,…),对每行使用join(“\n”,…),或者在行的末尾用“\n”一行一行地打印输出。我还是不明白。你能把你的想法嵌入到上面的代码中吗?push(@ADD,$entries[$i]);打印$afilejoin(“\t”,@ADD);我想我看到了在数组的前三个元素中的作用。在第二个for循环中,嵌入在第一个循环中的join如何使用?嘿,@frezik,那不应该是join('\t'而不是join(“\t”)?@eric-fre


DD。但是这把事情搞砸了。你可以对行中的每个元素都使用join(“\t”,…),对每行使用join(“\n”,…),或者在行的末尾用“\n”一行一行地打印输出。我还是不明白。你能把你的想法嵌入到上面的代码中吗?push(@ADD,$entries[$i]);打印$afilejoin(“\t”,@ADD);我想我看到了在数组的前三个元素中的作用。在第二个
for循环
中,嵌入在第一个循环中的
join如何使用?嘿,@frezik,那不应该是
join('\t'
而不是
join(“\t”)
?@eric-frezik是正确的,否则您将使用字符串文字
'\t'
而不是制表符来连接
。嗨@kenosis,但我一直在使用
'\t'
,它一直在为我的条目进行制表符分隔。我的数据是数字的,因此没有可拆分的t。另外,我看到了
连接的大多数示例在线使用单引号。我想我看到这对我数组中的前三个元素有效。你会如何使用第二个
for循环中的
join
,即嵌入第一个循环中的
join('\t'
),而不是
join('\t')
?@eric-frezik是正确的,否则您将使用字符串文字
'\t'
而不是制表符来连接
。嗨@kenosis,但我一直在使用
'\t'
,它一直在为我的条目进行制表符分隔。我的数据是数字的,因此没有可拆分的t。另外,我看到了
连接的大多数示例在线使用单引号。双引号和单引号的意义是什么?在我对拆分使用的回顾中,通常使用单引号
'
(或
/
,取决于上下文).双引号插入字符串中的变量。单引号不插入。双引号与单引号的意义是什么?在我对拆分使用的回顾中,通常使用单引号
'
(或
/
,取决于上下文)。双引号插入字符串中的变量。单引号不插入。
#!/usr/bin/perl
use strict; use warnings;

die "usage: [ imputed genotype.file ]\n" unless @ARGV == 1;

my $imputed = $ARGV[ 0 ];
open ( my $FILE, "<$imputed" );
my @data  = <$FILE>; 

my @ADD = ();
my @DOM = ();
my @IMP = ();

for ( my $i = 1; $i < scalar @data; $i++ ) ### for each line data[i], and use $i = 1 to
                                           ### skip header, 0 to include it output
    {
     my $line = $data[ $i ];
     chomp $line;

     my @entries = split( '\t', $data[ $i ] );

     push( @ADD, "$entries[ 0 ]\t$entries[ 1 ]\t$entries[ 2 ]\t" );
     push( @DOM, "$entries[ 0 ]\t$entries[ 1 ]\t$entries[ 2 ]\t" );
     push( @IMP, "$entries[ 0 ]\t$entries[ 1 ]\t$entries[ 2 ]\t" );

     for ( my $i = 3; $i < scalar @entries - 1 ; $i+=3 ) ### for each entry per line
         {
          push( @ADD, "$entries[ $i ]\t" );
          push( @DOM, "$entries[ $i + 1 ]\t" );

          if ( $entries[ $i + 2 ] eq 'NA' ) ### to replace any occuring "NA"s with blanks
             {
              $entries[ $i + 2 ] =~ s/NA//; 
             }

          push( @IMP, "$entries[ $i + 2 ]\t" );
          }

    push( @ADD, "\n" ); 
    push( @DOM, "\n" );
    push( @IMP, "\n" ); 

   } ### for loop   

open my $Afile, ">$imputed" . "_ADD.txt" or die $!;
print $Afile @ADD; 
close $Afile;

open my $Dfile, ">$imputed" . "_DOM.txt" or die $!;
print $Dfile @DOM;
close $Dfile;

open my $Ifile, ">$imputed" . "_IMP.txt" or die $!;
print $Ifile @IMP;
close $Ifile;
join( "\t", ...) 
print join "\t", @output;
#!/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;
push( @ADD, "$entries[ 0 ]\t$entries[ 1 ]\t$entries[ 2 ]\t" );
push( @ADD, join( "\t", @entries[0..2] ) );