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 main():
    """
    main function
    """

    tad1, tad2, contacts1, contacts2 = generate_random_contacts(size=12,
                                                                prob_mut=0.5,
                                                                num_changes=2)
    size1 = len(tad1)
    size2 = len(tad2)  #max([max(c) for c in contacts2])
    num_v = min(size1, size2)
    #align1a, align2a, scorea = run_aleigen(contacts1,
    #                                       contacts2, num_v)
    align1, align2, score = optimal_cmo(tad1, tad2, num_v)
    align1b = []
    align2b = []
    for c in range(len(align1)):
        if align1[c] != '-' and align2[c] != '-':
            align1b.append(align1[c])
            align2b.append(align2[c])
    print('=' * 80)
    print(''.join(['{:>5}'.format(i) for i in range(len(tad1))]))
    print('\n'.join(
        [''.join(['{:>5}'.format(round(j, 2)) for j in i]) for i in tad1]))
    print('-' * 80)
    print(''.join(['{:>5}'.format(i) for i in range(len(tad2))]))
    print('\n'.join(
        [''.join(['{:>5}'.format(round(j, 2)) for j in i]) for i in tad2]))
    print('=' * 80)
    #print ''.join(['{:>4}'.format(a) for a in align1a])
    #print ''.join(['{:>4}'.format(a) for a in align2a])
    print('-' * 80)
    print(''.join(['{:>4}'.format(a) for a in align1b]))
    print(''.join(['{:>4}'.format(a) for a in align2b]))
    print('=' * 80)
Example #4
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 #5
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 #6
0
def main():
    """
    main function
    """

    tad1, tad2, contacts1, contacts2 = generate_random_contacts(size=12,
                                                                prob_mut=0.5,
                                                                num_changes=2)
    size1 = len(tad1)
    size2 = len(tad2)#max([max(c) for c in contacts2])
    num_v = min(size1, size2)
    #align1a, align2a, scorea = run_aleigen(contacts1,
    #                                       contacts2, num_v)
    align1, align2, score = optimal_cmo(tad1, tad2, num_v)
    align1b = []
    align2b = []
    for c in xrange(len(align1)):
        if align1[c] != '-' and align2[c] != '-':
            align1b.append(align1[c])
            align2b.append(align2[c])
    print '='*80
    print ''.join(['{:>5}'.format(i) for i in range(len(tad1))])
    print '\n'.join([''.join(['{:>5}'.format(round(j, 2)) for j in i]) for i in tad1])
    print '-'*80
    print ''.join(['{:>5}'.format(i) for i in range(len(tad2))])
    print '\n'.join([''.join(['{:>5}'.format(round(j, 2)) for j in i]) for i in tad2])
    print '='*80
    #print ''.join(['{:>4}'.format(a) for a in align1a])
    #print ''.join(['{:>4}'.format(a) for a in align2a])
    print '-'*80
    print ''.join(['{:>4}'.format(a) for a in align1b])
    print ''.join(['{:>4}'.format(a) for a in align2b])
    print '='*80
Example #7
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 #8
0
def compareTwoTADs():
    from pytadbit.tad_clustering.tad_cmo import optimal_cmo
    tad1 = list(my_chrom.iter_tads('Control'))[31]
    tad2 = list(my_chrom.iter_tads('Control'))[35]
    align1, align2, score = optimal_cmo(tad1[1],
                                        tad2[1],
                                        max_num_v=8,
                                        long_nw=True,
                                        long_dist=True,
                                        method='frobenius')
Example #9
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 #10
0
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


cmap = plt.get_cmap()
cmap.set_bad(color = 'k', alpha = .7)
plt.subplot(2, 2, 2)
plt.imshow(log2(matrix1), origin='lower', interpolation="nearest")