comparison Dotplot_Release/SOFD.pl @ 3:bc752a05f16d draft

Uploaded
author bornea
date Tue, 15 Mar 2016 15:25:15 -0400
parents
children
comparison
equal deleted inserted replaced
2:cfe2edb1c5d8 3:bc752a05f16d
1 #!/usr/bin/perl
2
3 # 17/12/2013
4
5 if($#ARGV==0){
6 print "This program takes the Saint Output File and produces two matrices.\n";
7 print "One has average spectral counts and the other FDR scores,\n";
8 print "\nusage:\n $0\n-i [csv saint output file]\n-s [FDR cutoff, default=0.01]\n\n";
9 die;
10 }
11 else{
12 $i=0;
13 $cutoff=0.01;
14 $spec_cutoff=0;
15 while($i<=$#ARGV){
16 if($ARGV[$i] eq '-i'){
17 $i++;
18 $ifile=$ARGV[$i];
19 }
20 elsif($ARGV[$i] eq '-s'){
21 $i++;
22 if($ARGV[$i]>1 || $ARGV[$i]<0){
23 die "\nFDR cutoff must be between 0 and 1 \n\n";
24 }
25 $cutoff=$ARGV[$i];
26 }
27 elsif($ARGV[$i] eq '-x'){
28 $i++;
29 if($ARGV[$i]<0){
30 die "\nAvgSpec cutoff must be > 0 \n\n";
31 }
32 $spec_cutoff=$ARGV[$i];
33 }
34 else{
35 die "\Incorrect program usage\n\n";
36 }
37 $i++;
38 }
39 }
40
41 $baitn=0, $bait[0]=xxxx, $sig_preysn=0;
42 $file='';
43 open(IFILE,"<$ifile") || die "$ifile can't be opened: $!";
44 { local $/=undef; $file=<IFILE>; }
45 @lines=split /[\r\n]+/, $file;
46 foreach $line (@lines) {
47 if($line =~ /^Bait/){
48 }
49 elsif($line =~ /^([^\t]+)\t[^\t]+\t([^\t]+)\t[^\t]+\t[\d]+\t([\d\.]+)\t[\d]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t[^\t]+\t([^\t]+)\t[^\t]+\t([^\t]+)\t/){
50 if($1 ne $bait[$baitn]){
51 $baitn++;
52 $bait[$baitn]=$1;
53 $preyn[$baitn]=0;
54 }
55 $preyn[$baitn]++;
56 $preys[$baitn][$preyn[$baitn]]=$2;
57 $avgspec[$baitn][$preyn[$baitn]]=$3;
58 $saint[$baitn][$preyn[$baitn]]=$4;
59 $fdr[$baitn][$preyn[$baitn]]=$5;
60 if($5 <= $cutoff && $3 >= $spec_cutoff){
61 $check_prey=0;
62 for($i=1; $i<=$sig_preysn; $i++){
63 if($sig_preys[$i] eq $2){
64 $check_prey=1;
65 }
66 }
67 if($check_prey==0){
68 $sig_preysn++;
69 $sig_preys[$sig_preysn]=$2;
70 }
71 }
72 }
73 else{
74 }
75 }
76 close(IFILE);
77
78 open(SC_FILE, ">SC_data.txt");
79 open(FDR_FILE, ">FDR_data.txt");
80
81 for($i=1; $i<=$baitn; $i++){
82 print SC_FILE "\t$bait[$i]";
83 print FDR_FILE "\t$bait[$i]";
84 }
85 print SC_FILE "\n";
86 print FDR_FILE "\n";
87 for($i=1; $i<=$sig_preysn; $i++){
88 print SC_FILE "$sig_preys[$i]";
89 print FDR_FILE "$sig_preys[$i]";
90 for($j=1; $j<=$baitn; $j++){
91 $krem=0;
92 for($k=1; $k<=$preyn[$j]; $k++){;
93 if($preys[$j][$k] eq $sig_preys[$i]){
94 $krem=$k;
95 last;
96 }
97 }
98 if($krem != 0){
99 print SC_FILE "\t$avgspec[$j][$krem]";
100 print FDR_FILE "\t$fdr[$j][$krem]";
101 }
102 else{
103 print SC_FILE "\t0";
104 print FDR_FILE "\t1";
105 }
106 }
107 print SC_FILE "\n";
108 print FDR_FILE "\n";
109 }
110 close(SC_FILE);
111 close(FDR_FILE);
112