script/normalize_multicov.pl untested

filter: Statementstmt 0.0% 0 / 62 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 9 Podpod n/a totaltotal 0.0% 0 / 97 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/env perl
2 # -*-CPerl-*-
3 # Last changed Time-stamp: <2015-06-01 16:40:16 mtw>
4 #
5 # Compute normalized expression data in TPM or RPKM from (raw) read
6 # counts in multicov.
7 # TPM reference: Wagner et al, Theory Biosci. 131(4), pp 281-85 (2012)
8 #
9 # usage: normalize_multicov.pl -i file.multicov -r 50 -o /output/path
10 #
11 # ***********************************************************************
12 # * Copyright notice
13 # *
14 # * Copyright 2015 Michael T. Wolfinger <michael@wolfinger.eu>
15 # * All rights reserved
16 # *
17 # * This program is free software: you can redistribute it and/or modify
18 # * it under the terms of the GNU General Public License as published by
19 # * the Free Software Foundation, either version 3 of the License, or
20 # * (at your option) any later version.
21 # *
22 # * This program is distributed in the hope that it will be useful,
23 # * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # * GNU General Public License for more details.
26 # *
27 # * You should have received a copy of the GNU General Public License
28 # * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 # *
30 # * This copyright notice MUST APPEAR in all copies of the script!
31 # ***********************************************************************
32  
33 use strict;
34 use warnings;
35 use Getopt::Long;
36 use Data::Dumper;
37 use File::Basename;
38 use Pod::Usage;
39 use Cwd;
40 use Path::Class;
41 use Bio::ViennaNGS::Expression;
42  
43 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
44 #^^^^^^^^^^ Variables ^^^^^^^^^^^#
45 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
46  
47 my ($infile,$FC,$FC_sample,$conds,$totreads,$i,$sample,$basename);
48 my ($dir,$ext,$cwd);
49 my $readlength = 100;
50 my $dest = getcwd();
51 my $type = "TPM";
52  
53 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
54 #^^^^^^^^^^^^^^ Main ^^^^^^^^^^^^^#
55 #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^#
56 Getopt::Long::config('no_ignore_case');
57 pod2usage(-verbose => 1) unless GetOptions("i=s" => \$infile,
58 "readlength|r=s" => \$readlength,
59 "out|o=s" => \$dest,
60 "type|t=s" => \$type,
61 "man" => sub{pod2usage(-verbose => 2)},
62 "help|h" => sub{pod2usage(1)}
63 );
64 unless(-f $infile){
65 warn "Could not find input multicov file provided via -i option";
66 pod2usage(-verbose => 0);
67 }
68  
69 unless ($type eq "TPM" || $type eq "RPKM"){
70 warn "\"$type\" is an unknown normalization type, please specify \"TPM\" or \"RPKM\"";
71 pod2usage(-verbose => 0);
72 }
73  
74 $cwd = getcwd();
75 unless ($infile =~ /^\// || $infile =~ /^\.\//){$infile = file($cwd,$infile);}
76 unless ($dest =~ /\/$/){$dest .= "/";}
77 unless (-d $dest){mkdir $dest;}
78 ($basename,$dir,$ext) = fileparse($infile,qr/\.[^.]*/);
79  
80 # parse multicov file
81 my $exp = Bio::ViennaNGS::Expression->new();
82  
83 $exp->parse_readcounts_bed12("$infile"); # stringified Path::Class object
84 #print Dumper($exp->nr_features);
85 #print Dumper($exp->data);
86  
87 # compute TPM values for all genes in each condition
88 for ($i=0;$i<$exp->conds;$i++){
89 if($type eq "TPM"){
90 $exp->computeTPM($i, $readlength);
91 }
92 else{
93 $exp->computeRPKM($i);
94 }
95 }
96  
97 # write extended BED12 file for each condition past column 12
98 if($type eq "TPM"){
99 $exp->write_expression_bed12("TPM", $dest, $basename);
100 }
101 else {
102 $exp->write_expression_bed12("RPKM", $dest, $basename);
103 }
104  
105  
106 # compute RPKM from TPM for debugging purposes
107 #for ($i=0;$i<$exp->conds;$i++){
108 # my $avRPKM = $exp->computeRPKMfromTPM($i,$readlength);
109 # warn "RPKMfromTPM (sample $i): avg RPKM $avRPKM";
110 #}
111 #$exp->write_expression_bed12("RPKMfromTPM", $dest, $basename);
112  
113 __END__