File: get_longest_ORF_per_transcript.pl

package info (click to toggle)
transdecoder 5.7.1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 29,088 kB
  • sloc: perl: 11,574; python: 271; sh: 147; makefile: 73
file content (61 lines) | stat: -rwxr-xr-x 1,329 bytes parent folder | download
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
#!/usr/bin/env perl

use strict;
use warnings;

use FindBin;
use lib ("$FindBin::Bin/../PerlLib");
use Fasta_reader;

my $usage = "\n\n\tusage: $0 all_long_orfs.pep\n\n";

my $pep_file = $ARGV[0] or die $usage;

 main: {

     my %contig_to_longest_prot;
     
     my $fasta_reader = new Fasta_reader($pep_file);
     while (my $seq_obj = $fasta_reader->next()) {
         my $header = $seq_obj->get_header();
         my $sequence = $seq_obj->get_sequence();
         my $len = length($sequence);

         if ($header =~ / (\S+):\d+-\d+\([+-]\)/) {
             my $contig = $1;
             &store_entry(\%contig_to_longest_prot, $seq_obj, $len, $contig);
         }
         else {
             die "Error, cannot parse header info: $header ";
         }
     }
     
     foreach my $struct (values %contig_to_longest_prot) {
         my $fa = $struct->{seq_obj}->get_FASTA_format();

         print $fa;
     }

     exit(0);
}

####
sub store_entry {
    my ($contig_to_longest_prot_href, $seq_obj, $len, $contig) = @_;

    my $struct = $contig_to_longest_prot_href->{$contig};
    
    if ( (! $struct) || $struct->{length} < $len) {
        
        $struct = { seq_obj => $seq_obj,
                    length => $len,
        };

        $contig_to_longest_prot_href->{$contig} = $struct;
    }

    return;
}