Exemple #1
0
def test_barcode_matches_no_match():
    """
    Test :py:func:`riboviz.barcodes_umis.barcode_matches` with a
    non-matching record.
    """
    record = "@X1:Tag_AAA_ 1:N:0:XXXXXXXX"
    barcode = "AAC"
    assert not barcodes_umis.barcode_matches(record, barcode)
Exemple #2
0
def test_barcode_matches_two_mismatch():
    """
    Test :py:func:`riboviz.barcodes_umis.barcode_matches` with 2
    allowed mismatches and a non-matching record.
    """
    record = "@X1:Tag_ACC_ 1:N:0:XXXXXXXX"
    barcode = "AAA"
    assert barcodes_umis.barcode_matches(record, barcode, 2)
Exemple #3
0
def test_barcode_matches():
    """
    Test :py:func:`riboviz.barcodes_umis.barcode_matches` with default
    mismatches and delimiter.
    """
    record = "@X1:Tag_AAA_ 1:N:0:XXXXXXXX"
    barcode = "AAA"
    assert barcodes_umis.barcode_matches(record, barcode)
Exemple #4
0
def test_barcode_matches_one_mismatch_false():
    """
    Test :py:func:`riboviz.barcodes_umis.barcode_matches` with 1
    allowed mismatch and a non-matching record.
    """
    record = "@X1:Tag_ACC_ 1:N:0:XXXXXXXX"
    barcode = "AAA"
    assert not barcodes_umis.barcode_matches(record, barcode, 1)
Exemple #5
0
def test_barcode_matches_one_mismatch():
    """
    Test :py:func:`riboviz.barcodes_umis.barcode_matches` with 1
    allowed mismatch.
    """
    record = "@X1:Tag_AAC_ 1:N:0:XXXXXXXX"
    barcode = "AAA"
    assert barcodes_umis.barcode_matches(record, barcode, 1)
Exemple #6
0
def test_barcode_matches_no_barcode():
    """
    Test :py:func:`riboviz.barcodes_umis.barcode_matches` with a
    record with no barcode.
    """
    record = "@X1:Tag 1:N:0:XXXXXXXX"
    barcode = "AAA"
    assert not barcodes_umis.barcode_matches(record, barcode)
Exemple #7
0
def test_barcode_matches_delimiter():
    """
    Test :py:func:`riboviz.barcodes_umis.barcode_matches` with a
    non-default delimiter.
    """
    record = "@X1:Tag.AAA. 1:N:0:XXXXXXXX"
    barcode = "AAA"
    assert barcodes_umis.barcode_matches(record, barcode, delimiter=".")
Exemple #8
0
def test_barcode_matches_different_length_barcode():
    """
    Test :py:func:`riboviz.barcodes_umis.barcode_matches` with a
    record with that has a barcode a different length from that being
    matched.
    """
    record = "@X1:Tag_AAAA_ 1:N:0:XXXXXXXX"
    barcode = "AAA"
    assert not barcodes_umis.barcode_matches(record, barcode)
Exemple #9
0
def assign_sample(fastq_record1, fastq_record2, barcode, read1_split_fh,
                  read2_split_fh, is_paired_end, mismatches, delimiter):
    """
    Check if a FASTQ record matches a barcode for a sample and, if so,
    add the record to the FASTQ output file for that sample.

    :param fastq_record1: FASTQ record
    :type fastq_record1: list(str or unicode)
    :param fastq_record2: FASTQ record for paired read, or ``None``
    :type fastq_record2: list(str or unicode)
    :param barcode: Barcode
    :type barcode: str or unicode
    :param read1_split_fh: Read 1 output file handle
    :type read1_split_fh: io.IOBase
    :param read2_split_fh: Read 2 output file handle, or ``None``
    :type read2_split_fh: io.IOBase
    :param is_paired_end: Are paired reads being used? (if \
    ``True`` then ``fastq_record2`` is assumed to have a FASTQ \
    record and ``read2_split_fh`` is assumed to be an output \
    file handle, not ``None``)
    :type is_paired_end: bool
    :param mismatches: Mismatches allowed
    :type mismatches: int
    :param delimiter: Barcode delimiter
    :type delimiter: str or unicode
    :returns: `True` if FASTQ record matches barcode
    :rtype: bool
    """
    is_assigned = False
    if barcodes_umis.barcode_matches(fastq_record1[0], barcode, mismatches,
                                     delimiter):
        is_assigned = True
        read1_split_fh.writelines(fastq_record1)
        if is_paired_end:
            read2_split_fh.writelines(fastq_record2)
    return is_assigned