From f458a4c4f1ff3134c5cda4fb90d71cafd73cd96a Mon Sep 17 00:00:00 2001 From: Hirokazu Chiba Date: Sat, 23 Dec 2023 10:49:04 +0900 Subject: [PATCH] Add bin/taxid_labels.pl --- bin/taxid_labels.pl | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100755 bin/taxid_labels.pl diff --git a/bin/taxid_labels.pl b/bin/taxid_labels.pl new file mode 100755 index 0000000..bacf2a7 --- /dev/null +++ b/bin/taxid_labels.pl @@ -0,0 +1,48 @@ +#!/usr/bin/perl -w +use strict; +use File::Basename; +use Getopt::Std; +my $PROGRAM = basename $0; +my $USAGE= +"Usage: $PROGRAM +"; + +my %OPT; +getopts('', \%OPT); + +if (!@ARGV) { + print STDERR $USAGE; + exit 1; +} +my ($TAXID) = @ARGV; + +my @TAXON = `spang spang taxid $TAXID | cut -f2`; +chomp(@TAXON); + +my @OUT = (); +for (my $i=0; $i<@TAXON; $i++) { + my $taxon = $TAXON[$i]; + $taxon =~ s/^"//; + $taxon =~ s/"$//; + + if ($i == 0) { + if ($taxon ne "root") { + die $taxon; + } + next; + } + + if ($i == 1) { + if ($taxon ne "cellular organisms") { + die $taxon; + } + next; + } + + if ($taxon =~ /;/) { + die; + } + push @OUT, $taxon; +} + +print $TAXID, "\t", join(";", @OUT)."\n";