def test_three_contig_2(self):
     c_1 = ['GATCAAAA', 'CCCGGAAA','AAAAGATC']
     contig_dict_1 = mc.merge_check_global(c_1, 3)
     bbr_test_1 = mc.suffix_filter(contig_dict_1)
     bbl_test_1 = mc.extract_bbl(bbr_test_1)
     bbl_truth_1 = {'AAAAGATC':['GATCAAAA', 4], 'GATCAAAA':['AAAAGATC',4]}
     self.assertEqual(bbl_test_1, bbl_truth_1)
 def test_three_contig_3(self):
     c_1 = ['GATCTAAA', 'CCCGAAAA','AAAAGATC']
     contig_dict_1 = mc.merge_check_global(c_1, 3)
     bbr_test_1 = mc.suffix_filter(contig_dict_1)
     bbl_test_1 = mc.extract_bbl(bbr_test_1)
     contig_trace_test_1 = mc.trace_contigs(bbl_test_1)
     contig_trace_truth_1 = [[['CCCGAAAA',0],['AAAAGATC',4],['GATCTAAA',4]]]
     self.assertEqual(contig_trace_test_1, contig_trace_truth_1)
Example #3
0
 def test_three_contig_4(self):
     c_1 = ['GATCTAAA', 'CCCGAAAA', 'AAAAGATC']
     contig_dict_1 = mc.merge_check_global(c_1, 3)
     bbr_test_1 = mc.suffix_filter(contig_dict_1)
     bbl_test_1 = mc.extract_bbl(bbr_test_1)
     contig_trace_test_1 = mc.trace_contigs(bbl_test_1)
     new_contigs_test_1 = mc.merge_contigs(contig_trace_test_1, c_1)
     new_contigs_truth_1 = ['CCCGAAAAGATCTAAA']
     self.assertEqual(new_contigs_test_1, new_contigs_truth_1)
Example #4
0
 def test_three_contig_2(self):
     c_1 = ['GATCAAAA', 'CCCGGAAA', 'AAAAGATC']
     contig_dict_1 = mc.merge_check_global(c_1, 3)
     bbr_test_1 = mc.suffix_filter(contig_dict_1)
     bbl_test_1 = mc.extract_bbl(bbr_test_1)
     bbl_truth_1 = {
         'AAAAGATC': ['GATCAAAA', 4],
         'GATCAAAA': ['AAAAGATC', 4]
     }
     self.assertEqual(bbl_test_1, bbl_truth_1)
 def test_three_contig_1(self):
     c_1 = ['GATCTTTT', 'GATCGATC','ATCAAAAA']
     contig_dict_1 = mc.merge_check_global(c_1, 3)
     bbr_test_1 = mc.suffix_filter(contig_dict_1)
     bbr_truth_1 = {'GATCGATC':['GATCTTTT', 4]}
     self.assertEqual(bbr_test_1,bbr_truth_1)
     c_2 = ['GATCAAAA', 'CCCGGAAA','AAAAGATC']
     contig_dict_2 = mc.merge_check_global(c_2, 3)
     bbr_test_2 = mc.suffix_filter(contig_dict_2)
     bbr_truth_2 = {'CCCGGAAA':['AAAAGATC', 3], 'AAAAGATC':['GATCAAAA', 4], 'GATCAAAA':['AAAAGATC', 4]}
     self.assertEqual(bbr_test_2,bbr_truth_2)
Example #6
0
 def test_three_contig_1(self):
     c_1 = ['GATCTTTT', 'GATCGATC', 'ATCAAAAA']
     contig_dict_1 = mc.merge_check_global(c_1, 3)
     bbr_test_1 = mc.suffix_filter(contig_dict_1)
     bbr_truth_1 = {'GATCGATC': ['GATCTTTT', 4]}
     self.assertEqual(bbr_test_1, bbr_truth_1)
     c_2 = ['GATCAAAA', 'CCCGGAAA', 'AAAAGATC']
     contig_dict_2 = mc.merge_check_global(c_2, 3)
     bbr_test_2 = mc.suffix_filter(contig_dict_2)
     bbr_truth_2 = {
         'CCCGGAAA': ['AAAAGATC', 3],
         'AAAAGATC': ['GATCAAAA', 4],
         'GATCAAAA': ['AAAAGATC', 4]
     }
     self.assertEqual(bbr_test_2, bbr_truth_2)
 def test_read_reverse_1(self):
     reads_dict_1 = {'AAAAT':[[0,0,0.5,1]],'AAATC':[[0,1,0.5,1]],'AATCA':[[0,2,0.5,1],[1,0,0.5,1]],'ATCAG':[[1,1,0.5,1]],'TTTTT':[[2,0,0.5,1]]}
     reverse_dict_test_1 = mc.reverse_reads_dict(reads_dict_1)
     reverse_dict_truth_1 = {0:[['AAAAT',0,0.5,1],['AAATC',1,0.5,1],['AATCA',2,0.5,1]],1:[['AATCA',0,0.5,1],['ATCAG',1,0.5,1]],2:[['TTTTT',0,0.5,1]]}
     for i in reverse_dict_test_1:
         for j in reverse_dict_test_1[i]:
             self.assertTrue(j in reverse_dict_truth_1[i])
