【问题标题】:perl command to create matrix.txtperl 命令创建 matrix.txt
【发布时间】:2019-01-12 13:22:36
【问题描述】:

我有一个来自爆炸输出的 txt 文件,其中包含每个查询及其命中及其百分比标识和分数,我需要转换为矩阵文件以创建热图 我使用了这个长命令:

perl -we "while (<>) {chomp; @col = split /\t/; push @{$score{$col[0]}{$col[1]}}, $col[2], $col[3]}  @array = keys %score; print join "\t", "", @array, ""."\n"; foreach $key (keys %score) {print "$key\t";  foreach $hit (@array) {if ($score{$key}{$hit}) {print "$score{$key}{$hit}[0]\t" } else {print "\t"} } print "\n" }"

但我收到一条评论:未加引号的字符串 "t" 可能与 -e 第 1 行的未来保留字发生冲突

生成的文件大小为 0 KB

非常感谢您的帮助

【问题讨论】:

  • 请正确格式化您的代码 (stackoverflow.com/help/formatting)
  • "while (&lt;&gt;) {chomp; @col = split /\t/; push @{$score{$col[0]}{$col[1]}}, $col[2], $col[3]} @array = keys %score; print join " - 如果您的字符串以 " 开头,它会在下一个 " 结束。另外,你用的是什么外壳?
  • 我认为它以 " 结尾,请问您所说的 shell 是什么意思?
  • 我认为它是以双引号结尾的,如果你愿意,你所说的 shell 是什么意思?
  • 如果您知道代码以... print join " 结尾,您认为\t", "", @array, ""."\n 是什么?

标签: windows perl cmd


【解决方案1】:

您需要在任何地方将"..." 替换为qq/.../,例如

"$score{$key}{$hit}[0]\t"

变成

qq/$score{$key}{$hit}[0]\t/

但是说真的,这是一段非常长的代码,可以放入单行代码中。把它放到一个文件中,比如说matrix.pl 并运行perl matrix.pl。这样一来,您的阅读和编辑会更容易,而且其他任何人都可以更好地帮助您

这是您的代码的正确布局版本

矩阵.pl

use strict;
use warnings 'all';

my %score;

while ( <> ) {
    chomp;
    my @col = split /\t/;
    push @{ $score{$col[0]}{$col[1]} }, $col[2], $col[3];
}

my @keys = keys %score;

print join "\t", "", @keys, "" . "\n";

for my $key ( @keys ) {

    print "$key\t";

    for my $hit ( @keys ) {

        if ( $score{$key}{$hit} ) {
            print "$score{$key}{$hit}[0]\t";
        }
        else {
            print "\t";
        }
    }

    print "\n";
}

【讨论】:

  • 非常感谢您的帮助,但我不是 perl 专家,请您告诉我如何使用这个 matrix.pl 文件发出命令
  • 我告诉过你:perl matrix.pl 相当于你在问题中的行。您需要提供一些数据才能使其正常工作,但这不会改变。
  • 对不起,我知道了,你的评论里已经写了。再次非常感谢,你真的帮助我解决了我被困了将近一周的问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-12-29
  • 2015-07-02
  • 1970-01-01
  • 2011-05-05
  • 2023-03-23
  • 2020-12-24
  • 1970-01-01
相关资源
最近更新 更多