-
Notifications
You must be signed in to change notification settings - Fork 1
/
taxon_lineage.pl
executable file
·48 lines (31 loc) · 1.11 KB
/
taxon_lineage.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
#!/usr/bin/perl
use Bio::Taxon;
use Bio::Tree::Tree;
open IN, $ARGV[0];
open OUT, $ARGV[1];
my $count = 0;
while (my $entry = <IN>){
$count++;
my ($genome_id, $taxon_id) = $entry=~/(.*)\t(.*) *\n/;
my $dbh = Bio::DB::Taxonomy->new(-source => 'entrez');
$taxon = $dbh->get_taxon(-taxonid => '$taxon_id');
my $tree = Bio::Tree::Tree->new();
my @lineage = ($tree->get_lineage_nodes($taxon), $taxon);
#foreach $node (@lineage) { print $node->id, ";"; } print "\n";
#foreach $node (@lineage) { print $node->scientific_name, ";"; } print "\n";
@taxon_lineage_id = "";
@taxon_lineage_name = "";
foreach $node (@lineage) {
push @taxon_lineage_id, $node->id;
}
print "\n";
foreach $node (@lineage) {
push @taxon_lineage_name, $node->scientific_name;
}
$taxon_lineage_id = "\"", join('\",\"', @taxon_lineage_id), "\"";
$taxon_lineage_name = "\"", join('\",\"', @taxon_lineage_name), "\"";
print ",\n" unless $count == 1;
print OUT "{\"genome_id\":\"$genome_id\",\"taxon_lineage_ids\":{\"set\":[@taxon_lineage_id]},\"taxon_lineage_names\":{\"set\":[@taxon_lineage_name]}}";
}
close IN;
close OUT;