Skip to content

Instantly share code, notes, and snippets.

@walterst
Created April 3, 2018 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save walterst/79f687dd31bd344062ca278244cc4902 to your computer and use it in GitHub Desktop.
Save walterst/79f687dd31bd344062ca278244cc4902 to your computer and use it in GitHub Desktop.
Use to count the number of singletons present in an QIIME OTU mapping file, write these sequence IDs to an output file.
#!/usr/bin/env python
"""Usage: python record_singletons.py X Y
where X is the input OTU mapping file and Y is the output singleton sequence ID file.
"""
from sys import argv
otu_mapping = open(argv[1], "U")
singletons_out = open(argv[2], "w")
count = 0
for line in otu_mapping:
if len(line.strip()) == 0:
continue
curr_line = line.strip().split("\t")
if len(curr_line) == 2:
singletons_out.write("%s\n" % curr_line[1])
count += 1
print("Total count of singletons: %d" % count)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment