-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrotation.pl
62 lines (52 loc) · 1.53 KB
/
rotation.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/perl
die "usage: perl rotation.pl <ref.fa> <ref_rotation>\n" unless @ARGV == 2;
$headlen = 140;
$seq=$ARGV[0];
$out="$ARGV[1].out";
$sort = "$ARGV[1].sort";
$bdx_ref_name = "$ARGV[1].sort.ref_name.bdx";
open Seq, $seq;
open Out, '>'.$out;
open Bdx, '>'.$bdx_ref_name;
$header_line = <Seq>; # get header
($_,$header) = split(/>/, $header_line);
($ref_name,$_) = split(/ /, $header);
print Bdx $ref_name;
$line1 = <Seq>;chomp $line1; $linelen = length($line1);
$line2 = <Seq>;chomp $line2;
$line3 = <Seq>;chomp $line3;
$line = $line1.$line2.$line3;
$len=length($line);
#print $len."\n";
$count=0;
$posi = 0;
print Out substr($line,$count,$headlen)."\t".substr($line,0,1)."\t\$\t$posi\n";
$count=1;
$posi = 1;
while($count <= $len - $headlen){
print Out substr($line,$count,$headlen)."\t".substr($line,$count,1)."\t".substr($line,$count-1,1)."\t$posi\n";
$count++;
$posi++;
}
while($nextline=<Seq>){
chomp $nextline;
$line1=$line2;
$line2=$line3;
$line3=$nextline;
$line=$line1.$line2.$line3;
$count-=$linelen;
while($count <= $len - $headlen){
print Out substr($line,$count,$headlen)."\t".substr($line,$count,1)."\t".substr($line,$count-1,1)."\t$posi\n";
$count++;
$posi++;
}
}
$lastlinelen=length($line);
while($count < $lastlinelen){
print Out substr($line,$count,$len-$count)."\t".substr($line,$count,1)."\t".substr($line,$count-1,1)."\t$posi\n";
$count++;
$posi++;
}
print Out "\$\t\$\t".substr($line,$count-1,1)."\t$posi\n";
system("LC_COLLATE=C sort -k 1 $out > $sort");
system("rm $ARGV[1].out");