File: transcript_fasta_to_ORF_pics.pl

package info (click to toggle)
trinityrnaseq 2.11.0%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 417,528 kB
  • sloc: perl: 48,420; cpp: 17,749; java: 12,695; python: 3,124; sh: 1,030; ansic: 983; makefile: 688; xml: 62
file content (170 lines) | stat: -rwxr-xr-x 5,811 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env perl

use lib ("/usr/lib/trinityrnaseq/PerlLib");

use strict;
use warnings;
use Getopt::Std;
use Fasta_reader;
use Longest_orf;
use List::Util qw (min max);

use Bio::Graphics;
use Bio::SeqFeature::Generic;

my $usage = "\n\nusage: $0 transcripts.fasta\n\n";

my $transcripts_fasta_file = $ARGV[0] or die $usage;
my $min_prot_len = 50;


main: {

    my $fasta_reader = new Fasta_reader($transcripts_fasta_file);
    

    while (my $seq_obj = $fasta_reader->next()) {

        my $acc = $seq_obj->get_accession();
        my $sequence = $seq_obj->get_sequence();
        
        my $seq_length = length($sequence);
        

        my $panel = Bio::Graphics::Panel->new(
                                              -length    => $seq_length,
                                              -width     => 800,
                                              -pad_left  => 10,
                                              -pad_right => 10,
                                              );
        
        my $full_length = Bio::SeqFeature::Generic->new(
                                                        -start => 1,
                                                        -end   => $seq_length,
                                                        -strand => 1,
                                                        -display_name => $acc,
                                                        );
        
        
        
        ## add ticker
        $panel->add_track($full_length,
                          -glyph   => 'arrow',
                          -tick    => 2,
                          -fgcolor => 'black',
                          -double  => 1,
                          
                          );
        
        ## add feature
        $panel->add_track($full_length,
                          -glyph   => 'transcript2',
                          -bgcolor => 'black',
                          -label => 1,
                          );


        my $longest_orf_finder = new Longest_orf();
        $longest_orf_finder->allow_5prime_partials();
        $longest_orf_finder->allow_3prime_partials();

        my @orf_structs = $longest_orf_finder->capture_all_ORFs($sequence);
        
        

        
        @orf_structs = reverse sort {$a->{length}<=>$b->{length}} @orf_structs;

        
        

        my $top_track = $panel->add_track(-glyph => 'transcript2',
                                          -label => 1,
                                          -strand_arrow => 1,
                                          -bgcolor => 'blue',
                                          
                                          );
        
        my $bottom_track = $panel->add_track(-glyph => 'transcript2',
                                             -label => 1,
                                             -strand_arrow => 1,
                                             -bgcolor => 'red',
                                             );
        

        my $pep_file = "$acc.orfs.pep";
        my $cds_file = "$acc.orfs.cds";
        
        open (my $pep_ofh, ">$pep_file") or die "Error, cannot write to $pep_file";
        open (my $cds_ofh, ">$cds_file") or die "Error, cannot write to $cds_file";
        
        foreach my $orf (@orf_structs) {
            
            my $start = $orf->{start};
            my $stop = $orf->{stop};
            
            if ($stop <= 0) { $stop += 3; } # edge issue
            
            my $length = int($orf->{length}/3);
            if ($length < $min_prot_len) { next; }
            
            my $orient = $orf->{orient};
            my $protein = $orf->{protein};
            my $cds = $orf->{sequence};
            

            my $frame = $start % 3;
            if ($frame == 0) {
                $frame = 3;
            }
            
            my $orf_name = "$acc.$start-$stop.F$frame";
            print $pep_ofh ">$orf_name\n$protein\n";
            print $cds_ofh ">$orf_name\n$cds\n";
            

            if ($orient eq '+') {
                
                                
                my $feature = Bio::SeqFeature::Generic->new(
                                                            -start        => $start,
                                                            -end          => $stop,
                                                            -display_name => "orf: $start-$stop (F:$frame)",
                                                            -strand => 1,
                                                            
                                                            );
                $top_track->add_feature($feature);
                
            }
            else {
                # minus strand
            
                $frame = -1 * $frame;
    
                my $feature = Bio::SeqFeature::Generic->new(
                                                            -start        => $start,
                                                            -end          => $stop,
                                                            -display_name => "orf: $start-$stop (F:$frame)",
                                                            -strand => -1,
                                                            
                                                            );
                $bottom_track->add_feature($feature);
            }
        }
        close $pep_ofh;
        close $cds_ofh;
        

        my $img_filename = "$acc.orf.png";
        print STDERR "-writing: $img_filename\n";
        open (my $ofh, ">$img_filename") or die "Error, cannot write to file $img_filename";
        binmode($ofh);
        print $ofh $panel->png();
        close $ofh;
    }
    

    exit(0);
}