forked from keylabivdc/VIP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_tmp_table.pl
59 lines (49 loc) · 1.27 KB
/
create_tmp_table.pl
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
#!/usr/bin/perl
#
# create_tmp_table.pl
#
# This program will generate a file which include the id, gi, species, genus, family information in a tabular text.
#
# create_tmp_table.pl <annotated BOWTIE file> <annotated RAPSearch file> <NGS> <mode> <platform>
#
### Authors : Yang Li <liyang@ivdc.chinacdc.cn>
### License : GPL 3 <http://www.gnu.org/licenses/gpl.html>
### Update : 2015-08-05
### Copyright (C) 2015 Yang Li and Xuejun Ma - All Rights Reserved
use Getopt::Std;
use strict;
our ($opt_f, $opt_h);
open OUT, ">$ARGV[2].tempsorted";
getopts('f:h');
if ($opt_h) {
print <<USAGE;
create_tab_delimited_table.pl
This program will generate a file which include the id, gi, species, genus, family information in a tabular text as:
header gi species genus family
Usage:
create_tab_delimited_table.pl -f sam <file>
create_tab_delimited_table.pl -f blast <file>
USAGE
exit;
}
while (<>) {
my ($species, $genus, $family) = ("") x 3;
my @columns = split/\t/, $_;
if (/species--(.*?)\t/) {
$species = $1;
}
if (/genus--(.*?)\t/) {
$genus = $1;
}
if (/family--(.*?)\t/) {
$family = $1;
}
if ($opt_f eq "sam") {
print OUT "$columns[0]\t$columns[2]\t";
}
else {
$columns[1] =~ /(gi\|\d+\|)/;
print OUT "$columns[0]\t$1\t";
}
print OUT "$species\t$genus\t$family\n";
}