annotate NEUMA-1.2.1/combine_gFVKM_iFVKM_max.pl @ 0:c44c43d185ef draft default tip

NEUMA-1.2.1 Uploaded
author chawhwa
date Thu, 08 Aug 2013 00:46:13 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
1 #!/usr/bin/perl
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
2
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
3 #This script was adopted and modified from ``scripts/combine_gFVKM_iFVKM_5.pl`.
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
4
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
5
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
6 if(@ARGV<4) { print "usage: $0 gFVKM_file iFVKM_file gene2NM_file EUMA_CUT(eg.50, in bp) output.final.gFVKM output.final.iFVKM\n"; exit; }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
7 my ($gFVKM_file, $iFVKM_file, $gene2NM_file, $CUT, $final_gFVKM_file, $final_iFVKM_file ) = @ARGV;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
8
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
9
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
10 my %gFVKM=();
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
11 my %gEUMA=();
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
12 my %allgenes=();
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
13 &read_gFVKM($gFVKM_file,\%gFVKM,\%gEUMA,\%allgenes);
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
14
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
15
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
16 my %iFVKM=();
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
17 my %iEUMA=();
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
18 my %Alltranscirpts=();
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
19 &read_iFVKM($iFVKM_file,\%iFVKM,\%iEUMA,\%Allisoforms);
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
20
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
21
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
22 my %gene2NM=();
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
23 &read_gene2NM($gene2NM_file,\%gene2NM);
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
24
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
25
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
26 my %derived_gFVKM = ();
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
27 &compute_derived_gFVKM(\%derived_gFVKM,\%iFVKM,\%allgenes);
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
28
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
29 my %final_gFVKM=();
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
30 &compute_final_gFVKM(\%allgenes,\%gFVKM,\%derived_gFVKM,\%final_gFVKM);
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
31
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
32 my %final_iFVKM=();
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
33 my %iFVKM_factor=();
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
34 &compute_final_iFVKM(\%final_iFVKM,\%iFVKM,\%final_gFVKM,\%iFVKM_factor,\%Allisoforms)
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
35
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
36 &generate_final_gFVKM_file($final_gFVKM_file,\%allgenes,\%gFVKM,\%derived_gFVKM,\%gEUMA,\%iFVKM,\%gene2NM,\%final_gFVKM);
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
37 &generate_final_iFVKM_file($final_iFVKM_file,\%iFVKM,\%final_iFVKM,\%iFVKM_factor,\%iEUMA,\%gene2NM,\%Allisoforms);
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
38
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
39
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
40
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
41 #################
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
42 ## subroutines ##
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
43 #################
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
44
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
45
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
46 sub read_gFVKM {
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
47 my $gFVKM_file = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
48 my $pGFVKM = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
49 my $pgEUMA = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
50 my $pAllgenes = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
51
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
52 open IN, $gFVKM_file or die "Can't open gFVKM file $gFVKM_file\n";
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
53 while(<IN>){
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
54 chomp;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
55 my ($gene,$gFVKM_0,$gEUMA_0) = (split/\t/)[0,1,3];
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
56 next if $gEUMA_0 < $CUT;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
57 $pGFVKM->{$gene} = $gFVKM_0;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
58 $pgEUMA->{$gene} = $gEUMA_0;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
59 $pAllgenes->{$gene}=1;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
60 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
61 close IN;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
62 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
63
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
64
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
65 sub read_iFVKM {
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
66 my $iFVKM_file = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
67 my $pIFVKM = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
68 my $piEUMA = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
69 my $pAllisoforms = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
70
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
71 open IN, $iFVKM_file or die "Can't open iFVKM file $iFVKM_file\n";
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
72 while(<IN>){
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
73 chomp;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
74 my ($gid,$isoform,$iFVKM_0,$iEUMA_0) = (split/\t/)[0,1,2,4];
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
75 next if $iEUMA_0 < $CUT;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
76 $pIFVKM->{$gid}{$isoform} = $iFVKM_0;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
77 $piEUMA->{$gid}{$isoform} = $iEUMA_0;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
78 $pAllisoforms->{$gid}{$isoform} = 1;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
79 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
80 close IN;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
81 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
82
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
83
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
84 sub read_gene2NM {
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
85 my $gene2NM_file = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
86 my $pGene2NM = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
87
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
88 open IN, $gene2NM_file or die "Can't open gene2NM file $gene2NM_file\n";
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
89 while(<IN>){
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
90 chomp;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
91 my ($gid,$isoform) = split/\t/;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
92 $pGene2NM->{$gid}{$isoform}=1;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
93 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
94 close IN;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
95 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
96
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
97
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
98
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
99 sub compute_derived_gFVKM {
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
100 my $pDerived_gFVKM = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
101 my $pIFVKM = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
102 my $pAllgenes = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
103
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
104 #compute derived gFVKM
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
105 for my $gene (keys %$pIFVKM){
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
106 my $sumiFVKM = &sum(values(%{$pIFVKM->{$gene}}));
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
107 $pDerived_gFVKM->{$gene} = $sumiFVKM;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
108 $pAllgenes->{$gene}=1;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
109 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
110 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
111
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
112
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
113 sub compute_final_iFVKM {
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
114 my $pFinal_iFVKM = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
115 my $pIFVKM = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
116 my $pFinalGFVKM = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
117 my $pIFVKM_factor = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
118 my $pAllisoforms = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
119
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
120 #rescale iFVKM based on final gFVKM
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
121 for my $gene (keys %$pIFVKM){
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
122 my $sumiFVKM = &sum(values %{$pIFVKM->{$gene}});
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
123 if($sumiFVKM == 0) { $pIFVKM_factor->{$gene} = "inf"; }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
124 else { $pIFVKM_factor->{$gene} = $pFinalGFVKM->{$gene} / $sumiFVKM; }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
125 for my $isoform (keys %{$pIFVKM->{$gene}}) {
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
126 $pFinal_iFVKM->{$gene} = $pIFVKM->{$gene};
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
127 $pAllisoforms->{$gene}{$isoform} =1;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
128 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
129 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
130
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
131 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
132
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
133
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
134 # using max of gFVKM and sumiFVKM, instead of average.
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
135 sub compute_final_gFVKM {
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
136 my $pAllgenes = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
137 my $pGFVKM = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
138 my $pDerived_gFVKM = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
139 my $pFinal_gFVKM = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
140
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
141 for my $gene (sort keys %$pAllgenes){
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
142 my $orig_gFVKM = (exists $pGFVKM->{$gene})?$pGFVKM->{$gene}:'NA';
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
143 my $derived_gFVKM_val = (exists $pDerived_gFVKM->{$gene})?$pDerived_gFVKM->{$gene}:'NA';
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
144 my $final_gFVKM = 'NA';
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
145 if($orig_gFVKM ne 'NA' && $derived_gFVKM_val ne 'NA'){
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
146 #$final_gFVKM = ($orig_gFVKM+$derived_gFVKM_val)/2; #average
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
147 $final_gFVKM = ($orig_gFVKM>=$derived_gFVKM_val?$orig_gFVKM:$derived_gFVKM_val); #maximum
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
148 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
149 elsif($orig_gFVKM eq 'NA') { $final_gFVKM = $derived_gFVKM_val; }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
150 elsif($derived_gFVKM_val eq 'NA') { $final_gFVKM = $orig_gFVKM; }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
151
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
152 $pFinal_gFVKM->{$gene} = $final_gFVKM;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
153 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
154 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
155
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
156
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
157
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
158
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
159 sub generate_final_gFVKM_file {
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
160 my $final_gFVKM_file = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
161 my $pAllgenes = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
162 my $pGFVKM = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
163 my $pDerived_gFVKM = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
164 my $pgEUMA = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
165 my $pIFVKM = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
166 my $pGene2NM = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
167 my $pFinal_gFVKM = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
168
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
169 open FG_FVKM, ">$final_gFVKM_file" or die "Can't write to final gFVKM file $final_gFVKM_file\n";
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
170 print FG_FVKM "gene\tfinal.gFVK\torig.gFVK\tderived_gFVK\tgEUMA\t#isoforms\t#measured_isoforms\n";
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
171 for my $gene (sort keys %$pAllgenes){
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
172
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
173 my $orig_gFVKM = (exists $pGFVKM->{$gene})?$pGFVKM->{$gene}:'NA';
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
174 my $derived_gFVKM = (exists $pDerived_gFVKM->{$gene})?$pDerived_gFVKM->{$gene}:'NA';
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
175 my $final_gFVKM = (exists $pFinal_gFVKM->{$gene})?$pFinal_gFVKM->{$gene}:'NA';
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
176
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
177 my $gEUMA='';
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
178 if(exists $pgEUMA->{$gene}){ $gEUMA = $pgEUMA->{$gene}; }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
179 else { $gEUMA = 'below_cut'; }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
180
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
181 my $nTr = scalar keys %{$pGene2NM->{$gene}};
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
182 my $nTr_measured = scalar keys %{$pIFVKM->{$gene}};
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
183
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
184 print FG_FVKM "$gene\t$final_gFVKM\t$orig_gFVKM\t$derived_gFVKM\t$gEUMA\t$nTr\t$nTr_measured\n";
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
185 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
186 close FG_FVKM;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
187 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
188
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
189
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
190
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
191 sub generate_final_iFVKM_file {
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
192 my $final_iFVKM_file = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
193 my $pIFVKM = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
194 my $pFinal_iFVKM = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
195 my $pIFVKM_factor = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
196 my $piEUMA = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
197 my $pGene2NM = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
198 my $pAllisoforms = shift @_;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
199
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
200 #print scalar keys %$pDerived_iFVKM; ##DEBUGGING
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
201
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
202 open FI_FVKM, ">$final_iFVKM_file" or die "Can't write to final iFVKM file $final_iFVKM_file\n";
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
203 print FI_FVKM "gene\tisoform\tfinal.iFVK\torig.iFVK\tiFVKM.factor\tiEUMA\t#isoforms\t#measured_isoforms\n";
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
204 for my $gene (sort keys %$pAllisoforms){
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
205
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
206 my $nTr = scalar keys %{$pGene2NM->{$gene}};
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
207 my $nTr_measured = scalar keys %{$pIFVKM->{$gene}};
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
208
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
209 my $iFVKM_factor = (exists $pIFVKM_factor->{$gene})?$pIFVKM_factor->{$gene}:'NA';
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
210
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
211 for my $isoform (sort keys %{$pAllisoforms->{$gene}}){
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
212
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
213 my $iEUMA='';
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
214 if(exists $piEUMA->{$gene}{$isoform}) { $iEUMA = $piEUMA->{$gene}{$isoform}; }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
215 else { $iEUMA = 'below_cut'; }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
216
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
217 my $final_iFVKM = (exists $pFinal_iFVKM->{$gene} && exists ${$pFinal_iFVKM->{$gene}}{$isoform})?$pFinal_iFVKM->{$gene}{$isoform}:$pIFVKM->{$gene}{$isoform};
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
218 print FI_FVKM "$gene\t$isoform\t$final_iFVKM\t$pIFVKM->{$gene}{$isoform}\t$iFVKM_factor\t$iEUMA\t$nTr\t$nTr_measured\n";
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
219 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
220 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
221 close FI_FVKM;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
222 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
223
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
224 sub sum {
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
225 my $s=0;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
226 while(defined(my $x=shift @_)){
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
227 $s+=$x;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
228 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
229 return $s;
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
230 }
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
231
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
232
c44c43d185ef NEUMA-1.2.1 Uploaded
chawhwa
parents:
diff changeset
233