#! /usr/bin/perl
use strict;
my (@data,$data,@data1,@diff,$diff,$tempS,$tempE, @ID,@Seq,@Start,@End, @data2);
#my $file=<>;
open(FILE, "< ./out.txt");
while (<FILE>){
chomp $_;
#next if ($line =~/Measurement count:/ or $line =~/^\s+/) ;
#push @data, [split ("\t", $line)] ;
my @data = split('\t');
push(@ID, $data[0]);
push(@Seq, $data[1]);
push(@Start, $data[2]);
push(@End, $data[3]);
# push @$data, [split ("\t", $line)] ;
}
close(FILE);
my %hash = map { my $key = "$ID[$_]"; $key => [ $Start[$_], $End[$_] ] } (0..$#ID);
for my $key ( %hash) {
print "Key: $key contains: ";
for my $value ($hash{$key}) {
print " $hash{$key}[0] ";
}
print "\n";
}
for (my $j=0; $j <=$#Start ; $j++)
{
if ($Start[$j] > $End[$j])
{
$tempS=$Start[$j];
$Start[$j]=$End[$j];
$End[$j]=$tempS;
}
print"$tempS\t$Start[$j]\t$End[$j]\n";
}
my @sortStart = sort { $a <=> $b } @Start;
my @sortEnd = sort { $a <=> $b } @End;
#open(OUT,">>./trial.txt");
for(my $i=1521;$i>=0;$i--)
{
print "hey";
my $diff = $sortStart[$i] - $sortStart[$i-1];
print "$ID[$i]\t$diff\n";
}
排序其他兩個陣列我有相同的長度的三個陣列,ID
用的ID(字符串),Start
和End
與整數值(從文件讀取)。ID跟蹤,同時交換和在Perl
我想遍歷所有這些數組,並且還想跟蹤ID。首先將Start
中的元素與End
對換,如果開始>結束,那麼我必須對這兩個數組進行排序以供進一步應用(因爲我對Start
中的每個項目否定Start[0]-Start[1]
)。排序時,Id值可能會更改,並且由於我的ID對於每個Start和End
元素都是唯一的,因此如何在排序時跟蹤我的ID?
三個陣列,ID
,Start
和End
,都在我的考慮之下。
這是我的輸入數據的小塊:
DQ704383 191990066 191990037
DQ698580 191911184 191911214
DQ724878 191905507 191905532
DQ715191 191822657 191822686
DQ722467 191653368 191653339
DQ707634 191622552 191622581
DQ715636 191539187 191539157
DQ692360 191388765 191388796
DQ722377 191083572 191083599
DQ697520 189463214 189463185
DQ709562 187245165 187245192
DQ540163 182491372 182491400
DQ720940 180753033 180753060
DQ707760 178340696 178340726
DQ725442 178286164 178286134
DQ711885 178250090 178250119
DQ718075 171329314 171329344
DQ705091 171062479 171062503
上述ID,開始,結束分別。如果開始>結束,我只在這兩個數組之間交換它們。但交換後,降序可能會改變,但我希望它們的降序也是它們對應的否定ID,如上所述。
請添加您的代碼。 – serenesat
請忽略我的代碼中的哈希創建。 – Kanhu
添加輸入數據和預期輸出會更有幫助。 – serenesat