Example #1
0
def set_qc_fail(rec: pysam.AlignedSegment, tool: Callable[..., Any],
                reason: str) -> None:
    """Sets the QC fail flag, and adds tags containing the tool name and reason for failing.
    Args:
        rec: the record to fail
        tool: the tool (as a callable) that failed this record
        reason: the reason for failing
    """
    assert '\t' not in reason, f"Reason may not contain tabs: {reason}"
    rec.is_qcfail = True
    rec.set_tag(QcFailToolTag, tool.__name__)
    rec.set_tag(QcFailReasonTag, reason)
Example #2
0
    def _set_flags(self, rec: pysam.AlignedSegment, is_r1: bool,
                   strand: str) -> None:
        """Appropriately sets most flag fields on the given read.

        Args:
            rec: the read to set the flags on
            is_r1: True if the read is a R1, False if it is an R2
            strand: Either "+" or "-" to indicate strand of the read
        """
        rec.is_paired = True
        rec.is_read1 = is_r1
        rec.is_read2 = not is_r1
        rec.is_qcfail = False
        rec.is_duplicate = False
        rec.is_secondary = False
        rec.is_supplementary = False
        if not rec.is_unmapped:
            rec.is_reverse = strand != "+"