Repository navigation
Expand file tree
/
Copy pathGetRepTranscripts.pl
More file actions
executable file
·94 lines (86 loc) · 2.49 KB
/
Copy pathGetRepTranscripts.pl
File metadata and controls
executable file
·94 lines (86 loc) · 2.49 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/perl
# written by E Meyer, eli.meyer@science.oregonstate.edu
# distributed without any guarantees or restrictions
# -- check for dependencies and arguments
$mod1="Bio::SeqIO";
unless(eval("require $mod1")) {print "$mod1 not found. Exiting\n"; exit;}
use Bio::SeqIO;
$scriptname=$0; $scriptname =~ s/.+\///g;
unless ($#ARGV==3)
{
print "\nSelects the longest representative for each component or\n";
print "subcomponent in a Trinity transcriptome assembly.\n";
print "Usage: $scriptname assembly.fasta option output.tab output.fasta\n";
print "Where:\n";
print "\tassembly.fasta:\tthe input file, assembled by Trinity\n";
print "\toption:\t\tc for component, or s for subcomponent\n";
print "\toutput.tab:\ta name for the output summary file\n";
print "\toutput.fasta:\ta name for the output file of representative transcripts\n\n";
exit;
}
# define variables
$inseq = $ARGV[0];
$opt = $ARGV[1];
$outtab = $ARGV[2];
$outseq = $ARGV[3];
$iseqs = new Bio::SeqIO(-file=>$inseq, -format=>"fasta");
$oseqs = new Bio::SeqIO(-file=>">$outseq", -format=>"fasta");
open(OUT, ">$outtab");
# record length, component, and subcomponent for each transcript
while ($seq = $iseqs->next_seq)
{
$noseq++;
$rsid = $seq->display_id;
@rsa = split("_", $rsid);
$nh{$rsid}{"c"} = $rsa[0];
$nh{$rsid}{"s"} = $rsa[0]."_".$rsa[1];
$clh{$rsa[0]}{$rsid} = $seq->length;
$slh{$rsa[0]."_".$rsa[1]}{$rsid} = $seq->length;
$nrch{$rsa[0]}++;
$nrsh{$rsa[0]."_".$rsa[1]}++;
}
# build a hash of selected transcripts
if ($opt eq "c")
{
print OUT "comp\tmembers\tlongest\n";
foreach $c (sort(keys(%clh)))
{
%subch = %{$clh{$c}};
@ta = sort{$subch{$b}<=>$subch{$a}}(keys(%subch));
$nmc = @ta;
$ti = $ta[0];
$gh{$ti}++;
print OUT $c, "\t", $nmc, "\t", $ti, "\n";
}
}
elsif ($opt eq "s")
{
print OUT "subcomp\tmembers\tlongest\n";
foreach $s (sort(keys(%slh)))
{
%subsh = %{$slh{$s}};
@ta = sort{$subsh{$b}<=>$subsh{$a}}(keys(%subsh));
$nms = @ta;
$ti = $ta[0];
$gh{$ti}++;
print OUT $s, "\t", $nms, "\t", $ti, "\n";
}
}
# write out selected transcripts to output
$iseqs = new Bio::SeqIO(-file=>$inseq, -format=>"fasta");
while ($seq = $iseqs->next_seq)
{
$rsid = $seq->display_id;
if(exists($gh{$rsid}))
{
$oseqs->write_seq($seq);
}
}
# print summary output
@nrca = keys(%nrch);
@nrsa = keys(%nrsh);
$nnrc = @nrca;
$nnrs = @nrsa;
print STDERR $noseq, " sequences in input file.\n";
print STDERR $nnrc, " components.\n";
print STDERR $nnrs, " subcomponents.\n";