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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
#!/usr/bin/env perl
use strict;
use warnings;
use File::Basename;
use lib ($ENV{EUK_MODULES});
use Fasta_reader;
my $usage = "\n\n\tusage: $0 < list of audit.txt files from stdin \n\n\n";
my $MIN_SEQ_LEN = 1000;
my $total_genes = 0;
my $total_genes_reco = 0;
my $total_refseq_trans = 0;
my $total_iso_reco_count = 0;
my $total_extra = 0;
print join("\t", "gene_id", "reco_gene_flag", "num_refseqs", "num_FL_trin", "num_extra_trin") . "\n";
my $counter = 0;
while (<>) {
chomp;
my $dir = dirname($_);
$counter++;
my $gene_id = basename($dir);
my $trin_fasta_file = "$dir/trinity_out_dir.Trinity.fasta";
if (! -e $trin_fasta_file) {
print STDERR "ERROR: Cannot locate file: $trin_fasta_file\n";
next;
}
my $fasta_reader = new Fasta_reader($trin_fasta_file);
my %trin_seqs = $fasta_reader->retrieve_all_seqs_hash();
my %trin_lens = &get_seq_lens(%trin_seqs);
my $FL_reco_file = "$dir/FL.test.pslx.maps";
my %reco_refseq;
my %reco_trin_to_refseq = &parse_reco($FL_reco_file, \%reco_refseq);
my $num_FL_trin = scalar(keys %reco_trin_to_refseq);
my $refseqs_fa = "$dir/refseqs.fa";
my @refseq_accs = &get_accs($refseqs_fa);
my $num_refseqs = scalar(@refseq_accs);
my @failed_reco_refseqs;
foreach my $acc (@refseq_accs) {
unless ($reco_refseq{$acc}) {
push (@failed_reco_refseqs, $acc);
}
}
my $num_failed_reco_refseqs = scalar(@failed_reco_refseqs);
my @extra_trin_accs;
foreach my $trin_acc (keys %trin_seqs) {
if (! exists $reco_trin_to_refseq{$trin_acc}) {
if ($trin_lens{$trin_acc} >= $MIN_SEQ_LEN) {
push (@extra_trin_accs, $trin_acc);
}
}
}
my $num_extra_trin = scalar(@extra_trin_accs);
my $reco_gene_flag = ($num_failed_reco_refseqs == 0) ? "YES" : "NO";
print join("\t", $gene_id, $reco_gene_flag, $num_refseqs, $num_FL_trin, $num_extra_trin) . "\n";
$total_genes++;
if ($reco_gene_flag eq "YES") {
$total_genes_reco++;
}
$total_refseq_trans += $num_refseqs;
$total_iso_reco_count += $num_FL_trin;
$total_extra += $num_extra_trin;
}
if ($counter > 1) {
print "\n\n";
print join("\t", "Total_Genes", "Total_Genes_Reco", "Total_RefTrans", "Total_RefTransReco", "Total_extra_trans") . "\n";
print join("\t", $total_genes, $total_genes_reco, $total_refseq_trans, $total_iso_reco_count, $total_extra) . "\n";
}
exit(0);
####
sub get_accs {
my ($fasta_file) = @_;
my @accs;
open (my $fh, $fasta_file) or die $!;
while (<$fh>) {
if (/^>(\S+)/) {
push (@accs, $1);
}
}
return(@accs);
}
####
sub parse_reco {
my ($reco_file, $reco_refseq_href) = @_;
my %trin_to_reco_acc;
open (my $fh, $reco_file) or die $!;
while (<$fh>) {
chomp;
my ($trans_acc, $trinity_contigs) = split(/\t/);
my @trin_contigs = split(/,/, $trinity_contigs);
foreach my $trin (@trin_contigs) {
$trin_to_reco_acc{$trin}->{$trans_acc} = 1;
$reco_refseq_href->{$trans_acc} = 1;
}
}
close $fh;
return(%trin_to_reco_acc);
}
####
sub get_seq_lens {
my (%trin_seqs) = @_;
my %lens;
foreach my $acc (keys %trin_seqs) {
my $seq = $trin_seqs{$acc};
my $seqlen = length($seq);
$lens{$acc} = $seqlen;
}
return(%lens);
}
|