changeset 0:276e3ee68c37 draft

planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/ete commit 230ae552ddeb1bfdef3a09becaa5c6d373529a05-dirty
author earlhaminst
date Thu, 15 Dec 2016 12:55:02 -0500
parents
children a4ba317fc713
files ete_tree_generator.py ete_tree_generator.xml test-data/out.nhx test-data/species.txt
diffstat 4 files changed, 209 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ete_tree_generator.py	Thu Dec 15 12:55:02 2016 -0500
@@ -0,0 +1,56 @@
+import optparse
+
+from ete3 import NCBITaxa
+
+ncbi = NCBITaxa()
+
+parser = optparse.OptionParser()
+parser.add_option('-s', '--species', dest="input_species_filename",
+                  help='Species list in text format one species in each line')
+
+parser.add_option('-f', '--format', type='choice', choices=['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '100'], dest="format",
+                  default='8', help='outpur format for tree')
+
+parser.add_option('-t', '--treebest', type='choice', choices=['yes', 'no'], dest="treebest",
+                  default='no', help='To be used in TreeBest')
+
+parser.add_option('-d', '--database', type='choice', choices=['yes', 'no'], dest="database",
+                  default='no', help='Update database')
+
+options, args = parser.parse_args()
+
+if options.database == "yes":
+    try:
+        ncbi.update_taxonomy_database()
+    except:
+        pass
+
+if options.input_species_filename is None:
+    raise Exception('-s option must be specified, Species list in text format one species in each line')
+
+with open(options.input_species_filename) as f:
+    species_name = [_.strip().replace('_', ' ') for _ in f.readlines()]
+
+name2taxid = ncbi.get_name_translator(species_name)
+
+taxid = [name2taxid[_][0] for _ in species_name]
+
+tree = ncbi.get_topology(taxid)
+
+if options.treebest == "yes":
+    inv_map = {str(v[0]): k.replace(" ", "") + "*" for k, v in name2taxid.items()}
+else:
+    inv_map = {str(v[0]): k for k, v in name2taxid.items()}
+
+
+for leaf in tree:
+    leaf.name = inv_map[leaf.name]
+
+newickTree = tree.write(format=int(options.format))
+
+if options.treebest == "yes":
+    newickTree = newickTree.rstrip(';')
+    newickTree = newickTree + "root;"
+
+with open('newickTree.nhx', 'w') as newickFile:
+    newickFile.write(newickTree)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ete_tree_generator.xml	Thu Dec 15 12:55:02 2016 -0500
@@ -0,0 +1,90 @@
+<tool id="species_tree_generator" name="Species tree generator" version="3.0.0b35">
+    <description>from a list of species using the ETE Toolkit</description>
+     <requirements>
+        <requirement type="package" version="3.0.0b35">ete3</requirement>
+    </requirements>
+    <stdio>
+        <!-- Anything other than zero is an error -->
+        <exit_code range="1:" />
+    </stdio>
+    <command>
+    <![CDATA[
+python $__tool_directory__/ete_tree_generator.py 
+-s '$speciesFile'
+#if $output_format.treebest == 'yes'
+    -f 8
+#else
+    -f ${output_format.format_selector}
+#end if
+-t $output_format.treebest
+-d $database
+    ]]>
+    </command>
+    <inputs>
+        <param name="speciesFile" type="data" format="txt" label="Species file" help="List with one species per line" />        
+        <conditional name="output_format">
+            <param name="treebest" type="select" label="Use in TreeBest" help="Select yes if specie tree to be used in TreeBest">
+                <option value="yes">Yes</option>
+                <option value="no" selected="true">No</option>
+            </param>
+            <when value="yes" />
+            <when value="no">
+                <param name="format_selector" type="select" label="Output format" help="See table below">
+                    <option value="0" selected="true">Flexible with support values (0)</option>
+                    <option value="1">Flexible with internal node names (1)</option>
+                    <option value="2">All branches + leaf names + internal supports (2)</option>
+                    <option value="3">All branches + all names (3)</option>
+                    <option value="4">Leaf branches + leaf names (4)</option>
+                    <option value="5">Internal and leaf branches + leaf names (5)</option>
+                    <option value="6">Internal branches + leaf names (6)</option>
+                    <option value="7">Leaf branches + all names (7)</option>
+                    <option value="8">All names (8)</option>
+                    <option value="9">Leaf names (9)</option>
+                    <option value="100">Topology only (100)</option>
+                </param>
+            </when>
+        </conditional>
+        <param name="database" type="select" label="Update database" help="Update database from NCBI (slower)">
+            <option value="no" selected="true">No</option>
+            <option value="yes">Yes</option>
+        </param>
+    </inputs>
+    <outputs>
+        <data format="nhx" name="outputFile" label="${tool.name} on ${on_string}" from_work_dir="newickTree.nhx"/>
+    </outputs>
+    <tests>
+        <test>
+            <param name="speciesFile" ftype="txt" value="species.txt" />
+            <param name="treebest" value="yes" />
+            <output name="outputFile" file="out.nhx" />
+        </test>
+    </tests>
+    <help>
+    <![CDATA[
+Generate a species tree from a list of species using the `ETE Toolkit`_.
+
+.. _ETE Toolkit: http://etetoolkit.org/
+
+**Output format:**
+
+======= ============================================= ========================================================================================
+FORMAT  DESCRIPTION                                     SAMPLE
+------- --------------------------------------------- ----------------------------------------------------------------------------------------
+0       flexible with support values                    ((D:0.723274,F:0.567784)1.000000:0.067192,(B:0.279326,H:0.756049)1.000000:0.807788);
+1       flexible with internal node names               ((D:0.723274,F:0.567784)E:0.067192,(B:0.279326,H:0.756049)B:0.807788);
+2       all branches + leaf names + internal supports   ((D:0.723274,F:0.567784)1.000000:0.067192,(B:0.279326,H:0.756049)1.000000:0.807788);
+3       all branches + all names                        ((D:0.723274,F:0.567784)E:0.067192,(B:0.279326,H:0.756049)B:0.807788);
+4       leaf branches + leaf names                      ((D:0.723274,F:0.567784),(B:0.279326,H:0.756049));
+5       internal and leaf branches + leaf names         ((D:0.723274,F:0.567784):0.067192,(B:0.279326,H:0.756049):0.807788);
+6       internal branches + leaf names                  ((D,F):0.067192,(B,H):0.807788);
+7       leaf branches + all names                       ((D:0.723274,F:0.567784)E,(B:0.279326,H:0.756049)B);
+8       all names                                       ((D,F)E,(B,H)B);
+9       leaf names                                      ((D,F),(B,H));
+100     topology only                                   ((,),(,));
+======= ============================================= ========================================================================================
+    ]]>
+    </help>
+    <citations>
+        <citation type="doi">10.1093/molbev/msw046</citation>
+    </citations>
+</tool>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/out.nhx	Thu Dec 15 12:55:02 2016 -0500
@@ -0,0 +1,1 @@
+((((((((((((((((Homosapiens*,Pantroglodytes*,Gorillagorillagorilla*)207598,Pongoabelii*)9604,Nomascusleucogenys*)314295,(Chlorocebussabaeus*,Macacamulatta*,Papioanubis*)9528)9526,Callithrixjacchus*)314293,Tarsiussyrichta*)376913,(Microcebusmurinus*,Otolemurgarnettii*)376911)9443,((Oryctolaguscuniculus*,Ochotonaprinceps*)9975,(((Rattusnorvegicus*,Musmusculus*)39107,Dipodomysordii*,Ictidomystridecemlineatus*)33553,Caviaporcellus*)9989)314147,Tupaiabelangeri*)314146,(((Ailuropodamelanoleuca*,Canislupusfamiliaris*,Mustelaputoriusfuro*)379584,Feliscatus*)33554,(Erinaceuseuropaeus*,Sorexaraneus*)9362,(Myotislucifugus*,Pteropusvampyrus*)9397,((Ovisaries*,Bostaurus*)9895,Vicugnapacos*,Susscrofa*,Tursiopstruncatus*)91561,Equuscaballus*)314145)1437010,(Dasypusnovemcinctus*,Choloepushoffmanni*)9348,(Echinopstelfairi*,Loxodontaafricana*,Procaviacapensis*)311790)9347,(Sarcophilusharrisii*,Macropuseugenii*,Monodelphisdomestica*)9263)32525,Ornithorhynchusanatinus*)40674,((Pelodiscussinensis*,(((Meleagrisgallopavo*,Gallusgallus*)9005,Anasplatyrhynchos*)1549675,(Ficedulaalbicollis*,Taeniopygiaguttata*)9126)8825)1329799,Anoliscarolinensis*)32561)32524,Xenopustropicalis*)32523,Latimeriachalumnae*)8287,(((Daniorerio*,Astyanaxmexicanus*)186626,((((Tetraodonnigroviridis*,Takifugurubripes*)31031,Gasterosteusaculeatus*)1489922,((Poeciliaformosa*,Xiphophorusmaculatus*)586240,Oreochromisniloticus*)1489908)1489872,Gadusmorhua*)123368)186625,Lepisosteusoculatus*)41665)root;
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test-data/species.txt	Thu Dec 15 12:55:02 2016 -0500
@@ -0,0 +1,62 @@
+Latimeria chalumnae
+Xenopus tropicalis
+Ornithorhynchus anatinus
+Macropus eugenii
+Sarcophilus harrisii
+Monodelphis domestica
+Echinops telfairi
+Procavia capensis
+Loxodonta africana
+Dasypus novemcinctus
+Choloepus hoffmanni
+Ochotona princeps
+Oryctolagus cuniculus
+Cavia porcellus
+Ictidomys tridecemlineatus
+Dipodomys ordii
+Rattus norvegicus
+Mus musculus
+Tupaia belangeri
+Otolemur garnettii
+Microcebus murinus
+Tarsius syrichta
+Callithrix jacchus
+Chlorocebus sabaeus
+Papio anubis
+Macaca mulatta
+Nomascus leucogenys
+Pongo abelii
+Gorilla gorilla gorilla
+Pan troglodytes
+Homo sapiens
+Sorex araneus
+Erinaceus europaeus
+Pteropus vampyrus
+Myotis lucifugus
+Felis catus
+Canis lupus familiaris
+Mustela putorius furo
+Ailuropoda melanoleuca
+Equus caballus
+Vicugna pacos
+Sus scrofa
+Tursiops truncatus
+Ovis aries
+Bos taurus
+Anolis carolinensis
+Pelodiscus sinensis
+Taeniopygia guttata
+Ficedula albicollis
+Anas platyrhynchos
+Meleagris gallopavo
+Gallus gallus
+Lepisosteus oculatus
+Danio rerio
+Astyanax mexicanus
+Gadus morhua
+Oreochromis niloticus
+Poecilia formosa
+Xiphophorus maculatus
+Gasterosteus aculeatus
+Tetraodon nigroviridis
+Takifugu rubripes