def write_reads(demultiplex_dict, samplesDict, settings):
    """Write the fastq data to the correct (demultiplexed) file."""
    barcode_dict = {'other': '_other'}
    for sample in samplesDict:
        barcode_dict[samplesDict[sample]['barcode']] = sample
    for barcode in demultiplex_dict:
        if demultiplex_dict[barcode]:
            with open('{path}raw_data/{sample}.fastq'.format(path=settings.
                path, sample=barcode_dict[barcode]), 'a') as fo:
                for read in demultiplex_dict[barcode]:
                    fo.write('@{n}\n{s}\n+\n{q}\n'.format(n=read.name, s=
                        read.sequence, q=read.quality))