Example #8
0
 def test_merge_check_1(self):
     c_1 = ['GATCTTTT', 'GATCGATC']
     test_1 = mc.merge_check_global(c_1, 3)
     truth_1 = {
         'GATCTTTT': Counter({'GATCGATC': 0}),
         'GATCGATC': Counter({'GATCTTTT': 4})
     }
     self.assertEqual(test_1, truth_1)
 def test_run(self):
     c_1 = ['AAAATCA', 'AATCAGG', 'TTTTTTT']
     reads_dict_1 = {'AAAAT':[[0,0,0.5,1]],'AAATC':[[0,1,0.5,1]],'AATCA':[[0,2,0.5,1],[1,0,0.5,1]],'ATCAG':[[1,1,0.5,1]],'TTTTT':[[2,0,0.5,1]]}
     new_contigs_test_1, new_reads_test_1 = mc.run_merge(c_1,reads_dict_1,3)
     new_contigs_truth_1 = ['AAAATCAGG','TTTTTTT']
     new_reads_dict_truth_1 = {'ATCAG': [[0,3,0.5,1]], 'AATCA': [[0,2,0.5,1]], 'AAAAT': [[0,0,0.5,1]], 'TTTTT': [[1,0,0.5,1]], 'AAATC': [[0,1,0.5,1]]}
     self.assertEqual(new_reads_dict_truth_1, new_reads_test_1)
     self.assertEqual(new_contigs_truth_1,new_contigs_test_1)
Example #10
0
 def test_read_updates_1(self):
     c_1 = ['AAAATCA', 'AATCAGG', 'TTTTTTT']
     contig_dict_1 = mc.merge_check_global(c_1, 3)
     bbr_test_1 = mc.suffix_filter(contig_dict_1)
     bbl_test_1 = mc.extract_bbl(bbr_test_1)
     contig_trace_test_1 = mc.trace_contigs(bbl_test_1)
     new_contigs_test_1 = mc.merge_contigs(contig_trace_test_1, c_1[:])
     reads_dict_1 = {
         'AAAAT': [[0, 0, 0.5, 1]],
         'AAATC': [[0, 1, 0.5, 1]],
         'AATCA': [[0, 2, 0.5, 1], [1, 0, 0.5, 1]],
         'ATCAG': [[1, 1, 0.5, 1]],
         'TTTTT': [[2, 0, 0.5, 1]]
     }
     reverse_dict_test_1 = mc.reverse_reads_dict(reads_dict_1)
     new_reads_dict_test_1 = mc.change_reads_on_merge(
         reverse_dict_test_1, reads_dict_1, contig_trace_test_1, c_1,
         new_contigs_test_1)
     new_reads_dict_truth_1 = {
         'ATCAG': [[0, 3, 0.5, 1]],
         'AATCA': [[0, 2, 0.5, 1]],
         'AAAAT': [[0, 0, 0.5, 1]],
         'TTTTT': [[1, 0, 0.5, 1]],
         'AAATC': [[0, 1, 0.5, 1]]
     }
     self.assertEqual(new_reads_dict_truth_1, new_reads_dict_test_1)
 def test_read_updates_1(self):
     c_1 = ['AAAATCA', 'AATCAGG', 'TTTTTTT']
     contig_dict_1 = mc.merge_check_global(c_1,3)
     bbr_test_1 = mc.suffix_filter(contig_dict_1)
     bbl_test_1 = mc.extract_bbl(bbr_test_1)
     contig_trace_test_1 = mc.trace_contigs(bbl_test_1)
     new_contigs_test_1 = mc.merge_contigs(contig_trace_test_1, c_1[:])
     reads_dict_1 = {'AAAAT':[[0,0,0.5,1]],'AAATC':[[0,1,0.5,1]],'AATCA':[[0,2,0.5,1],[1,0,0.5,1]],'ATCAG':[[1,1,0.5,1]],'TTTTT':[[2,0,0.5,1]]}
     reverse_dict_test_1 = mc.reverse_reads_dict(reads_dict_1)
     new_reads_dict_test_1 = mc.change_reads_on_merge(reverse_dict_test_1, reads_dict_1, contig_trace_test_1, c_1, new_contigs_test_1)
     new_reads_dict_truth_1 = {'ATCAG': [[0,3,0.5,1]], 'AATCA': [[0,2,0.5,1]], 'AAAAT': [[0,0,0.5,1]], 'TTTTT': [[1,0,0.5,1]], 'AAATC': [[0,1,0.5,1]]}
     self.assertEqual(new_reads_dict_truth_1, new_reads_dict_test_1)
