Example #1
0
    def test_06_tad_clustering(self):
        if ONLY and ONLY != "06":
            return
        if CHKTIME:
            t0 = time()

        test_chr = Chromosome(
            name="Test Chromosome",
            experiment_tads=[exp4],
            experiment_names=["exp1"],
            experiment_hic_data=[PATH + "/20Kb/chrT/chrT_D.tsv"],
            experiment_resolutions=[20000, 20000],
            silent=True,
        )
        all_tads = []
        for _, tad in test_chr.iter_tads("exp1", normed=False):
            all_tads.append(tad)
        # align1, align2, _ = optimal_cmo(all_tads[7], all_tads[10], 7,
        #                                method='score')
        align1, align2, _ = optimal_cmo(all_tads[1], all_tads[3], 7, method="score")
        # Values with square root normalization.
        # self.assertEqual(align1, [0, 1, '-', 2, 3, '-', 4, 5, 6, 7, 8, 9, 10])
        # self.assertEqual(align2,[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
        self.assertEqual(align1, [0, 1, 2, "-", "-", 3, 4, 5, 6, 7, 8, "-", 9])
        self.assertEqual(align2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
        if CHKTIME:
            print "6", time() - t0
Example #2
0
    def test_06_tad_clustering(self):
        if ONLY and not "06" in ONLY:
            return
        if CHKTIME:
            t0 = time()

        test_chr = Chromosome(
            name="Test Chromosome",
            experiment_tads=[exp4],
            experiment_names=["exp1"],
            experiment_hic_data=[PATH + "/20Kb/chrT/chrT_D.tsv"],
            experiment_resolutions=[20000, 20000],
            silent=True)
        all_tads = []
        for _, tad in test_chr.iter_tads("exp1", normed=False):
            all_tads.append(tad)
        #align1, align2, _ = optimal_cmo(all_tads[7], all_tads[10], 7,
        #                                method="score")
        align1, align2, _ = optimal_cmo(all_tads[1],
                                        all_tads[3],
                                        7,
                                        method="score")
        # Values with square root normalization.
        #self.assertEqual(align1, [0, 1, "-", 2, 3, "-", 4, 5, 6, 7, 8, 9, 10])
        #self.assertEqual(align2,[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
        self.assertEqual(align1, [0, 1, 2, "-", "-", 3, 4, 5, 6, 7, 8, "-", 9])
        self.assertEqual(align2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
        if CHKTIME:
            print "6", time() - t0
Example #3
0
    def test_06_tad_clustering(self):
        if ONLY and ONLY != '06':
            return
        if CHKTIME:
            t0 = time()

        test_chr = Chromosome(name='Test Chromosome',
                              experiment_tads=[exp4],
                              experiment_names=['exp1'],
                              experiment_hic_data=[
                                  PATH + '/20Kb/chrT/chrT_D.tsv'],
                              experiment_resolutions=[20000,20000],
                              silent=True)
        all_tads = []
        for _, tad in test_chr.iter_tads('exp1', normed=False):
            all_tads.append(tad)
        #align1, align2, _ = optimal_cmo(all_tads[7], all_tads[10], 7,
        #                                method='score')
        align1, align2, _ = optimal_cmo(all_tads[1], all_tads[3], 7,
                                        method='score')
        # Values with square root normalization.
        #self.assertEqual(align1, [0, 1, '-', 2, 3, '-', 4, 5, 6, 7, 8, 9, 10])
        #self.assertEqual(align2,[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
        self.assertEqual(align1, [0, 1, 2, '-', '-', 3, 4, 5, 6, 7, 8, '-', 9])
        self.assertEqual(align2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
        if CHKTIME:
            print '6', time() - t0
Example #4
0
    def test_06_tad_clustering(self):
        if CHKTIME:
            t0 = time()

        test_chr = Chromosome(name='Test Chromosome',
                              experiment_tads=[exp4],
                              experiment_names=['exp1'],
                              experiment_hic_data=[
                                  PATH + '/20Kb/chrT/chrT_D.tsv'],
                              experiment_resolutions=[20000,20000],
                              silent=True)
        all_tads = []
        for _, tad in test_chr.iter_tads('exp1'):
            all_tads.append(tad)
        #align1, align2, _ = optimal_cmo(all_tads[7], all_tads[10], 7,
        #                                method='score')
        align1, align2, _ = optimal_cmo(all_tads[1], all_tads[3], 7,
                                        method='score')
        # Values with square root normalization.
        #self.assertEqual(align1, [0, 1, '-', 2, 3, '-', 4, 5, 6, 7, 8, 9, 10])
        #self.assertEqual(align2,[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
        self.assertEqual(align1, [0, 1, 2, '-', '-', 3, 4, 5, 6, 7, 8, '-', 9])
        self.assertEqual(align2, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
        if CHKTIME:
            print '6', time() - t0
Example #5
0
 def tad_clustering(self):
     test_chr = Chromosome(name="Test Chromosome", resolution=20000)
     test_chr.add_experiment("chrT/chrT_A.tsv", name="exp1")
     test_chr.find_TAD(["exp1"])
     all_tads = list(test_chr.iter_tads("exp1"))
     align1, align2 = optimal_cmo(all_tads[4], all_tads[8], 9)
     self.assertEqual(align1, [1, 2, "-", "-", "-", "-", 3, "-", 4, 5, 6, "-", 7, 8])
     self.assertEqual(align2, [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15])
Example #6
0
 def test_06_tad_clustering(self):
     test_chr = Chromosome(name='Test Chromosome',
                           experiment_tads=[exp4],
                           experiment_names=['exp1'],
                           experiment_hic_data=['20Kb/chrT/chrT_D.tsv'],
                           experiment_resolutions=[20000,20000])
     all_tads = []
     for _, tad in test_chr.iter_tads('exp1'):
         all_tads.append(tad)
     align1, align2, _ = optimal_cmo(all_tads[7], all_tads[10], 7,
                                     method='score')
     self.assertEqual(align1, [0, 1, '-', 2, 3, '-', 4, 5, 6, 7, 8, 9, 10])
     self.assertEqual(align2,[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])
Example #7
0
def main():
    """
    main function
    """
    n_pick = 4
    n_tot  = 10
    test_chr = Chromosome(name='Test Chromosome')
    test_chr.add_experiment('exp1', 100000, xp_handler=PATH +
                            'HIC_gm06690_chr19_chr19_100000_obs.txt')
    test_chr.find_tad(['exp1'])
    real_tads = {}
    for i, t in enumerate(test_chr.iter_tads('exp1', normed=False)):
        real_tads[i] = test_chr.experiments['exp1'].tads[i]
        real_tads[i]['hic'] = t[1]
    global DISTRA
    global DISTRD
    DISTRA, DISTRD = get_hic_distr(real_tads)
    # pick some tads
    picked_tads = []
    picked_keys = []
    for i in xrange(n_pick):
        key, new_tad = get_random_tad(real_tads)
        while key in picked_keys or (new_tad['end'] - new_tad['start'] < 15):
            key, new_tad = get_random_tad(real_tads)
        picked_tads.append(new_tad)
        picked_keys.append(key)
    # mutate this tads
    tads = {}
    tad_matrices = []
    tad_names = []
    for i in xrange(n_pick):
        print i
        tads[uppercase[i] + '_' + str(0)] = picked_tads[i]
        tad_names.append(uppercase[i] + '_' + str(0))
        for j in xrange(1, n_tot):
            hic, indels = generate_random_contacts(
                tad1=picked_tads[i]['hic'], prob=0.05, ext=int(random()*4) + 1,
                indel=int(random() * 4) + 1)[1:]
            # indels = '|'.join([str(n-1) if n>0 else '-' + str((abs(n)-1)) for n in indels])
            tads[uppercase[i] + '_' + str(j)] = {
                'hic'  : hic,
                'start': picked_tads[i]['start'],
                'end'  : picked_tads[i]['end']}
            tad_matrices.append(hic)
            tad_names.append(uppercase[i] + '_' + str(j))
    distances, cci = get_distances(tad_matrices, max_num_v=4,
                                   n_cpus=mu.cpu_count())
    results, clusters = pre_cluster(distances, cci, len(tad_matrices))
    paint_clustering(results, clusters, len(tad_matrices), test_chr,
                     tad_names, tad_matrices)
Example #8
0
def main():
    test_chr = Chromosome(name='Test Chromosome')
    test_chr.add_experiment('exp1', 100000, xp_handler=PATH +
                            'HIC_k562_chr19_chr19_100000_obs.txt')
    test_chr.find_tad(['exp1'])
    tad_names = []
    tad_matrices = []
    for name, matrix in test_chr.iter_tads('exp1'):
        if test_chr.experiments['exp1'].tads[name]['score'] < 0:
            continue
        if (test_chr.experiments['exp1'].tads[name]['end'] -
            test_chr.experiments['exp1'].tads[name]['start']) < 10:
            continue
        tad_names.append(name)
        tad_matrices.append(matrix)
    num = len(tad_names)
    distances, cci = get_distances(tad_matrices, max_num_v=mu.cpu_count())
    results, clusters = pre_cluster(distances, cci, num)
    paint_clustering(results, clusters, num, test_chr, tad_names)
Example #9
0
def main():
    test_chr = Chromosome(name='Test Chromosome')
    test_chr.add_experiment('exp1',
                            100000,
                            xp_handler=PATH +
                            'HIC_k562_chr19_chr19_100000_obs.txt')
    test_chr.find_tad(['exp1'])
    tad_names = []
    tad_matrices = []
    for name, matrix in test_chr.iter_tads('exp1'):
        if test_chr.experiments['exp1'].tads[name]['score'] < 0:
            continue
        if (test_chr.experiments['exp1'].tads[name]['end'] -
                test_chr.experiments['exp1'].tads[name]['start']) < 10:
            continue
        tad_names.append(name)
        tad_matrices.append(matrix)
    num = len(tad_names)
    distances, cci = get_distances(tad_matrices, max_num_v=mu.cpu_count())
    results, clusters = pre_cluster(distances, cci, num)
    paint_clustering(results, clusters, num, test_chr, tad_names)
Example #10
0
ali.get_column(3)

cond1 = lambda x: x['score'] > 7
   
print ali.get_column(cond1=cond1)

cond2 = lambda x: x['pos'] > 50
print ali.get_column(cond1=cond1, cond2=cond2)

print ali.get_column(cond1=cond1, cond2=cond2, min_num=1)


exp = my_chrom.experiments[0]

tad1 = list(my_chrom.iter_tads('First Hi-C experiment'))[41]
tad2 = list(my_chrom.iter_tads('First Hi-C experiment'))[39]


from pytadbit.tad_clustering.tad_cmo import optimal_cmo

align1, align2, score = optimal_cmo(tad1[1], tad2[1], max_num_v=8, long_nw=True, long_dist=True, method='frobenius')


from pytadbit.tad_clustering.tad_cmo import merge_tads


matrix1, matrix2, matrix_merged = merge_tads(tad1[1], tad2[1], align1, align2)

from matplotlib import pyplot as plt
from numpy import log2