File: merge_blast_n_rsem_results.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 (59 lines) | stat: -rwxr-xr-x 1,443 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
#!/usr/bin/env perl

use strict;
use warnings;
use lib ("/usr/lib/trinityrnaseq/PerlLib");
use Fasta_reader;

my $usage = "usage: $0 rsem.out blast.outfmt6 [transcripts.fasta]\n\n";

my $rsem_out = $ARGV[0] or die $usage;
my $blast_out = $ARGV[1] or die $usage;
my $transcripts_fasta = $ARGV[2];

main: {

    my %rsem_text;
    my $rsem_header;
    {
        open (my $fh, $rsem_out) or die $!;
        $rsem_header = <$fh>;
        chomp $rsem_header;
        while (<$fh>) {
            chomp;
            my $line = $_;
            my @x = split(/\t/);
            my ($gene, $trans_list) = ($x[0], $x[1]);
            foreach my $ele ($gene, split(/,/, $trans_list)) {
                $rsem_text{$ele} = $line;
            }
        }
        close $fh;
    }

    my %trans_seqs;
    if ($transcripts_fasta) {
        my $fasta_reader = new Fasta_reader($transcripts_fasta);
        %trans_seqs = $fasta_reader->retrieve_all_seqs_hash($transcripts_fasta);
    }
    

    open (my $fh, $blast_out) or die $!;
    my $header = <$fh>;
    print "$rsem_header\t$header";
    while (<$fh>) {
        chomp;
        my $line = $_;
        my @x = split(/\t/);
        my $acc = $x[0];
        my $rsem_line = $rsem_text{$acc} or die "Error, no rsem text for $acc";
        print "$rsem_line\t$line";
        if (my $seq = $trans_seqs{$acc}) {
            print "\t$seq";
        }
        print "\n";
    }
    close $fh;
    
    exit(0);
}