Example #12
0
 def test_read_reverse_1(self):
     reads_dict_1 = {
         'AAAAT': [[0, 0, 0.5, 1]],
         'AAATC': [[0, 1, 0.5, 1]],
         'AATCA': [[0, 2, 0.5, 1], [1, 0, 0.5, 1]],
         'ATCAG': [[1, 1, 0.5, 1]],
         'TTTTT': [[2, 0, 0.5, 1]]
     }
     reverse_dict_test_1 = mc.reverse_reads_dict(reads_dict_1)
     reverse_dict_truth_1 = {
         0: [['AAAAT', 0, 0.5, 1], ['AAATC', 1, 0.5, 1],
             ['AATCA', 2, 0.5, 1]],
         1: [['AATCA', 0, 0.5, 1], ['ATCAG', 1, 0.5, 1]],
         2: [['TTTTT', 0, 0.5, 1]]
     }
     for i in reverse_dict_test_1:
         for j in reverse_dict_test_1[i]:
             self.assertTrue(j in reverse_dict_truth_1[i])
Example #13
0
 def test_run(self):
     c_1 = ['AAAATCA', 'AATCAGG', 'TTTTTTT']
     reads_dict_1 = {
         'AAAAT': [[0, 0, 0.5, 1]],
         'AAATC': [[0, 1, 0.5, 1]],
         'AATCA': [[0, 2, 0.5, 1], [1, 0, 0.5, 1]],
         'ATCAG': [[1, 1, 0.5, 1]],
         'TTTTT': [[2, 0, 0.5, 1]]
     }
     new_contigs_test_1, new_reads_test_1 = mc.run_merge(
         c_1, reads_dict_1, 3)
     new_contigs_truth_1 = ['AAAATCAGG', 'TTTTTTT']
     new_reads_dict_truth_1 = {
         'ATCAG': [[0, 3, 0.5, 1]],
         'AATCA': [[0, 2, 0.5, 1]],
         'AAAAT': [[0, 0, 0.5, 1]],
         'TTTTT': [[1, 0, 0.5, 1]],
         'AAATC': [[0, 1, 0.5, 1]]
     }
     self.assertEqual(new_reads_dict_truth_1, new_reads_test_1)
     self.assertEqual(new_contigs_truth_1, new_contigs_test_1)
Example #14
0
 def test_merge_check_2(self):
     c_1 = ['GATCTTTT', 'GATCGATC']
     test_1 = mc.merge_check_global(c_1, 5)
     truth_1 = []
     self.assertEqual(test_1, truth_1)
 def test_merge_check_2(self):
     c_1 = ['GATCTTTT', 'GATCGATC']
     test_1 = mc.merge_check_global(c_1, 5)
     truth_1 = []
     self.assertEqual(test_1, truth_1)
