Skip to content

Instantly share code, notes, and snippets.

@soh-i
Created July 5, 2012 09:45
Show Gist options
  • Save soh-i/3052665 to your computer and use it in GitHub Desktop.
Save soh-i/3052665 to your computer and use it in GitHub Desktop.
Newick形式を与え、生物種名で色分けされた系統樹をiTolで書く
#!/usr/bin/env perl
use strict;
use warnings;
use LWP::Simple;
if ( scalar @ARGV != 1) {
die "Usage: perl $0 input.newick\n";
}
open my $fh, '<', $ARGV[0] || die $!;
while ( my $infile = <$fh> ) {
# Parsing Newick format
$infile =~ s/[()]//g;
$infile =~ s/\,/\n/g;
while ( $infile =~ m/(\d+\_\w+)\:/g ) {
my $id = $1;
my (undef, undef, $uniprot) = split /\_/, $id;
my $swiss = "http://togows.dbcls.jp/entry/uniprot/$uniprot";
my $flat = get($swiss);
if ( !$flat ) {
print "Error: Can not access to $uniprot";
}
# Taxonomy
$flat =~ m/OC\s+(\w+)/;
my $OC = $1;
my %color = (
Eukaryota => "#ff3399",
Bacteria => "#6633ff",
Archea => "#99cc00",
);
my $length = length $id;
if ( $length == 62 || $length == 63 || $length == 64 ){
# iTol output format
if ( $OC eq "Eukaryota" ) {
print "$id\t", "range\t", "$color{Eukaryota}\t", $OC, "\n";
}
elsif ( $OC eq "Bacteria" ){
print "$id\t", "range\t", "$color{Bacteria}\t", $OC, "\n";
}
elsif ( $OC eq "Archaea" ) {
print "$id\t", "range\t", "$color{Archea}\t", $OC, "\n";
}
}
sleep (2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment