# AUTOGENERATED FILE! PLEASE DON'T EDIT HERE. EDIT THE SOURCE NOTEBOOKS INSTEAD
"""
This is for functions that are .sam or .bam related
"""
from k1lib import cli; import k1lib
__all__ = ["cat", "header", "flag"]
settings = k1lib.Settings()
k1lib.settings.cli.add("sam", settings, "from k1lib.cli.sam module");
catF = lambda header: cli.applyS(lambda bamFile: None | cli.cmd(f"samtools view {'-h' if header else ''} {bamFile}") | cli.table("\t"))
[docs]def cat(bamFile:str=None, header:bool=True):                                     # cat
    """Get sam file outputs from bam file.
Example::
    sam.cat("file.bam") | display()
    "file.bam" | sam.cat(header=False) | display()
:param header: whether to include headers or not"""                              # cat
    return catF(header)(bamFile) if bamFile is not None else catF(header)        # cat 
settings.add("header", k1lib.Settings()                                          # cat
             .add("short", ["qname", "flag", "rname", "pos", "mapq", "cigar", "rnext", "pnext", "tlen", "seq", "qual"]) # cat
             .add("long", ["Query template name", "Flags", "Reference sequence name", "Position", "Mapping quality", "CIGAR string", "Rname of next read", "Position of next read", "Template length", "Sequence", "Quality"]), "sam headers") # cat
settings.add("flags", ['PAIRED', 'PROPER_PAIR', 'UNMAP', 'MUNMAP', 'REVERSE', 'MREVERSE', 'READ1', 'READ2', 'SECONDARY', 'QCFAIL', 'DUP', 'SUPPLEMENTARY'], "list of flags") # header
[docs]class flag(cli.bindec):                                                          # flag
[docs]    def __init__(self, f=None):                                                  # flag
        """Decodes flags attribute.
Example::
    # returns ['PAIRED', 'UNMAP']
    5 | flag()
    # returns 'PAIRED, UNMAP'
    5 | flag(cli.join(", "))
You'll mostly use this in this format::
    sam.cat("file.bam", False) | apply(sam.flag(), 1) | display()
You can change the flag labels like this::
    settings.cli.sam.flags = ["paired", ...]
:param f: transform function fed into :class:`~k1lib.cli.utils.bindec`, defaulted
    to `join(", ")`"""                                                           # flag
        super().__init__(k1lib.settings.cli.sam.flags, f or cli.join(", "))      # flag