comparison ete_lineage_generator.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 f1eca1158f21
children 2db72467da51
comparison
equal deleted inserted replaced
8:16e925bf567e 9:b29ee6a16524
39 taxid: a taxid (int) 39 taxid: a taxid (int)
40 ranks: list of ranks (should be initialized with "NA" x number of levels of interest) 40 ranks: list of ranks (should be initialized with "NA" x number of levels of interest)
41 RANK_IDX: mapping from rank names to indices (distance to root/leaf?) 41 RANK_IDX: mapping from rank names to indices (distance to root/leaf?)
42 lower: use lower taxa for filling "NA"s 42 lower: use lower taxa for filling "NA"s
43 """ 43 """
44 lineage = ncbi.get_lineage(taxid) 44 lineage_taxids = ncbi.get_lineage(taxid)
45 lineage_ranks = ncbi.get_rank(lineage) 45 lineage_ranks = ncbi.get_rank(lineage_taxids)
46 lineage_names = ncbi.get_taxid_translator(lineage, try_synonyms=True) 46 lineage_names = ncbi.get_taxid_translator(lineage_taxids, try_synonyms=True)
47 if lower: 47 if lower:
48 lineage.reverse() 48 lineage_taxids.reverse()
49 for l in lineage: 49 for parent_taxid in lineage_taxids:
50 if not lineage_ranks[l] in RANK_IDX: 50 parent_rank = lineage_ranks[parent_taxid]
51 if parent_rank not in RANK_IDX:
51 continue 52 continue
52 if ranks[RANK_IDX[lineage_ranks[l]]] != "NA": 53 parent_rank_index = RANK_IDX[parent_rank]
54 if ranks[parent_rank_index] != "NA":
53 continue 55 continue
54 ranks[RANK_IDX[lineage_ranks[l]]] = lineage_names[l] 56 ranks[parent_rank_index] = lineage_names[parent_taxid]
55 57
56 58
57 # get command line options 59 # get command line options
58 parser = optparse.OptionParser() 60 parser = optparse.OptionParser()
59 parser.add_option('-s', '--species', dest="input_species_filename", 61 parser.add_option('-s', '--species', dest="input_species_filename",