comparison ete_gene_cnv.py @ 13:ed74587a13c8 draft

planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/ete commit 23b3c7c09a7d391b576e3b19f8b34dd63d636bdc
author earlhaminst
date Thu, 01 Sep 2022 16:11:32 +0000
parents 16e925bf567e
children
comparison
equal deleted inserted replaced
12:dc32007a6b36 13:ed74587a13c8
43 genetree = PhyloTree(line) 43 genetree = PhyloTree(line)
44 leaves = genetree.get_leaf_names() 44 leaves = genetree.get_leaf_names()
45 45
46 leaves_parts = [_.split("_") for _ in leaves] 46 leaves_parts = [_.split("_") for _ in leaves]
47 for i, leaf_parts in enumerate(leaves_parts): 47 for i, leaf_parts in enumerate(leaves_parts):
48 if len(leaf_parts) != 2: 48 if len(leaf_parts) < 2:
49 raise Exception("Leaf node '%s' is not in gene_species format" % leaves[i]) 49 raise Exception("Leaf node '%s' is not in gene_species format" % leaves[i])
50 50
51 leaves_species = [_[1] for _ in leaves_parts] 51 leaves_species = [_[-1] for _ in leaves_parts]
52 species_counter = collections.Counter(leaves_species) 52 species_counter = collections.Counter(leaves_species)
53 53
54 # Assign to ref_species the first element of species_list which 54 # Assign to ref_species the first element of species_list which
55 # appears in a leaf node 55 # appears in a leaf node
56 for ref_species in species_list: 56 for ref_species in species_list:
59 else: 59 else:
60 raise Exception("None of the specified species was found in the GeneTree '%s'" % line) 60 raise Exception("None of the specified species was found in the GeneTree '%s'" % line)
61 61
62 # Find the gene of the (first) leaf node for the ref_species 62 # Find the gene of the (first) leaf node for the ref_species
63 for leaf_parts in leaves_parts: 63 for leaf_parts in leaves_parts:
64 if leaf_parts[1] == ref_species: 64 if leaf_parts[-1] == ref_species:
65 species_counter['gene'] = leaf_parts[0] 65 species_counter['gene'] = "_".join(leaf_parts[:-1])
66 break 66 break
67 67
68 table.append(species_counter) 68 table.append(species_counter)
69 69
70 colList = ["gene"] + species_list 70 colList = ["gene"] + species_list