Last active
December 10, 2015 02:18
-
-
Save meren/4366078 to your computer and use it in GitHub Desktop.
Convert oligotyping ready fasta files into QIIME ready ones.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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