File: differentiate.pl

package info (click to toggle)
radiant 2.7%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,048 kB
  • sloc: perl: 5,393; sh: 323; makefile: 35
file content (127 lines) | stat: -rwxr-xr-x 1,882 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env perl

use strict;

# get the path of this script; dependencies should be in the same directory
#
my $scriptPath;
BEGIN
{
	use Cwd 'abs_path';
	abs_path($0) =~ /(.*)\//;
	$scriptPath = $1;
}
use lib "$scriptPath/../lib";

use Krona;

if ( @ARGV < 3 )
{
	print "differentiate.pl <target_taxID> <bg_taxID> <blast...>\n";
	exit;
}

my ($target, $bg, @files) = @ARGV;

my @totals;

loadTaxonomy();

foreach my $file ( @files )
{
	open BLAST, "<$file";
	
	my $lastQueryID;
	my $topScore;
	
	# 0 = top hit, 1 = hit, 2 = no hit
	#
	my $targetHit;
	my $bgHit;
	
	while ( 1 )
	{
		my $line = <BLAST>;
		
		chomp $line;
		
		if ( $line =~ /^#/ )
		{
			next;
		}
		
		my
		(
			$queryID,
			$hitID,
			$identity,
			$length,
			$mismatches,
			$gaps,
			$queryStart,
			$queryEnd,
			$subjectStart,
			$subjectEnd,
			$eVal,
			$bitScore
		) = split /\t/, $line;
		
		if ( $queryID ne $lastQueryID && defined $lastQueryID )
		{
			$totals[$bgHit][$targetHit]++;
			#print "$targetHit\t$bgHit\n\n";
		}
		
		if ( ! defined $hitID )
		{
			last; # EOF
		}
		
		$hitID =~ /gi\|(\d+)/;
		
		my $gi = $1;
		
		my $taxID = getTaxID($gi);
		my $name = getName($taxID);
		
		#print "$queryID\t$taxID\t$bitScore\t$name\n";
		
		if ( $queryID ne $lastQueryID )
		{
			$topScore = $bitScore;
			$targetHit = 2;
			$bgHit = 2;
		}
		
		if ( contains($target, $taxID) )
		{
			if ( $bitScore == $topScore )
			{
				$targetHit = 0;
			}
			elsif ( $targetHit == 2 )
			{
				$targetHit = 1;
			}
		}
		elsif ( contains($bg, $taxID) )
		{
			if ( $bitScore == $topScore )
			{
				$bgHit = 0;
			}
			elsif ( $bgHit == 2 )
			{
				$bgHit = 1;
			}
		}
		
		$lastQueryID = $queryID;
	}
}

print ",,,Human\n";
print ",,top hit,hit,no hit\n";
print ",top hit,", join(',', @{$totals[0]}), "\n";
print "NHP,hit,", join(',', @{$totals[1]}), "\n";
print ",no hit,", join(',', @{$totals[2]}), "\n";