我需要帮助调试下面显示的代码。我已经问过这个问题的类似版本,但我无法开发出一个有效的脚本。我的输入文件是这样的:
line1
AAAAAAAAAAAAAAA
line2
BBBBBBBBBBBBBBB
line3
CCCCCCCCCCCCCCCC
line4
DDDDDDDDDDDDDDD
我希望脚本随机打乱文件中的行,例如:
line2
BBBBBBBBBBBBBBB
line1
AAAAAAAAAAAAAAA
line4
DDDDDDDDDDDDDDD
line3
CCCCCCCCCCCCCCC
该文件中有很多行(〜1,000,000)。目前,我收到以下错误:
Global symbol "$header_size" requires explicit package name at fasta_corrector9.pl line 40.
和
Global symbol "$header_size" requires explicit package name at fasta_corrector9.pl line 47.
我不明白如何给出$header_size
明确的包名。我不是程序员,所以我需要非常基本的解释。提前致谢。
#! /usr/bin/perl
use strict;
use warnings;
print "Please enter filename (without extension): ";
my $input = <>;
chomp($input);
print "Please enter total no. of sequence in fasta file: ";
my $orig_size = <> * 2 - 1;
chomp($orig_size);
open(INFILE, "$input.fasta") or die "Error opening input file for shuffling!";
open(SHUFFLED, ">" . "$input" . "_shuffled.fasta")
or die "Error creating shuffled output file!";
my @array = (0); # Need to initialise 1st element in array1&2 for the shift function
my @array2 = (0);
my $i = 1;
my $index = 0;
my $index2 = 0;
while (my @line = <INFILE>) {
while ($i <= $orig_size) {
$array[$i] = $line[$index];
$array[$i] =~ s/(.)\s/$1/seg;
$index++;
$array2[$i] = $line[$index];
$array2[$i] =~ s/(.)\s/$1/seg;
$i++;
$index++;
}
}
my $array = shift(@array);
my $array2 = shift(@array2);
for $i (reverse 0 .. $header_size) {
my $j = int rand($i + 1);
next if $i == $j;
@array[$i, $j] = @array[$j, $i];
@array2[$i, $j] = @array2[$j, $i];
}
while ($index2 <= $header_size) {
print SHUFFLED "$array[$index2]\n";
print SHUFFLED "$array2[$index2]\n";
$index2++;
}
close(INFILE);
close(SHUFFLED);