ipyrad/assemble/consens_se.py
def removerepeats(consens, arrayed):
    """
    Checks for interior Ns in consensus seqs and removes those that are at
    low depth, here defined as less than 1/3 of the average depth. The prop 1/3
    is chosen so that mindepth=6 requires 2 base calls that are not in [N,-].
    """

    ## default trim no edges
    consens = "".join(consens).replace("-", "N")

    ## split for pairs
    try:
        cons1, cons2 = consens.split("nnnn")
        split = consens.index("nnnn")
        arr1 = arrayed[:, :split]
        arr2 = arrayed[:, split+4:]
    except ValueError:
        cons1 = consens
        cons2 = ""
        arr1 = arrayed

    ## trim from left and right of cons1
    edges = [None, None]
    lcons = len(cons1)
    cons1 = cons1.lstrip("N")
    edges[0] = lcons - len(cons1)

    ## trim from right if nonzero
    lcons = len(cons1)
    cons1 = cons1.rstrip("N")
    if lcons - len(cons1):
        edges[1] = -1*(lcons - len(cons1))

    ## trim same from arrayed
    arr1 = arr1[:, edges[0]:edges[1]]

    ## trim from left and right of cons2 if present
    if cons2:
        ## trim from left and right of cons1
        edges = [None, None]
        lcons = len(cons2)
        cons2 = cons2.lstrip("N")
        edges[0] = lcons - len(cons2)

        ## trim from right if nonzero
        lcons = len(cons2)
        cons2 = cons2.rstrip("N")
        if lcons - len(cons2):
            edges[1] = -1*(lcons - len(cons2))

        ## trim same from arrayed
        arr2 = arr2[:, edges[0]:edges[1]]

        ## reconstitute pairs
        consens = cons1 + "nnnn" + cons2
        consens = np.array(list(consens))
        sep = np.array(arr1.shape[0]*[list("nnnn")])
        arrayed = np.hstack([arr1, sep, arr2])

    ## if single-end...
    else:
        consens = np.array(list(cons1))
        arrayed = arr1

    ## get column counts of Ns and -s
    ndepths = np.sum(arrayed == 'N', axis=0)
    idepths = np.sum(arrayed == '-', axis=0)

    ## get proportion of bases that are N- at each site
    nons = ((ndepths + idepths) / float(arrayed.shape[0])) >= 0.75
    ## boolean of whether base was called N
    isn = consens == "N"
    ## make ridx
    ridx = nons * isn

    ## apply filter
    consens = consens[~ridx]
    arrayed = arrayed[:, ~ridx]

    return consens, arrayed
def removerepeats(consens, arrayed):
    """
    Checks for interior Ns in consensus seqs and removes those that are at
    low depth, here defined as less than 1/3 of the average depth. The prop 1/3
    is chosen so that mindepth=6 requires 2 base calls that are not in [N,-].
    """

    ## default trim no edges
    consens = "".join(consens).replace("-", "N")

    ## split for pairs
    try:
        cons1, cons2 = consens.split("nnnn")
        split = consens.index("nnnn")
        arr1 = arrayed[:, :split]
        arr2 = arrayed[:, split+4:]
    except ValueError:
        cons1 = consens
        cons2 = ""
        arr1 = arrayed

    ## trim from left and right of cons1
    edges = [None, None]
    lcons = len(cons1)
    cons1 = cons1.lstrip("N")
    edges[0] = lcons - len(cons1)

    ## trim from right if nonzero
    lcons = len(cons1)
    cons1 = cons1.rstrip("N")
    if lcons - len(cons1):
        edges[1] = -1*(lcons - len(cons1))

    ## trim same from arrayed
    arr1 = arr1[:, edges[0]:edges[1]]

    ## trim from left and right of cons2 if present
    if cons2:
        ## trim from left and right of cons1
        edges = [None, None]
        lcons = len(cons2)
        cons2 = cons2.lstrip("N")
        edges[0] = lcons - len(cons2)

        ## trim from right if nonzero
        lcons = len(cons2)
        cons2 = cons2.rstrip("N")
        if lcons - len(cons2):
            edges[1] = -1*(lcons - len(cons2))

        ## trim same from arrayed
        arr2 = arr2[:, edges[0]:edges[1]]

        ## reconstitute pairs
        consens = cons1 + "nnnn" + cons2
        consens = np.array(list(consens))
        sep = np.array(arr1.shape[0]*[list("nnnn")])
        arrayed = np.hstack([arr1, sep, arr2])

    ## if single-end...
    else:
        consens = np.array(list(cons1))
        arrayed = arr1

    ## get column counts of Ns and -s
    ndepths = np.sum(arrayed == 'N', axis=0)
    idepths = np.sum(arrayed == '-', axis=0)

    ## get proportion of bases that are N- at each site
    nons = ((ndepths + idepths) / float(arrayed.shape[0])) >= 0.75
    ## boolean of whether base was called N
    isn = consens == "N"
    ## make ridx
    ridx = nons * isn

    ## apply filter
    consens = consens[~ridx]
    arrayed = arrayed[:, ~ridx]

    return consens, arrayed
