pyseer/enet.py
def load_all_vars(var_type, p, burden, burden_regions, infile,
                   all_strains, sample_order, min_af, max_af,
                   max_missing, uncompressed):
    """Load all variants in the input file into a sparse
    matrix representation

    Args:
        var_type (str)
            Variants type (one of: kmers, vcf or Rtab)
        p (pandas.DataFrame)
            Phenotype vector (n, 1)
        burden (bool)
            Whether to slice a vcf file by burden regions
        burden_regions (collections.deque)
            Burden regions to slice the vcf with
        infile (opened file)
            Handle to opened variant file
        all_strains (set-like)
            All sample labels that should be present
        sample_order
            Sampes order to interpret each Rtab line
        min_af (float)
            Minimum allele frequency (inclusive)
        max_af (float)
            maximum allele frequency (inclusive)
        max_missing (float)
            maximum missing frequency
        uncompressed (bool)
            Whether the kmers file is uncompressed

    Returns:
        variants (scipy.sparse.csr_matrix)
            A sparse matrix representation of all variants in
            the input
        selected_vars (list)
            0-Indices of variants in the input file in variants
            (which passed AF filtering)
        var_idx (int)
            The number of read variants (number of rows of variants)
    """
    # For building sparse matrix
    data = []
    indices = []
    indptr = [0]
    selected_vars = []
    var_idx = 0

    pbar = tqdm(unit="variants")
    while True:
        eof, k, var_name, kstrains, nkstrains, af, missing = read_variant(
                                        infile, p, var_type,
                                        burden, burden_regions,
                                        uncompressed, all_strains,
                                        sample_order)

        # check for EOF
        if eof:
            pbar.close()
            break
        else:
            pbar.update(1)

        if k is not None and af > min_af and af < max_af and missing < max_missing:
            # Minor allele encoding - most efficient use of sparse structure
            if af > 0.5:
                pres = 0
            else:
                pres = 1

            for idx, obs in enumerate(k):
                if obs == pres:
                    indices.append(idx)
                    data.append(1)
            indptr.append(len(indices))

            selected_vars.append(var_idx)

        var_idx += 1

    # construct sparse matrix
    variants = csr_matrix((data, indices, indptr), dtype=float)

    return(variants, selected_vars, var_idx)
Load all variants in the input file into a sparse
    matrix representation

    Args:
        var_type (str)
            Variants type (one of: kmers, vcf or Rtab)
        p (pandas.DataFrame)
            Phenotype vector (n, 1)
        burden (bool)
            Whether to slice a vcf file by burden regions
        burden_regions (collections.deque)
            Burden regions to slice the vcf with
        infile (opened file)
            Handle to opened variant file
        all_strains (set-like)
            All sample labels that should be present
        sample_order
            Sampes order to interpret each Rtab line
        min_af (float)
            Minimum allele frequency (inclusive)
        max_af (float)
            maximum allele frequency (inclusive)
        max_missing (float)
            maximum missing frequency
        uncompressed (bool)
            Whether the kmers file is uncompressed

    Returns:
        variants (scipy.sparse.csr_matrix)
            A sparse matrix representation of all variants in
            the input
        selected_vars (list)
            0-Indices of variants in the input file in variants
            (which passed AF filtering)
        var_idx (int)
            The number of read variants (number of rows of variants)
    
Load all variants in the input file into a sparse
matrix representation



variants (scipy.sparse.csr_matrix)
A sparse matrix representation of all variants in
the input
selected_vars (list)
0-Indices of variants in the input file in variants
(which passed AF filtering)
var_idx (int)
The number of read variants (number of rows of variants)
Load all variants in the input file into a sparse matrix representation variants ( scipy . sparse . csr_matrix ) A sparse matrix representation of all variants in the input selected_vars ( list ) 0 - Indices of variants in the input file in variants ( which passed AF filtering ) var_idx ( int ) The number of read variants ( number of rows of variants )
def load_all_vars(var_type, p, burden, burden_regions, infile,
                   all_strains, sample_order, min_af, max_af,
                   max_missing, uncompressed):
    data = []
    indices = []
    indptr = [0]
    selected_vars = []
    var_idx = 0
    pbar = tqdm(unit="variants")
    while True:
        eof, k, var_name, kstrains, nkstrains, af, missing = read_variant(
                                        infile, p, var_type,
                                        burden, burden_regions,
                                        uncompressed, all_strains,
                                        sample_order)
        if eof:
            pbar.close()
            break
        else:
            pbar.update(1)
        if k is not None and af > min_af and af < max_af and missing < max_missing:
            if af > 0.5:
                pres = 0
            else:
                pres = 1
            for idx, obs in enumerate(k):
                if obs == pres:
                    indices.append(idx)
                    data.append(1)
            indptr.append(len(indices))
            selected_vars.append(var_idx)
        var_idx += 1
    variants = csr_matrix((data, indices, indptr), dtype=float)
    return(variants, selected_vars, var_idx)
def load_all_vars ( var_type , p , burden , burden_regions , infile , all_strains , sample_order , min_af , max_af , max_missing , uncompressed ) : data = [ ] indices = [ ] indptr = [ 0 ] selected_vars = [ ] var_idx = 0 pbar = tqdm ( unit = "variants" ) while True : eof , k , var_name , kstrains , nkstrains , af , missing = read_variant ( infile , p , var_type , burden , burden_regions , uncompressed , all_strains , sample_order ) if eof : pbar . close ( ) break else : pbar . update ( 1 ) if k is not None and af > min_af and af < max_af and missing < max_missing : if af > 0.5 : pres = 0 else : pres = 1 for idx , obs in enumerate ( k ) : if obs == pres : indices . append ( idx ) data . append ( 1 ) indptr . append ( len ( indices ) ) selected_vars . append ( var_idx ) var_idx += 1 variants = csr_matrix ( ( data , indices , indptr ) , dtype = float ) return ( variants , selected_vars , var_idx )
Load all variants in the input file into a sparse
matrix representation
Load all variants in the input file into a sparse matrix representation
"""Load all variants in the input file into a sparse
    matrix representation

    Args:
        var_type (str)
            Variants type (one of: kmers, vcf or Rtab)
        p (pandas.DataFrame)
            Phenotype vector (n, 1)
        burden (bool)
            Whether to slice a vcf file by burden regions
        burden_regions (collections.deque)
            Burden regions to slice the vcf with
        infile (opened file)
            Handle to opened variant file
        all_strains (set-like)
            All sample labels that should be present
        sample_order
            Sampes order to interpret each Rtab line
        min_af (float)
            Minimum allele frequency (inclusive)
        max_af (float)
            maximum allele frequency (inclusive)
        max_missing (float)
            maximum missing frequency
        uncompressed (bool)
            Whether the kmers file is uncompressed

    Returns:
        variants (scipy.sparse.csr_matrix)
            A sparse matrix representation of all variants in
            the input
        selected_vars (list)
            0-Indices of variants in the input file in variants
            (which passed AF filtering)
        var_idx (int)
            The number of read variants (number of rows of variants)
    """ # For building sparse matrix # check for EOF # Minor allele encoding - most efficient use of sparse structure # construct sparse matrix
var_type
p
burden
burden_regions
infile
all_strains
sample_order
min_af
max_af
max_missing
uncompressed