]> git.donarmstrong.com Git - rsem.git/blob - extract-transcript-to-gene-map-from-trinity
Added error detection for cases such as a read's two mates having different names...
[rsem.git] / extract-transcript-to-gene-map-from-trinity
1 #!/usr/bin/env perl
2
3 use strict;
4
5 if (scalar(@ARGV) != 2) {
6     print "Usage: extract-transcript-to-gene-map-from-trinity trinity_fasta_file map_file\n";
7     exit(-1);
8 }
9
10 open(INPUT, $ARGV[0]);
11 open(OUTPUT, ">$ARGV[1]");
12
13 my ($tag, $line);
14 $tag = <INPUT>; chomp($tag);
15 while (substr($tag, 0, 1) eq ">") {
16     $tag = substr($tag, 1);
17     my $cnt = 0;
18     while (($line = <INPUT>) && substr($line, 0, 1) ne ">") {
19         $cnt++;
20     }
21     if ($cnt == 0) { print "Warning: Fasta entry $tag has an empty sequence, it is omitted.\n"; }
22     else {
23         my ($tid, @tmp) = split(/ /, $tag);
24         my ($comp, $c, @tmp) = split(/_/, $tag);
25         my $gid = join("_", $comp, $c);
26         print OUTPUT "$gid\t$tid\n";
27     }
28     $tag = $line; chomp($tag);
29
30
31 close(INPUT);
32 close(OUTPUT);
33
34