def write_mapping_file(mapF, sampleIDs, barcodes, treatment=None):
    """
    Given a mapping from sample IDs to barcodes/primers/other info,
    write out a QIIME-compatible mapping file.

    File format described at: http://qiime.org/documentation/file_formats.html
    Note that primer column can be left blank.
    """
    header = ['#SampleID', 'BarcodeSequence', 'LinkerPrimerSequence',
              'Description', '\n']
    if treatment is not None:
        header.insert(-2, treatment.name)
    primer = 'AAACCCGGGTTTAAACTGAC'
    sampleMap = {}

    with mapF:
        mapF.write('\t'.join(header))
        for sid, bc in zip(sampleIDs, barcodes):
            sampleMap[sid] = MapRecord(bc, primer, treatment.value, sid)
            line = [sid, bc, primer, sid]
            if treatment is not None:
                line.insert(-1, treatment.value)
            mapF.write('\t'.join(line) + '\n')

    return sampleMap
Given a mapping from sample IDs to barcodes/primers/other info,
    write out a QIIME-compatible mapping file.

    File format described at: http://qiime.org/documentation/file_formats.html
    Note that primer column can be left blank.