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

use strict;
use warnings;
use FindBin;
use lib ("$FindBin::RealBin/../../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);
}