annotate Dotplot_Release/SOFD.pl @ 0:dfa3436beb67 draft

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