예제 #1
0
def main(args):

    import argparse
    import gc
    import pathlib
    from sklearn.externals import joblib
    import numpy as np
    from peakachu import scoreUtils, utils

    np.seterr(divide='ignore', invalid='ignore')

    pathlib.Path(args.output).mkdir(parents=True, exist_ok=True)

    model = joblib.load(args.model)

    # more robust to check if a file is .hic
    hic_info = utils.read_hic_header(args.path)
    if hic_info is None:
        hic = False
        import cooler
        Lib = cooler.Cooler(args.path)
        chromosomes = Lib.chromnames[:]
        #nam = args.path.split('.cool')[0]
    else:
        hic = True
        chromosomes = utils.get_hic_chromosomes(args.path, args.resolution)
        #nam = args.path.split('.hic')[0]
    #nam = nam.split('/')[-1]

    for key in chromosomes:
        if key.startswith('chr'):
            cname = key
        else:
            cname = 'chr'+key
        if not hic:
            X = scoreUtils.Chromosome(Lib.matrix(balance=args.balance, sparse=True).fetch(key).tocsr(),
                                      model=model,
                                      cname=cname, lower=args.lower,
                                      upper=args.upper, res=args.resolution,
                                      width=args.width)
        else:
            if args.balance:
                X = scoreUtils.Chromosome(utils.csr_contact_matrix('KR', args.path, key, key, 'BP', args.resolution),
                                          model=model,
                                          cname=cname, lower=args.lower,
                                          upper=args.upper, res=args.resolution,
                                          width=args.width)
            else:
                X = scoreUtils.Chromosome(utils.csr_contact_matrix('NONE', args.path, key, key, 'BP', args.resolution),
                                          model=model,
                                          cname=cname, lower=args.lower,
                                          upper=args.upper, res=args.resolution,
                                          width=args.width)

        result, R = X.score()
        X.writeBed(args.output, result, R)
예제 #2
0
def main(args):
    import numpy as np
    np.seterr(divide='ignore', invalid='ignore')
    from peakachu import scoreUtils
    pathlib.Path(args.output).mkdir(parents=True, exist_ok=True)

    import cooler
    Lib = cooler.Cooler(args.path)
    nam = args.path.split('.cool')[0]
    nam = nam.split('/')[-1]
    #resolution = Lib.binsize
    resolution = args.resolution
    chroms = []

    model = joblib.load(args.model)
    for key in Lib.chromnames:
        if key.startswith('c'):
            cname = key
        else:
            cname = 'chr' + key
        X = scoreUtils.Chromosome(Lib.matrix(balance=args.balance,
                                             sparse=True).fetch(key).tocsr(),
                                  model=model,
                                  cname=cname,
                                  lower=args.lower,
                                  upper=args.upper,
                                  res=resolution,
                                  width=args.width)
        result, R = X.score()
        X.writeBed(args.output, result, R)
예제 #3
0
def main(args):
    import numpy as np
    np.seterr(divide='ignore', invalid='ignore')
    from peakachu import scoreUtils
    pathlib.Path(args.output).mkdir(parents=True, exist_ok=True)
    cikada = args.model
    cikada = cikada.split('.pk')[0]
    cikada = 'ch' + cikada.split('ch')[-1]

    model = joblib.load(args.model)

    import cooler
    Lib = cooler.Cooler(args.path)
    if cikada in Lib.chromnames:
        ccname = cikada
    else:
        ccname = cikada.split('hr')[1]
    #resolution = Lib.binsize
    resolution = args.resolution

    X = scoreUtils.Chromosome(Lib.matrix(balance=args.balance,
                                         sparse=True).fetch(ccname).tocsr(),
                              model=model,
                              cname=cikada,
                              lower=args.lower,
                              upper=args.upper,
                              res=resolution,
                              width=args.width)
    result, R = X.score()
    X.writeBed(args.output, result, R)
예제 #4
0
def main(args):

    import argparse, gc, pathlib, os
    import numpy as np
    from sklearn.externals import joblib
    from peakachu import scoreUtils, utils

    np.seterr(divide='ignore', invalid='ignore')

    pathlib.Path(args.output).mkdir(parents=True, exist_ok=True)

    model = joblib.load(args.model)

    hic_info = utils.read_hic_header(
        args.path)  # more robust to check if a file is .hic
    if hic_info is None:
        hic = False
    else:
        hic = True

    if not hic:
        import cooler
        Lib = cooler.Cooler(args.path)
        chromosomes = Lib.chromnames[:]
    else:
        chromosomes = list(hic_info['chromsizes'])

    pre = utils.find_chrom_pre(chromosomes)
    tmp = os.path.split(args.model)[1]  # support full path
    ccname = pre + tmp.split('.pk')[0].lstrip(
        'chr')  # ccname is consistent with chromosome labels in .hic / .cool
    cikada = 'chr' + ccname.lstrip('chr')  # cikada always has prefix "chr"

    if not hic:
        X = scoreUtils.Chromosome(Lib.matrix(
            balance=args.balance, sparse=True).fetch(ccname).tocsr(),
                                  model=model,
                                  cname=cikada,
                                  lower=args.lower,
                                  upper=args.upper,
                                  res=args.resolution,
                                  width=args.width)
    else:
        if args.balance:
            X = scoreUtils.Chromosome(utils.csr_contact_matrix(
                'KR', args.path, ccname, ccname, 'BP', args.resolution),
                                      model=model,
                                      cname=cikada,
                                      lower=args.lower,
                                      upper=args.upper,
                                      res=args.resolution,
                                      width=args.width)
        else:
            X = scoreUtils.Chromosome(utils.csr_contact_matrix(
                'NONE', args.path, ccname, ccname, 'BP', args.resolution),
                                      model=model,
                                      cname=cikada,
                                      lower=args.lower,
                                      upper=args.upper,
                                      res=args.resolution,
                                      width=args.width)
    result, R = X.score()
    X.writeBed(args.output, result, R)