def test_nisin(self):
        "Test lanthipeptide prediction for nisin A"
        rec = Record.from_biopython(seqio.read(
            helpers.get_path_to_nisin_with_detection()),
                                    taxon="bacteria")
        assert not rec.get_cds_motifs()
        result = run_specific_analysis(rec)
        assert len(result.clusters) == 1
        motifs = self.gather_all_motifs(result)
        assert len(motifs) == 1
        assert not rec.get_cds_motifs()
        result.add_to_record(rec)
        assert len(rec.get_cds_motifs()) == 1
        prepeptide = motifs[0]
        # real monoisotopic mass is 3351.51, but we overpredict a Dha
        self.assertAlmostEqual(3333.6,
                               prepeptide.monoisotopic_mass,
                               delta=0.05)
        # real mw is 3354.5, see above
        self.assertAlmostEqual(3336.0, prepeptide.molecular_weight, delta=0.05)
        for expected, calculated in zip([3354.0, 3372.1, 3390.1, 3408.1],
                                        prepeptide.alternative_weights):
            self.assertAlmostEqual(expected, calculated, delta=0.05)
        assert prepeptide.lan_bridges == 5
        self.assertEqual("MSTKDFNLDLVSVSKKDSGASPR", prepeptide.leader)
        self.assertEqual("ITSISLCTPGCKTGALMGCNMKTATCHCSIHVSK", prepeptide.core)
        self.assertEqual('Class I', prepeptide.peptide_subclass)

        initial_json = result.to_json()
        regenerated = LanthiResults.from_json(initial_json, rec)
        assert list(result.motifs_by_locus) == ["nisB"]
        assert str(result.motifs_by_locus) == str(regenerated.motifs_by_locus)
        assert result.clusters == regenerated.clusters
        assert initial_json == regenerated.to_json()
 def test_labyrinthopeptin(self):
     "Test lanthipeptide prediction for labyrinthopeptin"
     filename = path.get_full_path(__file__, 'data', 'labyrinthopeptin.gbk')
     rec = Record.from_biopython(seqio.read(filename), taxon="bacteria")
     assert not rec.get_cds_motifs()
     result = run_specific_analysis(rec)
     motifs = self.gather_all_motifs(result)
     assert len(motifs) == 2
     assert not rec.get_cds_motifs()
     result.add_to_record(rec)
     assert len(rec.get_cds_motifs()) == 2
 def test_sco_cluster3(self):
     "Test lanthipeptide prediction for SCO cluster #3"
     filename = path.get_full_path(__file__, 'data', 'sco_cluster3.gbk')
     rec = Record.from_biopython(seqio.read(filename), taxon="bacteria")
     assert not rec.get_cds_motifs()
     result = run_specific_analysis(rec)
     motifs = self.gather_all_motifs(result)
     assert len(motifs) == 1
     assert not rec.get_cds_motifs()
     result.add_to_record(rec)
     assert len(rec.get_cds_motifs()) == 1
     self.assertEqual('Class I', motifs[0].peptide_subclass)
 def test_lactocin_s(self):
     """Test lanthipeptide prediction for lactocin S"""
     filename = path.get_full_path(__file__, 'data', 'lactocin_s.gbk')
     rec = Record.from_biopython(seqio.read(filename), taxon="bacteria")
     assert not rec.get_cds_motifs()
     result = run_specific_analysis(rec)
     assert len(result.clusters) == 1
     assert result.clusters[1] == set(["lasM"])
     assert len(result.motifs_by_locus["lasM"]) == 1
     motifs = result.motifs_by_locus["lasM"]
     assert len(motifs) == 1
     assert not rec.get_cds_motifs()
     result.add_to_record(rec)
     assert len(rec.get_cds_motifs()) == 1
     self.assertEqual('Class II', motifs[0].peptide_subclass)
 def test_multiple_biosynthetic_enzymes(self):
     filename = path.get_full_path(__file__, 'data',
                                   'CP013129.1.section.gbk')
     rec = record_processing.parse_input_sequence(filename,
                                                  taxon="bacteria")[0]
     rec.clear_cds_motifs()
     assert rec.get_cluster(0).products == ("lanthipeptide", "nrps")
     assert rec.get_cluster(0).cds_children
     result = run_specific_analysis(rec)
     assert len(result.clusters) == 1
     assert result.clusters[1] == set(["AQF52_7190", "AQF52_7168"])
     motif = result.motifs_by_locus["AQF52_7190"][0]
     assert motif.peptide_subclass == "Class II"
     motif = result.motifs_by_locus["AQF52_7168"][0]
     assert motif.peptide_subclass == "Class III"
 def test_epidermin(self):
     "Test lanthipeptide prediction for epidermin"
     filename = path.get_full_path(__file__, 'data', 'epidermin.gbk')
     rec = Record.from_biopython(seqio.read(filename), taxon="bacteria")
     assert not rec.get_cds_motifs()
     result = run_specific_analysis(rec)
     motifs = self.gather_all_motifs(result)
     assert len(motifs) == 1
     assert not rec.get_cds_motifs()
     result.add_to_record(rec)
     assert len(rec.get_cds_motifs()) == 1
     prepeptide = motifs[0]
     self.assertAlmostEqual(2164, prepeptide.monoisotopic_mass, delta=0.5)
     self.assertAlmostEqual(2165.6, prepeptide.molecular_weight, delta=0.5)
     self.assertEqual(3, prepeptide.lan_bridges)
     self.assertEqual("MEAVKEKNDLFNLDVKVNAKESNDSGAEPR", prepeptide.leader)
     self.assertEqual("IASKFICTPGCAKTGSFNSYCC", prepeptide.core)
     self.assertEqual('Class I', prepeptide.peptide_subclass)
     self.assertEqual(['AviCys'], prepeptide.get_modifications())
    def test_epicidin(self):
        "Test lanthipeptide prediction for epicidin 280"
        filename = path.get_full_path(__file__, 'data', 'epicidin_280.gbk')
        rec = Record.from_biopython(seqio.read(filename), taxon="bacteria")
        assert len(rec.get_cds_motifs()) == 1
        result = run_specific_analysis(rec)
        motifs = self.gather_all_motifs(result)
        assert len(motifs) == 1
        assert len(rec.get_cds_motifs()) == 1
        result.add_to_record(rec)
        assert len(rec.get_cds_motifs()) == 2

        prepeptide = motifs[0]
        self.assertAlmostEqual(3115.7, prepeptide.monoisotopic_mass, delta=0.5)
        self.assertAlmostEqual(3117.7, prepeptide.molecular_weight, delta=0.5)
        for expected, calculated in zip([3135.7, 3153.7, 3171.7],
                                        prepeptide.alternative_weights):
            self.assertAlmostEqual(expected, calculated, delta=0.05)
        self.assertEqual(3, prepeptide.lan_bridges)
        self.assertEqual("MENKKDLFDLEIKKDNMENNNELEAQ", prepeptide.leader)
        self.assertEqual("SLGPAIKATRQVCPKATRFVTVSCKKSDCQ", prepeptide.core)
        self.assertEqual('Class I', prepeptide.peptide_subclass)
        self.assertEqual(['Lac'], prepeptide.get_modifications())
    def test_microbisporicin(self):
        "Test lanthipeptide prediction for microbisporicin"
        filename = path.get_full_path(__file__, 'data', 'microbisporicin.gbk')
        rec = Record.from_biopython(seqio.read(filename), taxon="bacteria")
        assert not rec.get_cds_motifs()
        result = run_specific_analysis(rec)
        motifs = self.gather_all_motifs(result)
        assert len(motifs) == 1
        assert not rec.get_cds_motifs()
        result.add_to_record(rec)
        assert len(rec.get_cds_motifs()) == 1

        prepeptide = motifs[0]
        # NOTE: this is not the correct weight for microbisporicin
        # there are some additional modifications we do not predict yet
        self.assertAlmostEqual(2212.9, prepeptide.monoisotopic_mass, delta=0.5)
        self.assertAlmostEqual(2214.5, prepeptide.molecular_weight, delta=0.5)
        self.assertEqual(4, prepeptide.lan_bridges)
        self.assertEqual("MPADILETRTSETEDLLDLDLSIGVEEITAGPA",
                         prepeptide.leader)
        self.assertEqual("VTSWSLCTPGCTSPGGGSNCSFCC", prepeptide.core)
        self.assertEqual('Class I', prepeptide.peptide_subclass)
        self.assertEqual(['AviCys', 'Cl', 'OH'],
                         prepeptide.get_modifications())