INNER CODE UNIT · Python
remove_taxa
hahnlab/CAFE5 · scripts/remove_taxa.py:7
def remove_taxa(input_file_path, output_file_path, taxa_to_remove):
taxa_list = taxa_to_remove.split(',')
header_order = dict() # node name:idx
node_name_idx = 0
with open(output_file_path, 'w') as output_file:
with open(input_file_path, 'r') as input_file:
for line in input_file:
line = line.rstrip()
if line.startswith('#'):
node_name = line.lstrip('#')
if not node_name in taxa_list:
output_file.write(line + '\n')
header_order[node_name] = node_name_idx
node_name_idx += 1