def _cap_enzymes_between_alleles(allele1, allele2, reference, location, all_enzymes=False): '''It looks in the enzymes that differenciate the given alleles. It returns a set. ''' kind1 = allele1['kind'] kind2 = allele2['kind'] allele1 = allele1['allele'] allele2 = allele2['allele'] #we have to build the two sequences if all_enzymes: restriction_batch = CommOnly else: restriction_batch = RestrictionBatch(COMMON_ENZYMES) seq1 = create_alleles('seq1', allele1, kind1, reference, location) seq2 = create_alleles('seq2', allele2, kind2, reference, location) anal1 = Analysis(restriction_batch, seq1, linear=True) enzymes1 = set(anal1.with_sites().keys()) anal1 = Analysis(restriction_batch, seq2, linear=True) enzymes2 = set(anal1.with_sites().keys()) enzymes = set(enzymes1).symmetric_difference(set(enzymes2)) return enzymes
def test_analysis_restrictions(self): """Test Fancier restriction analysis """ new_seq = Seq('TTCAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAA', IUPACAmbiguousDNA()) rb = RestrictionBatch([EcoRI, KpnI, EcoRV]) ana = Analysis(rb, new_seq, linear=False) self.assertEqual( ana.blunt(), {EcoRV: []}) # output only the result for enzymes which cut blunt self.assertEqual(ana.full(), {KpnI: [], EcoRV: [], EcoRI: [33]}) self.assertEqual( ana.with_sites(), {EcoRI: [33] }) # output only the result for enzymes which have a site self.assertEqual(ana.without_site(), { KpnI: [], EcoRV: [] }) # output only the enzymes which have no site self.assertEqual(ana.with_site_size([32]), {}) self.assertEqual(ana.only_between(1, 20), {}) # the enzymes which cut between position 1 and 20 self.assertEqual(ana.only_between(20, 34), {EcoRI: [33]}) # etc... self.assertEqual(ana.only_between(34, 20), {EcoRI: [33]}) # mix start end order self.assertEqual(ana.only_outside(20, 34), {}) with self.assertWarns(BiopythonWarning): ana.with_name(['fake']) self.assertEqual(ana.with_name([EcoRI]), {EcoRI: [33]}) self.assertEqual((ana._boundaries(1, 20)[:2]), (1, 20)) self.assertEqual((ana._boundaries(20, 1)[:2]), (1, 20)) # reverse order self.assertEqual((ana._boundaries(-1, 20)[:2]), (20, 33)) # fix negative start
def test_analysis_restrictions(self): """Test Fancier restriction analysis.""" new_seq = Seq('TTCAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAA', IUPACAmbiguousDNA()) rb = RestrictionBatch([EcoRI, KpnI, EcoRV]) ana = Analysis(rb, new_seq, linear=False) # Output only the result for enzymes which cut blunt: self.assertEqual(ana.blunt(), {EcoRV: []}) self.assertEqual(ana.full(), {KpnI: [], EcoRV: [], EcoRI: [33]}) # Output only the result for enzymes which have a site: self.assertEqual(ana.with_sites(), {EcoRI: [33]}) # Output only the enzymes which have no site: self.assertEqual(ana.without_site(), {KpnI: [], EcoRV: []}) self.assertEqual(ana.with_site_size([32]), {}) # Output only enzymes which produce 5' overhangs self.assertEqual(ana.overhang5(), {EcoRI: [33]}) # Output only enzymes which produce 3' overhangs self.assertEqual(ana.overhang3(), {KpnI: []}) # Output only enzymes which produce defined ends self.assertEqual(ana.defined(), {KpnI: [], EcoRV: [], EcoRI: [33]}) # Output only enzymes hich cut N times self.assertEqual(ana.with_N_sites(2), {}) # The enzymes which cut between position x and y: with self.assertRaises(TypeError): ana.only_between('t', 20) with self.assertRaises(TypeError): ana.only_between(1, 't') self.assertEqual(ana.only_between(1, 20), {}) self.assertEqual(ana.only_between(20, 34), {EcoRI: [33]}) # Mix start/end order: self.assertEqual(ana.only_between(34, 20), {EcoRI: [33]}) self.assertEqual(ana.only_outside(20, 34), {}) with self.assertWarns(BiopythonWarning): ana.with_name(['fake']) self.assertEqual(ana.with_name([EcoRI]), {EcoRI: [33]}) self.assertEqual((ana._boundaries(1, 20)[:2]), (1, 20)) # Reverse order: self.assertEqual((ana._boundaries(20, 1)[:2]), (1, 20)) # Fix negative start: self.assertEqual((ana._boundaries(-1, 20)[:2]), (20, 33)) # Fix negative end: self.assertEqual((ana._boundaries(1, -1)[:2]), (1, 33)) # Sites in- and outside of boundaries new_seq = Seq('GAATTCAAAAAAGAATTC', IUPACAmbiguousDNA()) rb = RestrictionBatch([EcoRI]) ana = Analysis(rb, new_seq) # Cut at least inside self.assertEqual(ana.between(1, 7), {EcoRI: [2, 14]}) # Cut at least inside and report only inside site self.assertEqual(ana.show_only_between(1, 7), {EcoRI: [2]}) # Cut at least outside self.assertEqual(ana.outside(1, 7), {EcoRI: [2, 14]}) # Don't cut within self.assertEqual(ana.do_not_cut(7, 12), {EcoRI: [2, 14]})