def test_finds_orientation_two_contigs(self):
     filtered_graph = nx.Graph()
     filtered_graph.add_edges_from([ ('gene1', 'gene2'), ('gene2', 'gene3'), ('gene3', 'geneA'),\
                                     ('geneA', 'geneB'), ('geneB', 'gene4'), ('gene4', 'gene5')])
     neighbouring_contigs = [[('Contig1', 'Contig2'), 2, ['geneA',
                                                          'geneB']]]
     gene_detector = GeneDetector(
         'madansi/tests/data/assembly_4_sequences.fa',
         'madansi/tests/data/refine_contig_neighbours_9_blast_hits_file')
     refine_contig_neighbours_object = RefineContigNeighbours(
         neighbouring_contigs, filtered_graph, filtered_graph,
         'madansi/tests/data/refine_contig_neighbours_9_blast_hits_file',
         gene_detector, {
             'Contig1': ['', '', 1000],
             'Contig2': ['', '', 800]
         })
     refine_contig_neighbours_object.contigs = { 'Contig1':{'gene1':None, 'gene2':None, 'gene3':None},\
                                                 'Contig2':{'gene4':None, 'gene5':None}}
     refine_contig_neighbours_object.genes = {   'gene1':'Contig1', 'gene2':'Contig1', 'gene3':'Contig1',\
                                                 'gene4':'Contig2', 'gene5':'Contig2'}
     expected_dict = {
         'Contig1': {
             'Contig2': [980, 490]
         },
         'Contig2': {
             'Contig1': [2, 301]
         }
     }
     refine_contig_neighbours_object.ends_of_contigs()
     self.assertDictEqual(refine_contig_neighbours_object.contig_ends,
                          expected_dict)
 def test_keep_three_cycle_two_equal_weights(self):
     """Tests that when there are three cycles with all connections having equal weight, these are preserved under refinement"""
     filtered_graph = nx.Graph()
     filtered_graph.add_edges_from([ ('gene1', 'gene2'), ('gene2', 'gene3'), ('gene3', 'gene4'),\
                                     ('gene4', 'gene5'), ('gene6', 'gene7'), ('gene7', 'gene8'),\
                                     ('gene8', 'gene1')])
     
     neighbouring_contigs = [[('Contig1', 'Contig2'), 1, ['gene3', 'gene4']],\
                             [('Contig2', 'Contig3'), 1, ['gene5', 'gene6']],\
                             [('Contig1', 'Contig3'), 1, ['gene8', 'gene1']]]
     
     gene_detector = GeneDetector('madansi/tests/data/assembly_4_sequences.fa', 'madansi/tests/data/refine_contig_neighbours_9_blast_hits_file')
     
     
     refine_contig_neighbours_object = RefineContigNeighbours(neighbouring_contigs, filtered_graph,filtered_graph, 'madansi/tests/data/refine_contig_neighbours_9_blast_hits_file', gene_detector, {})
     
     refine_contig_neighbours_object.contigs = { 'Contig1':{'gene1':None, 'gene2':None, 'gene3':None},\
                                                 'Contig2':{'gene4':None, 'gene5':None}              ,\
                                                 'Contig3':{'gene6':None, 'gene7':None, 'gene8':None}}
                                                 
     refine_contig_neighbours_object.genes = {   'gene1':'Contig1', 'gene2':'Contig1', 'gene3':'Contig1',\
                                                 'gene4':'Contig2', 'gene5':'Contig2', 'gene6':'Contig3',\
                                                 'gene7':'Contig3', 'gene8':'Contig3'}
     
     self.assertEqual(sorted(refine_contig_neighbours_object.refine_contig_neighbours()), sorted(neighbouring_contigs))
 def test_finds_orientation_two_contigs(self):
     filtered_graph = nx.Graph()
     filtered_graph.add_edges_from([ ('gene1', 'gene2'), ('gene2', 'gene3'), ('gene3', 'geneA'),\
                                     ('geneA', 'geneB'), ('geneB', 'gene4'), ('gene4', 'gene5')])
     neighbouring_contigs = [[('Contig1', 'Contig2'), 2, ['geneA', 'geneB']]]
     gene_detector = GeneDetector('madansi/tests/data/assembly_4_sequences.fa', 'madansi/tests/data/refine_contig_neighbours_9_blast_hits_file')
     refine_contig_neighbours_object = RefineContigNeighbours(neighbouring_contigs, filtered_graph, filtered_graph, 'madansi/tests/data/refine_contig_neighbours_9_blast_hits_file', gene_detector,{'Contig1':['','',1000], 'Contig2':['', '', 800]})
     refine_contig_neighbours_object.contigs = { 'Contig1':{'gene1':None, 'gene2':None, 'gene3':None},\
                                                 'Contig2':{'gene4':None, 'gene5':None}}                      
     refine_contig_neighbours_object.genes = {   'gene1':'Contig1', 'gene2':'Contig1', 'gene3':'Contig1',\
                                                 'gene4':'Contig2', 'gene5':'Contig2'}                                 
     expected_dict = {'Contig1': {'Contig2':[980,490]}, 'Contig2': {'Contig1':[2,301]}}
     refine_contig_neighbours_object.ends_of_contigs()
     self.assertDictEqual(refine_contig_neighbours_object.contig_ends, expected_dict) 
 def test_short_contig_in_middle(self):
     """Tests the case when there is a contig with only two genes between longer ones, we should find that the connection that needs more iterations is removed"""
     filtered_graph = nx.Graph()
     filtered_graph.add_edges_from([ ('gene1', 'gene2'), ('gene2', 'gene3'), ('gene3', 'gene4'),\
                                     ('gene4', 'gene5'), ('gene5', 'gene6'), ('gene6', 'gene7'),\
                                     ('gene7', 'gene8')])
                                     
     neighbouring_contigs = [[('Contig1', 'Contig2'),1,['gene3','gene4']],\
                             [('Contig2', 'Contig3'),1,['gene5', 'gene6']],\
                             [('Contig1', 'Contig3'),2,['gene4', 'gene5']]]
                             
     gene_detector = GeneDetector('madansi/tests/data/assembly_4_sequences.fa', 'madansi/tests/data/refine_contig_neighbours_9_blast_hits_file' )
     
     refine_contig_neighbours_object = RefineContigNeighbours(neighbouring_contigs, filtered_graph, filtered_graph, 'madansi/tests/data/refine_contig_neighbours_9_blast_hits_file', gene_detector, {})
     refine_contig_neighbours_object.contigs = { 'Contig1': {'gene1':None, 'gene2':None, 'gene3':None},\
                                                 'Contig2':{'gene4':None, 'gene5':None},\
                                                 'Contig3':{'gene6':None, 'gene7':None, 'gene8':None}}
                                         
     refine_contig_neighbours_object.genes = {   'gene1':'Contig1', 'gene2':'Contig1', 'gene3':'Contig1',\
                                                 'gene4':'Contig2', 'gene5':'Contig2', 'gene6':'Contig3',\
                                                 'gene7':'Contig3', 'gene8':'Contig3'}
 
     self.assertEqual(sorted(refine_contig_neighbours_object.refine_contig_neighbours()), sorted([[('Contig1', 'Contig2'),1,['gene3', 'gene4']], [('Contig2', 'Contig3'),1,['gene5', 'gene6']]]))