Mercurial > repos > earlhaminst > ete
changeset 5:817031b8486d draft
planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/ete commit b97aee603b9acf29981719160e963a1efe2946d0
author | earlhaminst |
---|---|
date | Thu, 10 May 2018 06:15:17 -0400 |
parents | 87b6de3ef63e |
children | f1eca1158f21 |
files | ete_homology_classifier.py ete_homology_classifier.xml test-data/11_homology.csv test-data/11_homology.tabular |
diffstat | 4 files changed, 427 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ete_homology_classifier.py Thu May 10 06:15:17 2018 -0400 @@ -0,0 +1,78 @@ +from __future__ import print_function + +import optparse + +from ete3 import PhyloTree + + +def main(): + usage = "usage: %prog --genetree <genetree-file> --speciestree <speciestree-file> [options]" + parser = optparse.OptionParser(usage=usage) + parser.add_option('--genetree', help='GeneTree in nhx format') + parser.add_option('--out_format', type='string', default='tabular', help='Choose output format') + parser.add_option('--filters', default='', help='Filter families') + + options, args = parser.parse_args() + + if options.genetree is None: + parser.error("--genetree option must be specified, GeneTree in nhx format") + + # reads single gene tree + genetree = PhyloTree(options.genetree) + + leaves_list = genetree.get_leaf_names() + # Genetree nodes are required to be in gene_species format + leaves_list = [_ for _ in leaves_list if '_' in _] + + species_list = [_.split("_")[1] for _ in leaves_list] + + species_dict = {} + for species in species_list: + count = "one" + if species in species_dict: + count = "many" + species_dict[species] = count + + homologies = { + 'one-to-one': [], + 'one-to-many': [], + 'many-to-one': [], + 'many-to-many': [], + 'paralogs': [] + } + + # stores relevant homology types in dict + for i, leaf1 in enumerate(leaves_list): + for leaf2 in leaves_list[i + 1:]: + id1 = leaf1.split(":")[1] if ":" in leaf1 else leaf1 + id2 = leaf2.split(":")[1] if ":" in leaf2 else leaf2 + species1 = id1.split("_")[1] + species2 = id2.split("_")[1] + if species1 == species2: + homology_type = 'paralogs' + else: + homology_type = species_dict[species1] + "-to-" + species_dict[species2] + homologies[homology_type].append((id1, id2)) + + options.filters = options.filters.split(",") + + if options.out_format == 'tabular': + for homology_type, homologs_list in homologies.items(): + # checks if homology type is in filter + if homology_type in options.filters: + for (gene1, gene2) in homologs_list: + print("%s\t%s\t%s" % (gene1, gene2, homology_type)) + elif options.out_format == 'csv': + print_family = True + for homology_type, homologs_list in homologies.items(): + if homologs_list and homology_type not in options.filters: + print_family = False + break + + # prints family if homology type is not found in filter + if print_family: + print(','.join(leaves_list)) + + +if __name__ == "__main__": + main()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ete_homology_classifier.xml Thu May 10 06:15:17 2018 -0400 @@ -0,0 +1,95 @@ +<tool id="ete_homology_classifier" name="Homology Classifier and Filter" version="@VERSION@"> + <description>from a genetree utilising the ETE Toolkit</description> + <macros> + <import>ete_macros.xml</import> + <xml name="homologies_macro" token_label="" token_help=""> + <param name="homologies" type="select" multiple="true" optional="false" display="checkboxes" label="@LABEL@" help="@HELP@"> + <option value="one-to-one" selected="true">one-to-one</option> + <option value="one-to-many" selected="true">one-to-many</option> + <option value="many-to-one" selected="true">many-to-one</option> + <option value="many-to-many" selected="true">many-to-many</option> + <option value="paralogs" selected="true">Paralogs</option> + </param> + </xml> + </macros> + <expand macro="requirements" /> + <command detect_errors="exit_code"> + <![CDATA[ +python '$__tool_directory__/ete_homology_classifier.py' +--genetree '$genetreeFile' +--out_format '$format_type.out_format' +#if $format_type.homologies: + --filters $format_type.homologies +#end if +> $homology + ]]> + </command> + <inputs> + <param name="genetreeFile" type="data" format="nhx" label="GeneTree file" help="GeneTree in nhx format, where nodes are in form of geneid_species" /> + <conditional name="format_type"> + <param name="out_format" type="select" label="Output format"> + <option value="tabular" selected="true">Tabular</option> + <option value="csv">One-line CSV</option> + </param> + <when value="tabular"> + <expand macro="homologies_macro" label="Pair types to keep"/> + </when> + <when value="csv"> + <expand macro="homologies_macro" label="Allowed homology types for the GeneTree" help="If the GeneTree contains any other homology type, then the output will be empty" /> + </when> + </conditional> + </inputs> + <outputs> + <data format="tabular" name="homology" label="${tool.name} on ${on_string}"> + <change_format> + <when input="format_type.out_format" value="csv" format="csv" /> + </change_format> + </data> + </outputs> + <tests> + <test> + <param name="genetreeFile" ftype="nhx" value="genetree.nhx" /> + <param name="out_format" value="tabular"/> + <param name="homologies" value="one-to-one,one-to-many,many-to-one,many-to-many,paralogs" /> + <output name="homology" file="11_homology.tabular" /> + </test> + <test> + <param name="genetreeFile" ftype="nhx" value="11_genetree.nhx" /> + <param name="out_format" value="csv"/> + <output name="homology" file="11_homology.csv" /> + </test> + </tests> + <help> + <![CDATA[ +Classify and filter Homology from single GeneTree by utilising the `ETE Toolkit`_. + +.. _ETE Toolkit: http://etetoolkit.org/ + +**Output format:** + +*tabular*: + +====================== ======================== ============ + gene_1 gene_2 homology +====================== ======================== ============ +insr_rattusnorvegicus insr_musmusculus one-to-one +insr_rattusnorvegicus insr_homosapiens one-to-one +insr_rattusnorvegicus insr_pantroglodytes one-to-one +insr_rattusnorvegicus insr_susscrofa one-to-one +insr_musmusculus insr_homosapiens one-to-one +insr_musmusculus insr_pantroglodytes one-to-one +insr_musmusculus insr_susscrofa one-to-one +insr_homosapiens insr_pantroglodytes one-to-one +insr_homosapiens insr_susscrofa one-to-one +insr_pantroglodytes insr_susscrofa one-to-one +====================== ======================== ============ + +\ + +*One-line CSV*:: + + insr_rattusnorvegicus,insr_musmusculus,insr_homosapiens,insr_pantroglodytes,insr_susscrofa + ]]> + </help> + <expand macro="citations" /> +</tool>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/11_homology.csv Thu May 10 06:15:17 2018 -0400 @@ -0,0 +1,1 @@ +insr_rattusnorvegicus,insr_musmusculus,insr_homosapiens,insr_pantroglodytes,insr_susscrofa
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/11_homology.tabular Thu May 10 06:15:17 2018 -0400 @@ -0,0 +1,253 @@ +insr_rattusnorvegicus insr_musmusculus many-to-many +insr_rattusnorvegicus insr_homosapiens many-to-many +insr_rattusnorvegicus insr_pantroglodytes many-to-many +insr_rattusnorvegicus insr_susscrofa many-to-many +insr_rattusnorvegicus maob_musmusculus many-to-many +insr_rattusnorvegicus maob_homosapiens many-to-many +insr_rattusnorvegicus maob_pantroglodytes many-to-many +insr_rattusnorvegicus maob_susscrofa many-to-many +insr_rattusnorvegicus maob_canisfamiliaris many-to-many +insr_rattusnorvegicus maoa_musmusculus many-to-many +insr_rattusnorvegicus maoa_homosapiens many-to-many +insr_rattusnorvegicus maoa_pantroglodytes many-to-many +insr_rattusnorvegicus maoa_susscrofa many-to-many +insr_rattusnorvegicus maoa_canisfamiliaris many-to-many +insr_rattusnorvegicus brat1_musmusculus many-to-many +insr_rattusnorvegicus brat1_homosapiens many-to-many +insr_rattusnorvegicus brat1_pantroglodytes many-to-many +insr_rattusnorvegicus brat1_susscrofa many-to-many +insr_rattusnorvegicus brat1_canisfamiliaris many-to-many +insr_musmusculus insr_homosapiens many-to-many +insr_musmusculus insr_pantroglodytes many-to-many +insr_musmusculus insr_susscrofa many-to-many +insr_musmusculus maob_rattusnorvegicus many-to-many +insr_musmusculus maob_homosapiens many-to-many +insr_musmusculus maob_pantroglodytes many-to-many +insr_musmusculus maob_susscrofa many-to-many +insr_musmusculus maob_canisfamiliaris many-to-many +insr_musmusculus maoa_rattusnorvegicus many-to-many +insr_musmusculus maoa_homosapiens many-to-many +insr_musmusculus maoa_pantroglodytes many-to-many +insr_musmusculus maoa_susscrofa many-to-many +insr_musmusculus maoa_canisfamiliaris many-to-many +insr_musmusculus brat1_rattusnorvegicus many-to-many +insr_musmusculus brat1_homosapiens many-to-many +insr_musmusculus brat1_pantroglodytes many-to-many +insr_musmusculus brat1_susscrofa many-to-many +insr_musmusculus brat1_canisfamiliaris many-to-many +insr_homosapiens insr_pantroglodytes many-to-many +insr_homosapiens insr_susscrofa many-to-many +insr_homosapiens maob_rattusnorvegicus many-to-many +insr_homosapiens maob_musmusculus many-to-many +insr_homosapiens maob_pantroglodytes many-to-many +insr_homosapiens maob_susscrofa many-to-many +insr_homosapiens maob_canisfamiliaris many-to-many +insr_homosapiens maoa_rattusnorvegicus many-to-many +insr_homosapiens maoa_musmusculus many-to-many +insr_homosapiens maoa_pantroglodytes many-to-many +insr_homosapiens maoa_susscrofa many-to-many +insr_homosapiens maoa_canisfamiliaris many-to-many +insr_homosapiens brat1_rattusnorvegicus many-to-many +insr_homosapiens brat1_musmusculus many-to-many +insr_homosapiens brat1_pantroglodytes many-to-many +insr_homosapiens brat1_susscrofa many-to-many +insr_homosapiens brat1_canisfamiliaris many-to-many +insr_pantroglodytes insr_susscrofa many-to-many +insr_pantroglodytes maob_rattusnorvegicus many-to-many +insr_pantroglodytes maob_musmusculus many-to-many +insr_pantroglodytes maob_homosapiens many-to-many +insr_pantroglodytes maob_susscrofa many-to-many +insr_pantroglodytes maob_canisfamiliaris many-to-many +insr_pantroglodytes maoa_rattusnorvegicus many-to-many +insr_pantroglodytes maoa_musmusculus many-to-many +insr_pantroglodytes maoa_homosapiens many-to-many +insr_pantroglodytes maoa_susscrofa many-to-many +insr_pantroglodytes maoa_canisfamiliaris many-to-many +insr_pantroglodytes brat1_rattusnorvegicus many-to-many +insr_pantroglodytes brat1_musmusculus many-to-many +insr_pantroglodytes brat1_homosapiens many-to-many +insr_pantroglodytes brat1_susscrofa many-to-many +insr_pantroglodytes brat1_canisfamiliaris many-to-many +insr_susscrofa maob_rattusnorvegicus many-to-many +insr_susscrofa maob_musmusculus many-to-many +insr_susscrofa maob_homosapiens many-to-many +insr_susscrofa maob_pantroglodytes many-to-many +insr_susscrofa maob_canisfamiliaris many-to-many +insr_susscrofa maoa_rattusnorvegicus many-to-many +insr_susscrofa maoa_musmusculus many-to-many +insr_susscrofa maoa_homosapiens many-to-many +insr_susscrofa maoa_pantroglodytes many-to-many +insr_susscrofa maoa_canisfamiliaris many-to-many +insr_susscrofa brat1_rattusnorvegicus many-to-many +insr_susscrofa brat1_musmusculus many-to-many +insr_susscrofa brat1_homosapiens many-to-many +insr_susscrofa brat1_pantroglodytes many-to-many +insr_susscrofa brat1_canisfamiliaris many-to-many +maob_rattusnorvegicus maob_musmusculus many-to-many +maob_rattusnorvegicus maob_homosapiens many-to-many +maob_rattusnorvegicus maob_pantroglodytes many-to-many +maob_rattusnorvegicus maob_susscrofa many-to-many +maob_rattusnorvegicus maob_canisfamiliaris many-to-many +maob_rattusnorvegicus maoa_musmusculus many-to-many +maob_rattusnorvegicus maoa_homosapiens many-to-many +maob_rattusnorvegicus maoa_pantroglodytes many-to-many +maob_rattusnorvegicus maoa_susscrofa many-to-many +maob_rattusnorvegicus maoa_canisfamiliaris many-to-many +maob_rattusnorvegicus brat1_musmusculus many-to-many +maob_rattusnorvegicus brat1_homosapiens many-to-many +maob_rattusnorvegicus brat1_pantroglodytes many-to-many +maob_rattusnorvegicus brat1_susscrofa many-to-many +maob_rattusnorvegicus brat1_canisfamiliaris many-to-many +maob_musmusculus maob_homosapiens many-to-many +maob_musmusculus maob_pantroglodytes many-to-many +maob_musmusculus maob_susscrofa many-to-many +maob_musmusculus maob_canisfamiliaris many-to-many +maob_musmusculus maoa_rattusnorvegicus many-to-many +maob_musmusculus maoa_homosapiens many-to-many +maob_musmusculus maoa_pantroglodytes many-to-many +maob_musmusculus maoa_susscrofa many-to-many +maob_musmusculus maoa_canisfamiliaris many-to-many +maob_musmusculus brat1_rattusnorvegicus many-to-many +maob_musmusculus brat1_homosapiens many-to-many +maob_musmusculus brat1_pantroglodytes many-to-many +maob_musmusculus brat1_susscrofa many-to-many +maob_musmusculus brat1_canisfamiliaris many-to-many +maob_homosapiens maob_pantroglodytes many-to-many +maob_homosapiens maob_susscrofa many-to-many +maob_homosapiens maob_canisfamiliaris many-to-many +maob_homosapiens maoa_rattusnorvegicus many-to-many +maob_homosapiens maoa_musmusculus many-to-many +maob_homosapiens maoa_pantroglodytes many-to-many +maob_homosapiens maoa_susscrofa many-to-many +maob_homosapiens maoa_canisfamiliaris many-to-many +maob_homosapiens brat1_rattusnorvegicus many-to-many +maob_homosapiens brat1_musmusculus many-to-many +maob_homosapiens brat1_pantroglodytes many-to-many +maob_homosapiens brat1_susscrofa many-to-many +maob_homosapiens brat1_canisfamiliaris many-to-many +maob_pantroglodytes maob_susscrofa many-to-many +maob_pantroglodytes maob_canisfamiliaris many-to-many +maob_pantroglodytes maoa_rattusnorvegicus many-to-many +maob_pantroglodytes maoa_musmusculus many-to-many +maob_pantroglodytes maoa_homosapiens many-to-many +maob_pantroglodytes maoa_susscrofa many-to-many +maob_pantroglodytes maoa_canisfamiliaris many-to-many +maob_pantroglodytes brat1_rattusnorvegicus many-to-many +maob_pantroglodytes brat1_musmusculus many-to-many +maob_pantroglodytes brat1_homosapiens many-to-many +maob_pantroglodytes brat1_susscrofa many-to-many +maob_pantroglodytes brat1_canisfamiliaris many-to-many +maob_susscrofa maob_canisfamiliaris many-to-many +maob_susscrofa maoa_rattusnorvegicus many-to-many +maob_susscrofa maoa_musmusculus many-to-many +maob_susscrofa maoa_homosapiens many-to-many +maob_susscrofa maoa_pantroglodytes many-to-many +maob_susscrofa maoa_canisfamiliaris many-to-many +maob_susscrofa brat1_rattusnorvegicus many-to-many +maob_susscrofa brat1_musmusculus many-to-many +maob_susscrofa brat1_homosapiens many-to-many +maob_susscrofa brat1_pantroglodytes many-to-many +maob_susscrofa brat1_canisfamiliaris many-to-many +maob_canisfamiliaris maoa_rattusnorvegicus many-to-many +maob_canisfamiliaris maoa_musmusculus many-to-many +maob_canisfamiliaris maoa_homosapiens many-to-many +maob_canisfamiliaris maoa_pantroglodytes many-to-many +maob_canisfamiliaris maoa_susscrofa many-to-many +maob_canisfamiliaris brat1_rattusnorvegicus many-to-many +maob_canisfamiliaris brat1_musmusculus many-to-many +maob_canisfamiliaris brat1_homosapiens many-to-many +maob_canisfamiliaris brat1_pantroglodytes many-to-many +maob_canisfamiliaris brat1_susscrofa many-to-many +maoa_rattusnorvegicus maoa_musmusculus many-to-many +maoa_rattusnorvegicus maoa_homosapiens many-to-many +maoa_rattusnorvegicus maoa_pantroglodytes many-to-many +maoa_rattusnorvegicus maoa_susscrofa many-to-many +maoa_rattusnorvegicus maoa_canisfamiliaris many-to-many +maoa_rattusnorvegicus brat1_musmusculus many-to-many +maoa_rattusnorvegicus brat1_homosapiens many-to-many +maoa_rattusnorvegicus brat1_pantroglodytes many-to-many +maoa_rattusnorvegicus brat1_susscrofa many-to-many +maoa_rattusnorvegicus brat1_canisfamiliaris many-to-many +maoa_musmusculus maoa_homosapiens many-to-many +maoa_musmusculus maoa_pantroglodytes many-to-many +maoa_musmusculus maoa_susscrofa many-to-many +maoa_musmusculus maoa_canisfamiliaris many-to-many +maoa_musmusculus brat1_rattusnorvegicus many-to-many +maoa_musmusculus brat1_homosapiens many-to-many +maoa_musmusculus brat1_pantroglodytes many-to-many +maoa_musmusculus brat1_susscrofa many-to-many +maoa_musmusculus brat1_canisfamiliaris many-to-many +maoa_homosapiens maoa_pantroglodytes many-to-many +maoa_homosapiens maoa_susscrofa many-to-many +maoa_homosapiens maoa_canisfamiliaris many-to-many +maoa_homosapiens brat1_rattusnorvegicus many-to-many +maoa_homosapiens brat1_musmusculus many-to-many +maoa_homosapiens brat1_pantroglodytes many-to-many +maoa_homosapiens brat1_susscrofa many-to-many +maoa_homosapiens brat1_canisfamiliaris many-to-many +maoa_pantroglodytes maoa_susscrofa many-to-many +maoa_pantroglodytes maoa_canisfamiliaris many-to-many +maoa_pantroglodytes brat1_rattusnorvegicus many-to-many +maoa_pantroglodytes brat1_musmusculus many-to-many +maoa_pantroglodytes brat1_homosapiens many-to-many +maoa_pantroglodytes brat1_susscrofa many-to-many +maoa_pantroglodytes brat1_canisfamiliaris many-to-many +maoa_susscrofa maoa_canisfamiliaris many-to-many +maoa_susscrofa brat1_rattusnorvegicus many-to-many +maoa_susscrofa brat1_musmusculus many-to-many +maoa_susscrofa brat1_homosapiens many-to-many +maoa_susscrofa brat1_pantroglodytes many-to-many +maoa_susscrofa brat1_canisfamiliaris many-to-many +maoa_canisfamiliaris brat1_rattusnorvegicus many-to-many +maoa_canisfamiliaris brat1_musmusculus many-to-many +maoa_canisfamiliaris brat1_homosapiens many-to-many +maoa_canisfamiliaris brat1_pantroglodytes many-to-many +maoa_canisfamiliaris brat1_susscrofa many-to-many +brat1_rattusnorvegicus brat1_musmusculus many-to-many +brat1_rattusnorvegicus brat1_homosapiens many-to-many +brat1_rattusnorvegicus brat1_pantroglodytes many-to-many +brat1_rattusnorvegicus brat1_susscrofa many-to-many +brat1_rattusnorvegicus brat1_canisfamiliaris many-to-many +brat1_musmusculus brat1_homosapiens many-to-many +brat1_musmusculus brat1_pantroglodytes many-to-many +brat1_musmusculus brat1_susscrofa many-to-many +brat1_musmusculus brat1_canisfamiliaris many-to-many +brat1_homosapiens brat1_pantroglodytes many-to-many +brat1_homosapiens brat1_susscrofa many-to-many +brat1_homosapiens brat1_canisfamiliaris many-to-many +brat1_pantroglodytes brat1_susscrofa many-to-many +brat1_pantroglodytes brat1_canisfamiliaris many-to-many +brat1_susscrofa brat1_canisfamiliaris many-to-many +insr_rattusnorvegicus maob_rattusnorvegicus paralogs +insr_rattusnorvegicus maoa_rattusnorvegicus paralogs +insr_rattusnorvegicus brat1_rattusnorvegicus paralogs +insr_musmusculus maob_musmusculus paralogs +insr_musmusculus maoa_musmusculus paralogs +insr_musmusculus brat1_musmusculus paralogs +insr_homosapiens maob_homosapiens paralogs +insr_homosapiens maoa_homosapiens paralogs +insr_homosapiens brat1_homosapiens paralogs +insr_pantroglodytes maob_pantroglodytes paralogs +insr_pantroglodytes maoa_pantroglodytes paralogs +insr_pantroglodytes brat1_pantroglodytes paralogs +insr_susscrofa maob_susscrofa paralogs +insr_susscrofa maoa_susscrofa paralogs +insr_susscrofa brat1_susscrofa paralogs +maob_rattusnorvegicus maoa_rattusnorvegicus paralogs +maob_rattusnorvegicus brat1_rattusnorvegicus paralogs +maob_musmusculus maoa_musmusculus paralogs +maob_musmusculus brat1_musmusculus paralogs +maob_homosapiens maoa_homosapiens paralogs +maob_homosapiens brat1_homosapiens paralogs +maob_pantroglodytes maoa_pantroglodytes paralogs +maob_pantroglodytes brat1_pantroglodytes paralogs +maob_susscrofa maoa_susscrofa paralogs +maob_susscrofa brat1_susscrofa paralogs +maob_canisfamiliaris maoa_canisfamiliaris paralogs +maob_canisfamiliaris brat1_canisfamiliaris paralogs +maoa_rattusnorvegicus brat1_rattusnorvegicus paralogs +maoa_musmusculus brat1_musmusculus paralogs +maoa_homosapiens brat1_homosapiens paralogs +maoa_pantroglodytes brat1_pantroglodytes paralogs +maoa_susscrofa brat1_susscrofa paralogs +maoa_canisfamiliaris brat1_canisfamiliaris paralogs