File: TophatCufflinksWrapper.pl

package info (click to toggle)
trinityrnaseq 2.2.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 212,452 kB
  • ctags: 5,067
  • sloc: perl: 45,552; cpp: 19,678; java: 11,865; sh: 1,485; makefile: 613; ansic: 427; python: 313; xml: 83
file content (199 lines) | stat: -rwxr-xr-x 4,897 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/usr/bin/env perl

use strict;
use warnings;

use Carp;
use Getopt::Long qw(:config no_ignore_case bundling pass_through);
use File::Basename;
use FindBin;
use Cwd;

my $usage = <<__EOUSAGE__;

###############################################################################
#
# Required:
#
#  --target <string>       : genome multifasta file
#  --seqType <string>      :type of reads ('fq' or 'fa')
#
#  If paired reads:
#      --left  <string>    :left reads
#      --right <string>    :right reads
#
#  Or, if unpaired reads:
#      --single <string>   :single reads 
#
#  --output|-o <string>               :name of directory for output 
#
#  -i <int>                :min intron length
#  -I <int>                :max intron length 
#
#
# Optional:
#
#  --SS_lib_type <string>          :strand-specific library type : {RF, FR, R, F}  (RF =~ fr-firststrand)
#  --CPU <int>                     :number of CPUs to use
#
#  --GTF <string>                  :annotations to assist, provided in GTF file format
#
###############################################################################


__EOUSAGE__

    ;



my $help_flag;

my ($seqType, $left_file, $right_file, $single_file, $SS_lib_type, $output_dir, $CPU, $target_genome, $min_intron_length, $max_intron_length);

my $GTF_annots;

&GetOptions ( 'h' => \$help_flag,
              
              ## general opts
              "seqType=s" => \$seqType,
              "left=s" => \$left_file,
              "right=s" => \$right_file,
              "single=s" => \$single_file,
              "target=s" => \$target_genome,

              "SS_lib_type=s" => \$SS_lib_type,
              "output|o=s" => \$output_dir,

              'CPU=i' => \$CPU,
              'GTF=s' => \$GTF_annots,

              'i=i' => \$min_intron_length,
              'I=i' => \$max_intron_length,
              
              );


if (@ARGV) {
    die "Error, do not understand options: @ARGV\n";
}

unless ($seqType && $target_genome && ( ($single_file) || ($left_file && $right_file) ) && $output_dir) {
    die $usage;
}

if ($GTF_annots) {
    ## add full path
    if ($GTF_annots !~ /^\//) {
        $GTF_annots = cwd() . "/$GTF_annots";
    }
}


main: {

    my $util_dir = "$FindBin::RealBin/..";
    
    #############################
    ## align reads using Tophat
    #############################
    
    my $cmd = "$util_dir/alignReads.pl --seqType $seqType --output $output_dir --aligner tophat2 --target $target_genome ";
    if ($single_file) {
        $cmd .= " --single $single_file ";
    }
    else {
        $cmd .= " --left $left_file --right $right_file ";
    }
    if ($SS_lib_type) {
        $cmd .= " --SS_lib_type $SS_lib_type ";
    }
    if ($min_intron_length) {
        $cmd .= " -i $min_intron_length ";
    }
    if ($max_intron_length) {
        $cmd .= " -I $max_intron_length ";
    }
    

    if ($CPU || $GTF_annots) {
        $cmd .= " -- ";

        if ($CPU) {
            $cmd .= " -p $CPU ";
        }
        if ($GTF_annots) {
            $cmd .= " --GTF $GTF_annots ";
            
            my $transcriptome_index_dir = "$GTF_annots.tuxedo_indices";
            if (-d $transcriptome_index_dir) {
                my $prefix = basename($GTF_annots);
                $prefix =~ s/\.[^\.]+$//;
                $cmd .= " --transcriptome-index $transcriptome_index_dir/$prefix ";
            }
            else {
                #die "Error, cannot find: $transcriptome_index_dir";
                print STDERR "WARNING: cannot find pre-built index for $GTF_annots; this will slow it down.\n";
            }
                        
        }
    }
    
    &process_cmd($cmd);
    
    
    #######################################
    # assemble transcripts using cufflinks
    #######################################

    my $tophat_alignment_bam = "$output_dir/tophat_out/accepted_hits.bam";

    $cmd = "cufflinks  --no-update-check --upper-quartile-norm -o $output_dir/cuff_out ";
    if ($GTF_annots) {
        $cmd .= " --GTF-guide $GTF_annots ";
    }


    
    
    if ($SS_lib_type) {
        my %tuxedo_lib_type = (RF => "fr-firststrand",
                               R => "fr-firststrand",
                               FR => "fr-secondstrand",
                               F => "fr-secondstrand",
                               );
        
        my $lib_type = $tuxedo_lib_type{$SS_lib_type} or die "Error, cannot determine tophat lib_type based on SS_lib_type: $SS_lib_type ";
        
        $cmd .= " --library-type $lib_type ";
    }
    
    if ($CPU) {
        $cmd .= " -p $CPU ";
    }
    
    $cmd .= " $tophat_alignment_bam ";
    
    &process_cmd($cmd);

    exit(0);
    
}


####
sub process_cmd {
    my ($cmd) = @_;

    print STDERR "CMD: $cmd\n";
    
    my $ret = system($cmd);
    if ($ret) {
        die "Error, cmd: $cmd died with ret $ret";
    }

    return;
}