comparison ete_genetree_splitter.py @ 9:b29ee6a16524 draft

"planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/ete commit 17c65045b726d0695814bfe761e534f6521786f1"
author earlhaminst
date Tue, 20 Oct 2020 15:10:40 +0000
parents 6a5282f71f82
children dc32007a6b36
comparison
equal deleted inserted replaced
8:16e925bf567e 9:b29ee6a16524
11 parser.add_option('--genetree', help='GeneTree in nhx format') 11 parser.add_option('--genetree', help='GeneTree in nhx format')
12 parser.add_option('--speciestree', help='Species Tree in nhx format') 12 parser.add_option('--speciestree', help='Species Tree in nhx format')
13 parser.add_option('--species_format', type='int', default=8, help='Species Tree input format (0-9)') 13 parser.add_option('--species_format', type='int', default=8, help='Species Tree input format (0-9)')
14 parser.add_option('--gene_node', type='int', default=0, help='Gene node format 0=gene_species, 1=species_gene') 14 parser.add_option('--gene_node', type='int', default=0, help='Gene node format 0=gene_species, 1=species_gene')
15 parser.add_option('--gainlose', action='store_true', default=False, help='Find out gene gain/lose') 15 parser.add_option('--gainlose', action='store_true', default=False, help='Find out gene gain/lose')
16 parser.add_option('--split', type='choice', choices=['dups', 'treeko'], dest="split", default='dups', help='Choose GeneTree splitting algorithms')
16 parser.add_option('--output_format', type='int', default=9, help='GeneTree output format (0-9)') 17 parser.add_option('--output_format', type='int', default=9, help='GeneTree output format (0-9)')
17 options, args = parser.parse_args() 18 options, args = parser.parse_args()
18 19
19 if options.genetree is None: 20 if options.genetree is None:
20 parser.error("--genetree option must be specified, GeneTree in nhx format") 21 parser.error("--genetree option must be specified, GeneTree in nhx format")
45 for leaf in speciestree: 46 for leaf in speciestree:
46 leaf.name = leaf.name.strip('*') 47 leaf.name = leaf.name.strip('*')
47 48
48 genetree, events = genetree.reconcile(speciestree) 49 genetree, events = genetree.reconcile(speciestree)
49 50
50 # splits tree by duplication events which returns the list of all subtrees resulting from splitting current tree by its duplication nodes. 51 if options.split == "dups":
51 for cluster_id, node in enumerate(genetree.split_by_dups(), 1): 52 # splits tree by duplication events which returns the list of all subtrees resulting from splitting current tree by its duplication nodes.
52 outfile = str(cluster_id) + '_genetree.nhx' 53 for cluster_id, node in enumerate(genetree.split_by_dups(), 1):
53 with open(outfile, 'w') as f: 54 outfile = str(cluster_id) + '_genetree.nhx'
54 f.write(node.write(format=options.output_format)) 55 with open(outfile, 'w') as f:
56 f.write(node.write(format=options.output_format))
57 elif options.split == "treeko":
58 # splits tree using the TreeKO algorithm.
59 ntrees, ndups, sptrees = genetree.get_speciation_trees()
60
61 cluster_id = 0
62 for spt in sptrees:
63 cluster_id = cluster_id + 1
64 outfile = str(cluster_id) + '_genetree.nhx'
65 with open(outfile, 'w') as f:
66 f.write(spt.write(format=options.output_format))
55 67
56 68
57 def parse_sp_name(node_name): 69 def parse_sp_name(node_name):
58 return node_name.split("_")[1] 70 return node_name.split("_")[1]
59 71