comparison ete_lineage_generator.py @ 6:f1eca1158f21 draft

planemo upload for repository https://github.com/TGAC/earlham-galaxytools/tree/master/tools/ete commit 133bb57feca9672734d664e6b34e428488cf2e73
author earlhaminst
date Wed, 10 Oct 2018 05:24:04 -0400
parents 87b6de3ef63e
children b29ee6a16524
comparison
equal deleted inserted replaced
5:817031b8486d 6:f1eca1158f21
67 help='Fill unnamed ranks with super/sub ranks (see -l)') 67 help='Fill unnamed ranks with super/sub ranks (see -l)')
68 parser.add_option('-l', dest="lower", action="store_true", default=False, 68 parser.add_option('-l', dest="lower", action="store_true", default=False,
69 help='Prefer lower levels when compressed') 69 help='Prefer lower levels when compressed')
70 parser.add_option('-r', '--rank', dest='ranks', action="append", 70 parser.add_option('-r', '--rank', dest='ranks', action="append",
71 help='include rank - multiple ones can be specified') 71 help='include rank - multiple ones can be specified')
72 parser.add_option('-i', '--includeid', dest="addid", action="store_true", default=False,
73 help='add taxid column')
72 74
73 options, args = parser.parse_args() 75 options, args = parser.parse_args()
74 # check command line options 76 # check command line options
75 if options.input_species_filename is None: 77 if options.input_species_filename is None:
76 parser.error("-s option must be specified, Species list in text format one species in each line") 78 parser.error("-s option must be specified, Species list in text format one species in each line")
104 if options.compress: 106 if options.compress:
105 for ir in range(len(RANKS)): 107 for ir in range(len(RANKS)):
106 for ilr in range(len(LONG_RANKS)): 108 for ilr in range(len(LONG_RANKS)):
107 if RANKS[ir] in LONG_RANKS[ilr]: 109 if RANKS[ir] in LONG_RANKS[ilr]:
108 COMP_RANK_IDX[LONG_RANKS[ilr]] = ir 110 COMP_RANK_IDX[LONG_RANKS[ilr]] = ir
111
109 # write header 112 # write header
110 of.write("#species/taxid\t%s\n" % ("\t".join(RANKS))) 113 of.write("# query")
114 if options.addid:
115 of.write("\ttaxid")
116 of.write("\t%s\n" % ("\t".join(RANKS)))
117
111 # get and write data 118 # get and write data
112 with open(options.input_species_filename) as f: 119 with open(options.input_species_filename) as f:
113 for line in f.readlines(): 120 for line in f.readlines():
114 line = line.strip().replace('_', ' ') 121 line = line.strip().replace('_', ' ')
115 try: 122 try:
126 continue 133 continue
127 ranks = ["NA"] * len(RANKS) 134 ranks = ["NA"] * len(RANKS)
128 process_taxid(ncbi, taxid, ranks, RANK_IDX) 135 process_taxid(ncbi, taxid, ranks, RANK_IDX)
129 if options.compress: 136 if options.compress:
130 process_taxid(ncbi, taxid, ranks, COMP_RANK_IDX, options.lower) 137 process_taxid(ncbi, taxid, ranks, COMP_RANK_IDX, options.lower)
131 of.write("%s\t%s\n" % (line, "\t".join(ranks))) 138 of.write("%s" % line)
139 if options.addid:
140 of.write("\t%d" % taxid)
141 of.write("\t%s\n" % "\t".join(ranks))
132 of.close() 142 of.close()