Skip to content

Instantly share code, notes, and snippets.

@walterst
Created September 9, 2014 21:02
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/f5c619799e6dc1f575a0 to your computer and use it in GitHub Desktop.
Save walterst/f5c619799e6dc1f575a0 to your computer and use it in GitHub Desktop.
Usage python fix_fasta_labels.py X Y where X is the input fasta file, Y is the output fasta file The second string following a split on white space will be written as the label in the output fasta, this is intended to make a label in a fasta file generated from QIIME's pick_rep_set.py match the original sequence ID rather than the OTU ID.
#!/usr/bin/env python
"""Usage
python fix_fasta_labels.py X Y
where X is the input fasta file, Y is the output fasta file
The second string following a split on white space will be written
as the label in the output fasta, this is intended to make a label in a
fasta file generated from QIIME's pick_rep_set.py match the original
sequence ID rather than the OTU ID."""
from sys import argv
from cogent.parse.fasta import MinimalFastaParser
input_fasta = open(argv[1], "U")
output_fasta = open(argv[2], "w")
for label,seq in MinimalFastaParser(input_fasta):
curr_label = " ".join(label.split(" ")[1:])
output_fasta.write(">%s\n%s\n" % (curr_label, seq))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment