0

我正在尝试创建一个 PNG 文件。

下面的脚本执行没有返回任何错误,tester.png无法查看输出文件(并且 cmd 窗口打印附加的附加文本)。

我不确定为什么我无法查看此脚本生成的 PNG 文件。

我使用了 Active Perl (5.18.2) 和 Strawberry Perl (5.18.4.1) 但同样的问题。我尝试了 Strawberry Perllibgdlibpng作为安装的一部分,即使我没有收到任何错误。有什么建议吗?

#!/usr/bin/perl

use Bio::Graphics;
use Bio::SeqFeature::Generic;
use strict;
use warnings;

my $infile = "data1.txt";
open( ALIGN, "$infile" ) or die;
my $outputfile = "tester.png";
open( OUTFILE, ">$outputfile" ) or die;

my $panel = Bio::Graphics::Panel->new(
    -length => 1000,
    -width  => 800
);
my $track = $panel->add_track(
    -glyph => 'generic',
    -label => 1
);

while (<ALIGN>) {    # read blast file
    chomp;

    #next if /^\#/;  # ignore comments
    my ( $name, $score, $start, $end ) = split /\t+/;
    my $feature = Bio::SeqFeature::Generic->new(
        -display_name => $name,
        -score        => $score,
        -start        => $start,
        -end          => $end
    );
    $track->add_feature($feature);

}

binmode STDOUT;
print $panel->png;
print OUTFILE $panel->png;

cmd打印截图

4

1 回答 1

2

你有

binmode STDOUT;
print $panel->png;

有趣的是,您还拥有:

print OUTFILE $panel->png;

但你从来没有binmode OUTFILE。因此,您在命令提示符中显示 PNG 文件的内容,并创建一个损坏的 PNG 文件。(另见当位不粘时。)

如果您删除print OUTFILE ..., 并将脚本的输出重定向到 PNG 文件,您应该能够在图像查看器中查看其内容。

C:\> perl myscript.pl > panel.png

或者,您可以避免将二进制文件的内容打印到控制台窗口,而是使用

binmode OUTFILE;
print $panel->png;
于 2015-04-06T15:52:25.120 回答