def removerepeats ( consens , arrayed ) : ## default trim no edges consens = "" . join ( consens ) . replace ( "-" , "N" ) ## split for pairs try : cons1 , cons2 = consens . split ( "nnnn" ) split = consens . index ( "nnnn" ) arr1 = arrayed [ : , : split ] arr2 = arrayed [ : , split + 4 : ] except ValueError : cons1 = consens cons2 = "" arr1 = arrayed ## trim from left and right of cons1 edges = [ None , None ] lcons = len ( cons1 ) cons1 = cons1 . lstrip ( "N" ) edges [ 0 ] = lcons - len ( cons1 ) ## trim from right if nonzero lcons = len ( cons1 ) cons1 = cons1 . rstrip ( "N" ) if lcons - len ( cons1 ) : edges [ 1 ] = - 1 * ( lcons - len ( cons1 ) ) ## trim same from arrayed arr1 = arr1 [ : , edges [ 0 ] : edges [ 1 ] ] ## trim from left and right of cons2 if present if cons2 : ## trim from left and right of cons1 edges = [ None , None ] lcons = len ( cons2 ) cons2 = cons2 . lstrip ( "N" ) edges [ 0 ] = lcons - len ( cons2 ) ## trim from right if nonzero lcons = len ( cons2 ) cons2 = cons2 . rstrip ( "N" ) if lcons - len ( cons2 ) : edges [ 1 ] = - 1 * ( lcons - len ( cons2 ) ) ## trim same from arrayed arr2 = arr2 [ : , edges [ 0 ] : edges [ 1 ] ] ## reconstitute pairs consens = cons1 + "nnnn" + cons2 consens = np . array ( list ( consens ) ) sep = np . array ( arr1 . shape [ 0 ] * [ list ( "nnnn" ) ] ) arrayed = np . hstack ( [ arr1 , sep , arr2 ] ) ## if single-end... else : consens = np . array ( list ( cons1 ) ) arrayed = arr1 ## get column counts of Ns and -s ndepths = np . sum ( arrayed == 'N' , axis = 0 ) idepths = np . sum ( arrayed == '-' , axis = 0 ) ## get proportion of bases that are N- at each site nons = ( ( ndepths + idepths ) / float ( arrayed . shape [ 0 ] ) ) >= 0.75 ## boolean of whether base was called N isn = consens == "N" ## make ridx ridx = nons * isn ## apply filter consens = consens [ ~ ridx ] arrayed = arrayed [ : , ~ ridx ] return consens , arrayed
Checks for interior Ns in consensus seqs and removes those that are at
    low depth, here defined as less than 1/3 of the average depth. The prop 1/3
    is chosen so that mindepth=6 requires 2 base calls that are not in [N,-].
Checks for interior Ns in consensus seqs and removes those that are at low depth here defined as less than 1 / 3 of the average depth . The prop 1 / 3 is chosen so that mindepth = 6 requires 2 base calls that are not in [ N - ] .