Skip to content

Instantly share code, notes, and snippets.

@meren
Last active December 10, 2015 02:18
Show Gist options
  • Save meren/4366078 to your computer and use it in GitHub Desktop.
Save meren/4366078 to your computer and use it in GitHub Desktop.
Convert oligotyping ready fasta files into QIIME ready ones.
import sys
import Oligotyping.lib.fastalib as u
fasta = u.SequenceSource(sys.argv[1])
output = u.FastaOutput(sys.argv[1] + '-QIIME-READY')
# H12DL4_12 B022DACXX4110133892403 orig_bc=GATCAG new_bc=GATCAG bc_diffs=0
sample_read_counter = {}
while fasta.next():
if len(fasta.id.split('_')) > 1:
sample = '_'.join(fasta.id.split('_')[:-1])
read_id = fasta.id.split('_')[-1].split('|')[0]
else:
sample = 'sample'
read_id = fasta.id
if not sample_read_counter.has_key(sample):
sample_read_counter[sample] = 0
else:
sample_read_counter[sample] += 1
current_sample = sample
output.write_id('%s_%d %s orig_bc=GATCAG new_bc=GATCAG bc_diffs=0' % (sample, sample_read_counter[sample], read_id))
output.write_seq(fasta.seq, split = False)
fasta.close()
output.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment