-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_nupack_ids.pl
69 lines (58 loc) · 1.76 KB
/
get_nupack_ids.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
63
64
65
66
67
68
69
#!/usr/local/bin/perl
#ARGV[0] = diretcory where the nupack run files are, ARGV[1] directory where Nupack_Rank_Topo.txt should be written
# get the list of NUPACK bpseq output files
$command="ls ".$ARGV[0]."*.nupack.bpseq > ".$ARGV[0]."temp_list.txt";
system($command);
@ranks=();
@min_ids=();
$count = -1;
$list_file=$ARGV[0]."temp_list.txt";
open(LIST,"<$list_file");
while($line=<LIST>){ # for every rnafold output file
$count++;
$line=~ s/\n//g;
#getting the rank / number of the struct file
@cols=split(/\//,$line);
@cols2=split(/\./,$cols[2]);
print $cols2[0]."\n";
$cols2[0] =~ s/Top//g;
$ranks[$count] = $cols2[0];
#runnning treeGraphs to get the RAG IDs
$command="python2.7 modified-treeGraph/treeGraphs.py ".$line;
$output_text=`$command`;
@outlines=split(/\n/,$output_text);
$topo_min="";
for(my $i=0; $i<scalar(@outlines); $i++){
@cols5=split(/:/,$outlines[$i]);
if($cols5[0] eq "Graph ID"){ # this is the graph id of the bpseq file
$topo_min = $cols5[1];
$topo_min =~ s/\s+//g;
$topo_min =~ s/\n//g;
@min_ids[$count]=$topo_min;
last;
}
}
}
#clean up
$command="rm -f ".$ARGV[0]."temp*";
system($command);
#sort accoring to numerical rank
for($i=0;$i<=$count;$i++){
for($j=$i+1;$j<=$count;$j++){
if($ranks[$i] > $ranks[$j]){
$temp = $ranks[$i];
$ranks[$i] = $ranks[$j];
$ranks[$j] = $temp;
$temp = $min_ids[$i];
$min_ids[$i] = $min_ids[$j];
$min_ids[$j] = $temp;
}
}
}
#writing the output file
$output_file=$ARGV[1]."Nupack_Rank_Topo.txt";
open(OUTPUT,">$output_file");
for($i=0;$i<=$count;$i++){
print OUTPUT $ranks[$i]."\t".$min_ids[$i]."\n";
}
close(OUTPUT);