comparison ete_lineage_generator.py @ 11:2db72467da51 draft

"planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/ete commit 67e136d433c0d925db362342919305b46fdffecd"
author earlhaminst
date Thu, 10 Mar 2022 14:01:44 +0000
parents b29ee6a16524
children
comparison
equal deleted inserted replaced
10:541a2ffc01ff 11:2db72467da51
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_taxids = ncbi.get_lineage(taxid) 44 try:
45 lineage_taxids = ncbi.get_lineage(taxid)
46 except ValueError:
47 sys.stderr.write("[%s] could not determine lineage!\n" % taxid)
48 return
49 if lineage_taxids is None:
50 sys.stderr.write("[%s] could not determine lineage!\n" % taxid)
51 return
45 lineage_ranks = ncbi.get_rank(lineage_taxids) 52 lineage_ranks = ncbi.get_rank(lineage_taxids)
46 lineage_names = ncbi.get_taxid_translator(lineage_taxids, try_synonyms=True) 53 lineage_names = ncbi.get_taxid_translator(lineage_taxids, try_synonyms=True)
47 if lower: 54 if lower:
48 lineage_taxids.reverse() 55 lineage_taxids.reverse()
49 for parent_taxid in lineage_taxids: 56 for parent_taxid in lineage_taxids:
119 126
120 # get and write data 127 # get and write data
121 with open(options.input_species_filename) as f: 128 with open(options.input_species_filename) as f:
122 for line in f.readlines(): 129 for line in f.readlines():
123 line = line.strip().replace('_', ' ') 130 line = line.strip().replace('_', ' ')
131 if line == "":
132 continue
124 try: 133 try:
125 taxid = int(line) 134 taxid = int(line)
126 except ValueError: 135 except ValueError:
127 # TODO: one could use fuzzy name lookup (i.e. accept typos in the species names), 136 # TODO: one could use fuzzy name lookup (i.e. accept typos in the species names),
128 # but then a pysqlite version that supports this is needed (needs to be enabled 137 # but then a pysqlite version that supports this is needed (needs to be enabled