annotate Dotplot_Release/SOFD.pl @ 13:e74888e94f96 draft

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