def _main():

    # Open files and process reads dictionary
    f = open(sys.argv[1], 'r') 
    reads_dict = init._process(f)

    # Get contigs from first consensus sequence
    contigs = cs.run_consensus(reads_dict)
    contig_file = open(sys.argv[2] + '/contig.txt', 'w+')
    ll_file = open(sys.argv[2] + '/likelihood.txt', 'w+')

    # Set initial parameters 
    likelihood = 0
    likelihood_new = 0
    #likelihood_list = []

    for i in range(NUM_ITERS):

        '''FILE WRITES'''
        # Contigs file write data
        contig_file.write('%s\tstart\t' %(str(i)))
        for c in contigs:
            contig_file.write('%s\t' %(str(c)))
        contig_file.write('\n')
        contig_file.flush()
        # Likelihood file write data
        ll_file.write('%s\t%s\t%s\n' %(str(i), str(likelihood), str(len(contigs)))), ll_file.flush()
        #likelihood_list.append(float(likelihood))
        # Reads file write data
        reads_file = open(sys.argv[2] + '/reads_trial_' + str(i) + '.txt','w')
        for r in reads_dict:
            for l in reads_dict[r]:
                reads_file.write(str(l[3])+','+str(l[0])+','+str(l[1])+str(',')+str(l[3])+'\n')
        reads_file.close()
        '''COMPUTATION OF ALGORITHM'''
        # Update likelihood
        likelihood = likelihood_new
        # Map reads
        reads_dict = rm.run(reads_dict, contigs)
        # Run Consensus Sequence
        contigs = cs.run_consensus(reads_dict)
        # Print data to file
        contig_file.write('%s\tmerge\t' %(str(i)))
        for c in contigs:
            contig_file.write('%s\t' %(str(c)))
        contig_file.write('\n')
        # Run merge
        contigs, reads_dict = mc.run_merge(contigs,reads_dict) # how do we know if a merge has happened..do we need to know?
        # Get new likelihood
        likelihood_new = ll._likelihood(reads_dict,contigs)


    '''FILE WRITES'''
    # Reads file write data
    reads_file = open(sys.argv[2] + '/reads_trial_' + str(i+1) + '.txt','w')
    for r in reads_dict:
        for l in reads_dict[r]:
            reads_file.write(str(l[3])+','+str(l[0])+','+str(l[1])+str(',')+str(l[3])+'\n')
    reads_file.close()
    # Print data to file
    for c in contigs:
        contig_file.write('1000\tend\t%s\n' %(str(c)))
    ll_file.write('%s\t%s\t%s\n' %(str(NUM_ITERS), str(likelihood), str(len(contigs)))), ll_file.flush()
Example #17
0
def _main():

    # Open files and process reads dictionary
    f = open(sys.argv[1], 'r')
    reads_dict = init._process(f)

    # Get contigs from first consensus sequence
    contigs = cs.run_consensus(reads_dict)
    contig_file = open(sys.argv[2] + '/contig.txt', 'w+')
    ll_file = open(sys.argv[2] + '/likelihood.txt', 'w+')

    # Set initial parameters
    likelihood = 0
    likelihood_new = 0
    #likelihood_list = []

    for i in range(NUM_ITERS):
        '''FILE WRITES'''
        # Contigs file write data
        contig_file.write('%s\tstart\t' % (str(i)))
        for c in contigs:
            contig_file.write('%s\t' % (str(c)))
        contig_file.write('\n')
        contig_file.flush()
        # Likelihood file write data
        ll_file.write(
            '%s\t%s\t%s\n' %
            (str(i), str(likelihood), str(len(contigs)))), ll_file.flush()
        #likelihood_list.append(float(likelihood))
        # Reads file write data
        reads_file = open(sys.argv[2] + '/reads_trial_' + str(i) + '.txt', 'w')
        for r in reads_dict:
            for l in reads_dict[r]:
                reads_file.write(
                    str(l[3]) + ',' + str(l[0]) + ',' + str(l[1]) + str(',') +
                    str(l[3]) + '\n')
        reads_file.close()
        '''COMPUTATION OF ALGORITHM'''
        # Update likelihood
        likelihood = likelihood_new
        # Map reads
        reads_dict = rm.run(reads_dict, contigs)
        # Run Consensus Sequence
        contigs = cs.run_consensus(reads_dict)
        # Print data to file
        contig_file.write('%s\tmerge\t' % (str(i)))
        for c in contigs:
            contig_file.write('%s\t' % (str(c)))
        contig_file.write('\n')
        # Run merge
        contigs, reads_dict = mc.run_merge(
            contigs, reads_dict
        )  # how do we know if a merge has happened..do we need to know?
        # Get new likelihood
        likelihood_new = ll._likelihood(reads_dict, contigs)
    '''FILE WRITES'''
    # Reads file write data
    reads_file = open(sys.argv[2] + '/reads_trial_' + str(i + 1) + '.txt', 'w')
    for r in reads_dict:
        for l in reads_dict[r]:
            reads_file.write(
                str(l[3]) + ',' + str(l[0]) + ',' + str(l[1]) + str(',') +
                str(l[3]) + '\n')
    reads_file.close()
    # Print data to file
    for c in contigs:
        contig_file.write('1000\tend\t%s\n' % (str(c)))
    ll_file.write(
        '%s\t%s\t%s\n' %
        (str(NUM_ITERS), str(likelihood), str(len(contigs)))), ll_file.flush()
 def test_merge_check_1(self):
     c_1 = ['GATCTTTT', 'GATCGATC']
     test_1 = mc.merge_check_global(c_1, 3)
     truth_1 = {'GATCTTTT': Counter({'GATCGATC':0}), 'GATCGATC': Counter({'GATCTTTT':4})}
     self.assertEqual(test_1, truth_1)