Next changeset 1:267858c28a34 (2019-06-20) |
Commit message:
planemo upload for repository https://github.com/phac-nml/galaxy_tools/blob/master/tools/tree_relabeler commit 974af0d5e7ccfcbd47284eb85a5f593d5e48daf8 |
added:
nml_tree_relabeler.pl test-data/phylogeneticTree.newick.nhx test-data/results test-data/tabs.txt tree_relabeler.xml |
b |
diff -r 000000000000 -r 02bc0d7d40b5 nml_tree_relabeler.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nml_tree_relabeler.pl Mon Apr 29 11:18:32 2019 -0400 |
[ |
b'@@ -0,0 +1,408 @@\n+#!/usr/bin/env perl\n+\n+use strict;\n+use warnings;\n+use Bio::TreeIO;\n+use Bio::Tree::Tree;\n+use IO::String;\n+use Getopt::Long;\n+use Pod::Usage;\n+\n+my ($treefile, $tabfile, $delim, $outfile, $template, $help, $replace, $tabline, $man );\n+\n+GetOptions(\n+ \'i|treefile=s\' => \\$treefile,\n+ \'t|tabfile=s\' => \\$tabfile,\n+ \'o|outfile=s\' => \\$outfile,\n+ \'d|delim:s\' => \\$delim,\n+ \'p|print-template=s\' => \\$template,\n+ \'r|replace\' => \\$replace,\n+ \'h|help\' => \\$help,\n+ \'m|man\' => \\$man\n+);\n+\n+if ($help){\n+ pod2usage(-verbose => 99,\n+ -sections => "SYNOPSIS|OPTIONS AND ARGUMENTS|DESCRIPTION|DIAGNOSTICS");\n+} elsif ($man){\n+ pod2usage(-verbose => 2);\n+} elsif (!$treefile) {\n+ pod2usage(-msg => "**Tree file is required.**\\n",\n+ -exitval => 2,\n+ -verbose => 1,\n+ -output => \\*STDERR);\n+} elsif ( !(($template) || ($tabfile && $outfile)) ){\n+ pod2usage(-msg => "**Either select a template file, or a tab file and outfile**\\n",\n+ -exitval => 2,\n+ -verbose => 1,\n+ -output => \\*STDERR);\n+} elsif ( $treefile && $template) {\n+ generate_template();\n+} elsif ( $treefile && $tabfile && $outfile ){\n+ relabel_tree();\n+}\n+\n+sub generate_template\n+{\n+ check_treefile();\n+ print_template();\n+}\n+\n+sub relabel_tree\n+{\n+ my %new_labels;\n+ check_delimiter();\n+ %new_labels = %{load_tabfile()};\n+ check_treefile();\n+ write_treefile(\\%new_labels);\n+}\n+\n+sub print_template\n+{\n+ open my $tempout, \'>\', $template or die "Could not open file: $!";\n+ print $tempout "#label\\n";\n+\n+ my $treein = Bio::TreeIO->new(\n+ -format => "newick",\n+ -file => "$treefile"\n+ );\n+\n+ while(my $t = $treein->next_tree)\n+ {\n+ my @nodes = $t->get_nodes;\n+\n+ if (scalar(@nodes) <= 1)\n+ {\n+ print STDERR "Tree is not in newick format.\\n";\n+ exit(2);\n+ }\n+ else\n+ {\n+ foreach my $node ($t->get_leaf_nodes)\n+ {\n+ print $tempout $node->id,"\\n";\n+ }\n+ }\n+ }\n+ close ($tempout);\n+}\n+\n+sub check_delimiter\n+{\n+ if (!($delim)){\n+ $delim = \' \';\n+ } else{\n+ my $delimlen = length $delim;\n+ # delim length less than 1 indicates empty string.\n+ if ($delimlen < 1){\n+ $delim = \' \';\n+ }elsif ($delim =~ /[\\(\\)\\;\\,\\:]/){\n+ print STDERR "Delimiters cannot be Newick reserved characters \'(),;:\'.\\n";\n+ exit(1);\n+ }\n+ }\n+}\n+\n+sub load_tabfile\n+{\n+ my %new_labels;\n+ if (!(-e $tabfile)){\n+ # exit if error in tab file\n+ print STDERR "Error opening tab file.\\n";\n+ exit(1);\n+ }\n+\n+ open (my $tabin, \'<\', $tabfile);\n+\n+ # append the > to the front of the outfile string\n+ # $outfile = \'>\'.$outfile;\n+\n+ # go through tab file to add new labels to a hash file\n+ while ($tabline = <$tabin>){\n+ # skip the first row if it starts with a #\n+ next if $tabline =~ s/^#//;\n+ $tabline =~ s/\\r//g;\n+ chomp $tabline;\n+\n+ if ($tabline =~ /[\\(\\)\\;\\,\\:]/){\n+ print STDERR "New labels cannot contain Newick reserved characters \'(),;:\'.\\n";\n+ exit(1);\n+ }\n+\n+ my @splits = split("\\t", $tabline);\n+\n+ # Check that the tab file has more than one column \n+ my $num_cols = scalar @splits;\n+ if ($num_cols <= 1){\n+ # exit if one column or less; no new info to add to tree/error with tab layout.\n+ print STDERR "Tab file does not contain new labels.\\n";\n+ exit(1);\n+ }\n+ # set the hash label to the first value in a row, is the original tip label.\n+ my $label = $splits[0];\n+ # If user chose find and replace instead, get rid of the first value.\n+ shift @splits if ($replace);\n+ '..b"not contain one of the Newick reserved characters '(),:;' (required option)\n+\n+=item B<-o>, B<--out>\n+\n+The output file. (required option)\n+\n+=item B<-d>, B<--delim>\n+\n+The character to use to divide the information of the labels. Must not be one of the Newick reserved characters '(),:;' (optional)\n+\n+=item B<-r>, B<--replace>\n+\n+Replace the tip names. This option will replace the tree tip names with the specified labels, instead of adding them to the tip name.\n+\n+=item B<-p>, B<--print-template>\n+\n+The name of the output template file. Prints out a template for the tabfile.(required option)\n+\n+=item B<-h>, B<--help>\n+\n+To display help message\n+\n+=item B<-m>, B<--man>\n+\n+To display manual\n+\n+=back\n+\n+=head1 DESCRIPTION\n+\n+=over \n+\n+nml_tree_relabeler takes a newick format tree file to modify tip labels and a tab-delimited file containing current tip labels and additional information to add to the tips in 2 or more columns. Header row of the tab delimited file must start with a '#'. An example is below:\n+\n+ #label outbreak year location\n+ orgs1 outbreak1 year1 location1\n+ orgs2 outbreak2 year2 location2\n+\n+and so on.\n+\n+The information in the tab file is inserted into the tree file so the new information will appear on the tip labels.\n+\n+Alternatively, nml_tree_relabeler can print out the tip names to a tab-delimited template file.\n+\n+=back\n+\n+=head1 DIAGNOSTICS\n+\n+=over\n+\n+=item B<Tree file, tab file, and output file are required>\n+\n+Use the proper command line arguments (-i, -t, -o respectively) to add the filenames of the tree file, tab file, and output file.\n+\n+=item B<Tree file is required>\n+\n+Use the -i command line argument to add the tree file.\n+\n+=itemB<Either select a template file, or a tab file and outfile>\n+\n+Use the proper command line arguments to either add a template file (-p) to print a tab template, or to add a tab file and an output file (-t, -o respectively) to relabel a tree.\n+\n+=item B<Label not found>\n+\n+A warning that a label provided in the tab file was not found in the tree file. Relabeling continues.\n+\n+=item B<Error opening tab/tree file>\n+\n+An error occured while opening the tab/tree file, please check path/file.\n+\n+=item B<Tree is not in newick format>\n+\n+The tree file does not appear to be in newick format. Please check file and convert if necessary.\n+\n+=item B<Tab file does not contain new labels>\n+\n+The tab file only contains one column and therefore does not have any additional information to add to the tree. Please check the tab file.\n+\n+=item B<Delimiter/tabfile cannot contain Newick reserved characters '(),;:' >\n+\n+The tab file or delimiter selected contains one of the characters used in the Newick format. This will cause an error when trying to read the tree. Please modify your tab file or select a new delimiter.\n+\n+=back\n+\n+=head1 CONFIGURATION AND ENVIRONMENT\n+\n+=head1 DEPENDENCIES\n+\n+=over\n+\n+=item use Bio::TreeIO\n+\n+=item use Bio::Tree::Tree\n+\n+=back\n+\n+=head1 INCOMPATIBILITIES\n+\n+This script only works for NEWICK formatted trees. All other tree formats are not compatible. \n+\n+=head1 AUTHOR\n+\n+Jen Cabral, <jencabral@gmail.com>\n+\n+=head1 BUGS AND LIMITATIONS\n+\n+There are no known bugs in this module.\n+\n+Please report problems to Jen Cabral, <jencabral@gmail.com>\n+\n+=head1 COPYRIGHT & LICENSE \n+\n+Copyright (C) 2015 by NML\n+\n+This program is free software: you can redistribute it and/or modify\n+it under the terms of the GNU General Public License as published by\n+the Free Software Foundation, either version 3 of the License, or\n+(at your option) any later version.\n+\n+This program is distributed in the hope that it will be useful,\n+but WITHOUT ANY WARRANTY; without even the implied warranty of\n+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+GNU General Public License for more details.\n+\n+You should have received a copy of the GNU General Public License\n+along with this program. If not, see <http://www.gnu.org/licenses/>\n+\n+=cut\n\\ No newline at end of file\n" |
b |
diff -r 000000000000 -r 02bc0d7d40b5 test-data/phylogeneticTree.newick.nhx --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/phylogeneticTree.newick.nhx Mon Apr 29 11:18:32 2019 -0400 |
b |
@@ -0,0 +1,1 @@ +(reference:0.29121884); |
b |
diff -r 000000000000 -r 02bc0d7d40b5 test-data/results --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/results Mon Apr 29 11:18:32 2019 -0400 |
b |
@@ -0,0 +1,1 @@ +(reference outbreak1 year1 location1:0.29121884); \ No newline at end of file |
b |
diff -r 000000000000 -r 02bc0d7d40b5 test-data/tabs.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/tabs.txt Mon Apr 29 11:18:32 2019 -0400 |
b |
@@ -0,0 +1,1 @@ +reference outbreak1 year1 location1 |
b |
diff -r 000000000000 -r 02bc0d7d40b5 tree_relabeler.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tree_relabeler.xml Mon Apr 29 11:18:32 2019 -0400 |
b |
@@ -0,0 +1,68 @@ +<tool id="tree_relabel" name="Tree Relabeler" version="1.0.0"> + <description>Relabels the tips of a newick formatted tree.</description> + + <requirements> + <requirement type="package" version="1.7.2">perl-bioperl</requirement> + <requirement type="package" version="2.49">perl-getopt-long</requirement> + </requirements> + + <stdio> + <exit_code range="1" level="fatal" description="Error opening a file."/> + <exit_code range="2" level="fatal" description="Error with tree format."/> + </stdio> + + <command interpreter="perl"> + nml_tree_relabeler.pl -i $treefile -t $tabfile -o $output -d $delim + </command> + + <inputs> + <param name="treefile" type="data" format="txt" label="The newick formated tree file to be relabeled:" optional="false"/> + <param name="tabfile" type="data" format="txt" label="The tab separated file containing the current labels and the info to be added to the labels" optional="false"/> + <param name="delim" type="text" label="Delimiter for new tip labels (space, _, etc)" optional="true" help="If left blank, labels of updated tips will be separated by spaces."/> + </inputs> + + <outputs> + <data format="txt" name="output"/> + </outputs> + + <tests> + <test> + <param name="treefile" value="phylogeneticTree.newick.nhx"/> + <param name="tabfile" value="tabs.txt"/> + <output name="output" file="results"/> + </test> + </tests> + <help> + +What it does +============ + +This tool provides a means for relabeling the tips of a newick formatted tree. + +It takes a newick format tree file to modify tip labels and a tab-delimited file containing current tip labels and additional information to add to the tips in 2 or more columns. + +Usage +===== + +Header row of the tab delimited file must start with a '#'. An example is below: + +- #label outbreak year location +- orgs1 outbreak1 year1 location1 +- orgs2 outbreak2 year2 location2 + +and so on. + +The information in the tab file is inserted into the tree file so the new information will appear on the tip labels. + + +Input +===== + +Newick format tree + +Tab delimted file + +Desired delimiter for updated tip labels + + </help> +</tool> |