def test_type(self):
        no_integrase = Integron("foo")
        self.assertIsNone(no_integrase.type())

        just_one_integrase = Integron("just_one_integrase")
        just_one_integrase.add_integrase(10,
                                         100,
                                         'foo',
                                         1,
                                         1e-2,
                                         "intersection_tyr_intI")
        self.assertEqual(just_one_integrase.type(), "In0")

        just_one_attC = Integron("just_one_attC")
        just_one_attC.add_attC(10,
                               100,
                               1,
                               1e-2,
                               "intersection_tyr_intI")
        self.assertEqual(just_one_attC.type(), "attC0")

        one_integrase_one_attC = Integron("one_integrase_one_attC")
        one_integrase_one_attC.add_integrase(10,
                                             100,
                                             'foo',
                                             1,
                                             1e-2,
                                             "intersection_tyr_intI")
        one_integrase_one_attC.add_attC(10,
                                        100,
                                        1,
                                        1e-2,
                                        "intersection_tyr_intI")
        self.assertEqual(one_integrase_one_attC.type(), "complete")
    def test_has_attC(self):
        integron = Integron("foo")
        self.assertFalse(integron.has_attC())

        just_one_attC = Integron("just_one_attC")
        just_one_attC.add_attC(10, 100, 1, 1e-2, "intersection_tyr_intI")
        self.assertTrue(just_one_attC.has_attC())
    def test_has_attC(self):
        integron = Integron("foo")
        self.assertFalse(integron.has_attC())

        just_one_attC = Integron("just_one_attC")
        just_one_attC.add_attC(10, 100, 1, 1e-2, "intersection_tyr_intI")
        self.assertTrue(just_one_attC.has_attC())
    def test_add_attc(self):
        id_replicon = "acba.007.p01.13"

        data_attc_1 = {
            "pos_beg": 10,
            "pos_end": 100,
            "strand": -1,
            "evalue": 1.1e-07,
            "type_elt": "attC",
            "annotation": "attC",
            "model": "attc_4",
            "distance_2attC": np.nan
        }

        attc_1 = pd.DataFrame(data_attc_1,
                              columns=self.columns,
                              index=['attc_001'])
        attc_1 = attc_1.astype(dtype=self.dtype)

        integron = Integron(id_replicon)
        integron.add_attC(attc_1.loc['attc_001', 'pos_beg'],
                          attc_1.loc['attc_001',
                                     'pos_end'], attc_1.loc['attc_001',
                                                            'strand'],
                          attc_1.loc['attc_001',
                                     'evalue'], attc_1.loc['attc_001',
                                                           'model'])

        pdt.assert_frame_equal(attc_1, integron.attC)

        integron_finder.SIZE_REPLICON = 3

        attc_2 = pd.DataFrame(data_attc_1,
                              columns=self.columns,
                              index=['attc_002'])
        attc_2 = attc_2.astype(dtype=self.dtype)
        attc_2['pos_beg'] = attc_2['pos_beg'] + 100
        attc_2['pos_end'] = attc_2['pos_end'] + 100
        attc_2["distance_2attC"] = (attc_2.loc['attc_002', 'pos_beg'] - attc_1.loc['attc_001', 'pos_end']) % \
                                   integron_finder.SIZE_REPLICON
        attc = attc_1.append(attc_2)

        integron.add_attC(attc_2.loc['attc_002', 'pos_beg'],
                          attc_2.loc['attc_002',
                                     'pos_end'], attc_2.loc['attc_002',
                                                            'strand'],
                          attc_2.loc['attc_002',
                                     'evalue'], attc_2.loc['attc_002',
                                                           'model'])
        pdt.assert_frame_equal(attc, integron.attC)
    def test_type(self):
        no_integrase = Integron("foo")
        self.assertIsNone(no_integrase.type())

        just_one_integrase = Integron("just_one_integrase")
        just_one_integrase.add_integrase(10, 100, "foo", 1, 1e-2, "intersection_tyr_intI")
        self.assertEqual(just_one_integrase.type(), "In0")

        just_one_attC = Integron("just_one_attC")
        just_one_attC.add_attC(10, 100, 1, 1e-2, "intersection_tyr_intI")
        self.assertEqual(just_one_attC.type(), "attC0")

        one_integrase_one_attC = Integron("one_integrase_one_attC")
        one_integrase_one_attC.add_integrase(10, 100, "foo", 1, 1e-2, "intersection_tyr_intI")
        one_integrase_one_attC.add_attC(10, 100, 1, 1e-2, "intersection_tyr_intI")
        self.assertEqual(one_integrase_one_attC.type(), "complete")
    def test_add_attc(self):
        id_replicon = "acba.007.p01.13"
        data_attc = {"pos_beg" : 10,
                          "pos_end" : 100,
                          "strand" : -1,
                          "evalue" : 1.1e-07,
                          "type_elt" : "attC",
                          "annotation" : "attC",
                          "model" : "attc_4"}

        df = pd.DataFrame(columns=["pos_beg", "pos_end", "strand", "evalue", "type_elt",
                                   "model", "distance_2attC", "annotation"])
        tmp_df = pd.DataFrame()
        tmp_df["pos_beg"] = [data_attc["pos_beg"]]
        tmp_df["pos_end"] = [data_attc["pos_end"]]
        tmp_df["strand"] = [data_attc["strand"]]
        tmp_df["evalue"] = [data_attc["evalue"]]
        tmp_df["type_elt"] = "attC"
        tmp_df["annotation"] = "attC"
        tmp_df["model"] = [data_attc["model"]]

        df = df.append(tmp_df, ignore_index=True)
        sizes_cassettes = [np.nan]
        df["distance_2attC"] = sizes_cassettes
        df.index = ["attc_%03i" % int(j + 1) for j in df.index]

        integron = Integron(id_replicon)
        integron.add_attC(data_attc["pos_beg"],
                          data_attc["pos_end"],
                          data_attc["strand"],
                          data_attc["evalue"],
                          data_attc["model"])

        self.assert_frame_equal(df, integron.attC, check_dtype=False)
        self.assertListEqual(sizes_cassettes, integron.sizes_cassettes)

        integron_finder.SIZE_REPLICON = 3

        tmp_df2 = pd.DataFrame()
        tmp_df2["pos_beg"] = [data_attc["pos_beg"] + 100]
        tmp_df2["pos_end"] = [data_attc["pos_end"] + 100]
        tmp_df2["strand"] = [data_attc["strand"]]
        tmp_df2["evalue"] = [data_attc["evalue"]]
        tmp_df2["type_elt"] = "attC"
        tmp_df2["annotation"] = "attC"
        tmp_df2["model"] = [data_attc["model"]]
        sizes_cassettes.append((
                                (data_attc["pos_beg"] + 100) -
                                (data_attc["pos_end"])) %
                                integron_finder.SIZE_REPLICON)

        df = df.append(tmp_df2, ignore_index=True)
        df["distance_2attC"] = sizes_cassettes
        df.index = ["attc_%03i" % int(j + 1) for j in df.index]
        integron.add_attC(data_attc["pos_beg"] + 100,
                          data_attc["pos_end"] + 100,
                          data_attc["strand"],
                          data_attc["evalue"],
                          data_attc["model"])

        self.assert_frame_equal(df, integron.attC, check_dtype=False)
        self.assertListEqual(sizes_cassettes, integron.sizes_cassettes)
    def test_add_attc(self):
        id_replicon = "acba.007.p01.13"
        data_attc = {
            "pos_beg": 10,
            "pos_end": 100,
            "strand": -1,
            "evalue": 1.1e-07,
            "type_elt": "attC",
            "annotation": "attC",
            "model": "attc_4",
        }

        df = pd.DataFrame(
            columns=["pos_beg", "pos_end", "strand", "evalue", "type_elt", "model", "distance_2attC", "annotation"]
        )
        tmp_df = pd.DataFrame()
        tmp_df["pos_beg"] = [data_attc["pos_beg"]]
        tmp_df["pos_end"] = [data_attc["pos_end"]]
        tmp_df["strand"] = [data_attc["strand"]]
        tmp_df["evalue"] = [data_attc["evalue"]]
        tmp_df["type_elt"] = "attC"
        tmp_df["annotation"] = "attC"
        tmp_df["model"] = [data_attc["model"]]

        df = df.append(tmp_df, ignore_index=True)
        sizes_cassettes = [np.nan]
        df["distance_2attC"] = sizes_cassettes
        df.index = ["attc_%03i" % int(j + 1) for j in df.index]

        integron = Integron(id_replicon)
        integron.add_attC(
            data_attc["pos_beg"], data_attc["pos_end"], data_attc["strand"], data_attc["evalue"], data_attc["model"]
        )

        self.assert_frame_equal(df, integron.attC, check_dtype=False)
        self.assertListEqual(sizes_cassettes, integron.sizes_cassettes)

        integron_finder.SIZE_REPLICON = 3

        tmp_df2 = pd.DataFrame()
        tmp_df2["pos_beg"] = [data_attc["pos_beg"] + 100]
        tmp_df2["pos_end"] = [data_attc["pos_end"] + 100]
        tmp_df2["strand"] = [data_attc["strand"]]
        tmp_df2["evalue"] = [data_attc["evalue"]]
        tmp_df2["type_elt"] = "attC"
        tmp_df2["annotation"] = "attC"
        tmp_df2["model"] = [data_attc["model"]]
        sizes_cassettes.append(((data_attc["pos_beg"] + 100) - (data_attc["pos_end"])) % integron_finder.SIZE_REPLICON)

        df = df.append(tmp_df2, ignore_index=True)
        df["distance_2attC"] = sizes_cassettes
        df.index = ["attc_%03i" % int(j + 1) for j in df.index]
        integron.add_attC(
            data_attc["pos_beg"] + 100,
            data_attc["pos_end"] + 100,
            data_attc["strand"],
            data_attc["evalue"],
            data_attc["model"],
        )

        self.assert_frame_equal(df, integron.attC, check_dtype=False)
        self.assertListEqual(sizes_cassettes, integron.sizes_cassettes)