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);
}
|