Mercurial > repos > earlhaminst > blast_parser
comparison blast_parser.pl @ 0:87eda806422d draft
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/blast_parser commit 75c6b4d9bd23cdd5f8e5626b1b01f2abba32c274-dirty
author | earlhaminst |
---|---|
date | Mon, 12 Dec 2016 07:13:57 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:87eda806422d |
---|---|
1 #!/usr/bin/perl | |
2 use strict; | |
3 use warnings; | |
4 use List::Util qw(min max); | |
5 | |
6 # A simple Perl parser to convert a BLAST 12-column or 24-column output into a | |
7 # 3-column input for hcluster_hg (id1, id2, weight): | |
8 # parse_blast.pl <file> | |
9 | |
10 use constant LOG_E_10 => log(10); | |
11 | |
12 my $file1 = $ARGV[0]; | |
13 open my $fh1, '<', $file1; | |
14 | |
15 while (my $line = <$fh1>) { | |
16 my @row = split(/\t/, $line); | |
17 | |
18 if ($row[0] eq $row[1]) { | |
19 # ignore self matching hits | |
20 } else { | |
21 # Convert evalue to an integer weight with max 100 | |
22 my $weight = 100; | |
23 | |
24 #if the evalue is 0, leave weight at 100 | |
25 if ($row[10] != 0 && $row[10] != 0.0) { | |
26 $weight = min(100, positive_round(-1 * log10($row[10]))); | |
27 } | |
28 print"$row[0]\t$row[1]\t$weight\n"; | |
29 } | |
30 } | |
31 close $fh1; | |
32 | |
33 # Calculate logarithm to base 10 of a number | |
34 sub log10 { | |
35 my $n = shift; | |
36 return log($n) / LOG_E_10; | |
37 } | |
38 | |
39 # Round a positive float to the nearest integer | |
40 sub positive_round{ | |
41 my $n = shift; | |
42 return int($n + 0.5); | |
43 } |