def scrobble_data_dir(dataDir, sampleMap, outF, qualF=None, idopt=None,<EOL>utf16=False):
seqcount = <NUM_LIT:0><EOL>outfiles = [osp.split(outF.name)[<NUM_LIT:1>]]<EOL>if qualF:<EOL><INDENT>outfiles.append(osp.split(qualF.name)[<NUM_LIT:1>])<EOL><DEDENT>for item in os.listdir(dataDir):<EOL><INDENT>if item in outfiles or not osp.isfile(os.path.join(dataDir, item)):<EOL><INDENT>continue<EOL><DEDENT>if osp.splitext(item)[<NUM_LIT:1>] in file_types['<STR_LIT>']:<EOL><INDENT>fh = open_enc(os.path.join(dataDir, item), utf16)<EOL>records = SeqIO.parse(fh, '<STR_LIT>')<EOL>for record in records:<EOL><INDENT>if isinstance(idopt, tuple):<EOL><INDENT>sep, field = idopt<EOL>sampleID = record.id.split(sep)[field - <NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>sampleID = osp.splitext(item)[<NUM_LIT:0>]<EOL><DEDENT>record.seq = (sampleMap[sampleID].barcode +<EOL>sampleMap[sampleID].primer +<EOL>record.seq)<EOL>SeqIO.write(record, outF, '<STR_LIT>')<EOL>seqcount += <NUM_LIT:1><EOL><DEDENT>fh.close()<EOL><DEDENT>elif qualF and osp.splitext(item)[<NUM_LIT:1>] in file_types['<STR_LIT>']:<EOL><INDENT>fh = open_enc(os.path.join(dataDir, item), utf16)<EOL>records = SeqIO.parse(fh, '<STR_LIT>')<EOL>for record in records:<EOL><INDENT>mi = sampleMap[list(sampleMap.keys())[<NUM_LIT:0>]]<EOL>quals = [<NUM_LIT> for _ in range(len(mi.barcode) + len(mi.primer))]<EOL>record.letter_annotations['<STR_LIT>'][<NUM_LIT:0>:<NUM_LIT:0>] = quals<EOL>SeqIO.write(record, qualF, '<STR_LIT>')<EOL><DEDENT>fh.close()<EOL><DEDENT><DEDENT>return seqcount<EOL>
Given a sample ID and a mapping, modify a Sanger FASTA file
to include the barcode and 'primer' in the sequence data
and change the description line as needed.