我有一個數組,其中包含一些DNA序列作爲存儲在其元素中的字符串。
例如:print $array[0];
給出如下輸出:ACTAG
(#每個序列中的第一個位置)。從數組perl中索引字符串元素的值
我寫了這段代碼,可以讓我分析每個序列的第一個位置。
#!/usr/bin/perl
$infile = @ARGV[0];
$ws= $ARGV[1];
$wsnumber= $ARGV[2];
open INFILE, $infile or die "Can't open $infile: $!"; # This opens file, but if file isn't there it mentions this will not open
my $sequence =(); # This sequence variable stores the sequences from the .fasta file
my $line; # This reads the input file one-line-at-a-time
while ($line = <INFILE>) {
chomp $line;
if ($ws ne "--ws=") {
print "no flag or invalid flag\n";
last;
}
else {
if($line =~ /^\s*$/) { # This finds lines with whitespaces from the beginning to the ending of the sequence. Removes blank line.
next;
} elsif($line =~ /^\s*#/) { # This finds lines with spaces before the hash character. Removes .fasta comment
next;
} elsif($line =~ /^>/) { # This finds lines with the '>' symbol at beginning of label. Removes .fasta label
next;
} else {
$sequence = $line;
$sequence =~ s/\s//g; # Whitespace characters are removed
@array = split //,$sequence;
$seqlength = length($sequence);}
}
$count=0;
foreach ($array[0]){
if($array[0] !~ m/A|T|C|G/){
next;
}
else {
$count += 1;
$suma += $count;
}
}
}
但我不知道如何修改$陣列運行該代碼爲每個位置[0](我只能勉強做特定現在的位置(在上面的例子中的第一位置。?)
有人可以幫助我 謝謝
**總是**'使用嚴格;使用警告;' – Toto