예제 #1
0
def solver_with_input(inputs, use_fast_approximation_algorithm):
    goi, plasmid, mutations = inputs
    config = create_test_config(goi, plasmid, mutations,
                                use_fast_approximation_algorithm)
    start = time()
    solution = ssm_solve(config, NullPrimerGenerator(), AllPrimerGenerator())
    end = time()

    return stats_dataframe_for_solution(solution, end - start)
예제 #2
0
class SsmSolveTestSpecificConfigsRandom16(SsmSolveTestConfigRange):
    secondary_generator = AllPrimerGenerator()
    initialized = False
    percentage = 0.59
    num_of_tests = 0

    separate_temp_calc = True
    exclude_fl_prim = True
    primary_generator = Primer3(primer3_path=PRIMER3_PATH)
    use_fast_approximation = False
    hairpins = False
예제 #3
0
class SsmSolveTestSpecificConfigsRandom14(SsmSolveTestConfigRange):
    secondary_generator = AllPrimerGenerator()
    initialized = False
    percentage = 0.9
    num_of_tests = 10

    separate_temp_calc = True
    exclude_fl_prim = True
    primary_generator = NullPrimerGenerator()
    use_fast_approximation = True
    hairpins = False
예제 #4
0
from mutation_maker.ssm import ssm_solve
from mutation_maker.qclm import qclm_solve, QCLMInput, QCLMOutput
from mutation_maker.primer3_interoperability import Primer3, AllPrimerGenerator, NullPrimerGenerator
from mutation_maker.ssm_types import SSMInput, SSMOutput
from mutation_maker.pas import pas_solve
from mutation_maker.pas_types import PASInput

print("Mutation Maker version: 1.0.0")

PRIMER3_PATH = os.environ.get('PRIMER3HOME')
CELERY_BROKER_URL = os.environ.get('CELERY_BROKER_URL', 'redis://*****:*****@celery.task(name='tasks.ssm')
def ssm(ssm_input):
    data = parse_body(ssm_input)
    input = SSMInput(data)

    if input.config.use_primer3:
        main_generator = primer3
    else:
        main_generator = NullPrimerGenerator()

    return ssm_solve(input, main_generator, secondary_generator)

예제 #5
0
class SsmSolveTestConfigRange(unittest.TestCase):
    """
    Run tests with null generator as primary generator on random examples
    """
    percentage = 0.9
    primary_generator = Primer3(primer3_path=PRIMER3_PATH)
    secondary_generator = AllPrimerGenerator()
    use_fast_approximation = True
    exclude_fl_prim = False
    initialized = False
    hairpins = False
    separate_temp_calc = True
    num_of_tests = 1

    @classmethod
    def initialize(cls):

        max_muts = 24
        if not cls.initialized:
            # b_tmp = [True, False]
            # primary_generators = [Primer3(primer3_path=PRIMER3_PATH), NullPrimerGenerator()]
            # # all configurations
            # for use_fast_approximation in b_tmp:
            #     for exclude_fl_prim in b_tmp:
            #         for p_generator in primary_generators:
            random.seed(123)
            tst_start = 0
            tst_end = cls.num_of_tests
            cls.results = []
            for ind in range(tst_start, tst_end):
                print(f"\nRandom result NO. {ind+1} generated.\n")
                cls.results.append(
                    ssm_solve(
                        generate_random_SSM_input(
                            mut_cnt=random.randint(12, max_muts),
                            use_fast_approximation=cls.use_fast_approximation,
                            exclude_fl_prim=cls.exclude_fl_prim,
                            hairpins=cls.hairpins,
                            separate=cls.separate_temp_calc),
                        cls.primary_generator, cls.secondary_generator))
            cls.initialized = True

    def test_primer_size(self):
        self.__class__.initialize()
        cnt = 0
        for result in self.__class__.results:
            # test primer size
            if test_primer_size_in_range(result):
                cnt += 1
        self.assertGreaterEqual(
            cnt,
            len(self.__class__.results) * self.__class__.percentage,
            "Too many primers out of range")
        if len(self.__class__.results) > 0:
            print("%.2f of primers have size in range." %
                  (cnt / len(self.__class__.results) * 100))

    def test_3_end_size(self):
        self.__class__.initialize()
        cnt = 0
        for result in self.__class__.results:
            # test primer size
            if test_3end_size_in_range(result):
                cnt += 1
        self.assertGreaterEqual(
            cnt,
            len(self.__class__.results) * self.__class__.percentage,
            "Too many primers 3 end size out of range")
        if len(self.__class__.results) > 0:
            print("%.2f of primers have 3 end size in range." %
                  (cnt / len(self.__class__.results) * 100))

    def test_5_end_size(self):
        self.__class__.initialize()
        cnt = 0
        for result in self.__class__.results:
            # test primer size
            if test_5end_size_in_range(result):
                cnt += 1
        self.assertGreaterEqual(
            cnt,
            len(self.__class__.results) * self.__class__.percentage,
            "Too many primers 5 end size out of range")
        if len(self.__class__.results) > 0:
            print("%.2f of primers have 5 end size in range." %
                  (cnt / len(self.__class__.results) * 100))

    def test_overlap_size(self):
        self.__class__.initialize()
        cnt = 0
        for result in self.__class__.results:
            # test primer size
            if test_overlap_size_in_range(result):
                cnt += 1
        self.assertGreaterEqual(
            cnt,
            len(self.__class__.results) * self.__class__.percentage,
            "Too many primers overlap size is out of range!")
        if len(self.__class__.results) > 0:
            print("%.2f  of primers have overlap size in range." %
                  (cnt / len(self.__class__.results) * 100))

    def test_overlap_temp(self):
        self.__class__.initialize()
        cnt = 0
        for result in self.__class__.results:
            # test primer size
            if test_overlap_temperature_in_range(result):
                cnt += 1
        self.assertGreaterEqual(
            cnt, 0, "Too many primers overlap temperature is out of range!")
        if len(self.__class__.results) > 0:
            print("%.2f  of primers have overlap temp. in range." %
                  (cnt / len(self.__class__.results) * 100))

    def test_3_end_temp(self):
        self.__class__.initialize()
        cnt = 0
        for result in self.__class__.results:
            # test primer size
            if test_3end_temperature_in_range(result):
                cnt += 1
        self.assertGreaterEqual(
            cnt,
            len(self.__class__.results) * self.__class__.percentage,
            "Too many primers 3 end temperatures out of range")
        if len(self.__class__.results) > 0:
            print("%.2f  of primers have 3'end temp. in range." %
                  (cnt / len(self.__class__.results) * 100))

    def test_overlap_complementary(self):
        self.__class__.initialize()
        cnt = 0
        for result in self.__class__.results:
            # test primer size
            if test_overlap_complementary(result):
                cnt += 1
        self.assertGreaterEqual(
            cnt,
            len(self.__class__.results) * self.__class__.percentage,
            "Too many primers overlap size is incorrectly computed")
        if len(self.__class__.results) > 0:
            print("%.2f of primers are correctly complements to each other." %
                  (cnt / len(self.__class__.results) * 100))

    def test_mutation_position(self):
        self.__class__.initialize()
        cnt = 0
        for result in self.__class__.results:
            # test primer size
            if test_mutation_position(result):
                cnt += 1
        self.assertGreaterEqual(
            cnt,
            len(self.__class__.results) * self.__class__.percentage,
            "Too many primers mutation is not on expected location!")
        if len(self.__class__.results) > 0:
            print("%.2f of primers mutation at right spot." %
                  (cnt / len(self.__class__.results) * 100))
예제 #6
0
class SsmSolveTestOnPresetPrimer3(unittest.TestCase):
    initialized = False
    primary_generator = Primer3(primer3_path=PRIMER3_PATH)
    secondary_generator = AllPrimerGenerator()
    use_fast_approximation = True
    exclude_fl_prim = True

    @classmethod
    def initialize(cls):
        if not cls.initialized:
            tst_start = 0
            tst_end = 10
            cls.results = []
            for ind in range(tst_start, tst_end):
                print(f"\nPreset result NO. {ind+1} generated.\n")
                cls.results.append(
                    ssm_solve(
                        generate_SSM_input(
                            ind,
                            primer_growth=cls.use_fast_approximation,
                            separateTM=cls.exclude_fl_prim),
                        cls.primary_generator, cls.secondary_generator))
            cls.initialized = True

    def test_primer_size(self):
        self.__class__.initialize()
        for result in self.__class__.results:
            # test primer size
            self.assertTrue(test_primer_size_in_range(result),
                            msg="Primer size is out of range!")

    def test_3_end_size(self):
        self.__class__.initialize()
        for result in self.__class__.results:
            self.assertTrue(test_3end_size_in_range(result),
                            msg="Primers 3'end size is out of range!")

    def test_overlap_size(self):
        self.__class__.initialize()
        for result in self.__class__.results:
            # test overlap size
            self.assertTrue(test_overlap_size_in_range(result),
                            msg="Overlap size is out of range!")

    def test_overlap_temp(self):
        self.__class__.initialize()
        for result in self.__class__.results:
            # test overlap temperature in range
            self.assertTrue(test_overlap_temperature_in_range(result),
                            msg="Overlap temperature is out of range!")

    def test_3_end_temp(self):
        self.__class__.initialize()
        for result in self.__class__.results:
            # test 3'end temperature of primers
            self.assertTrue(test_3end_temperature_in_range(result),
                            msg="Primer 3'end temperature is out of range!")

    def test_overlap_complementary(self):
        self.__class__.initialize()
        for result in self.__class__.results:
            # test overlap complementary
            self.assertTrue(test_overlap_complementary(result),
                            msg="Overlap size is incorrectly computed!")

    def test_mutation_position(self):
        self.__class__.initialize()
        for result in self.__class__.results:
            # test mutation position
            self.assertTrue(test_mutation_position(result),
                            msg="Mutation is not on expected location!")

    def test_min_5_end_size(self):
        self.__class__.initialize()
        for result in self.__class__.results:
            # test mutation position
            self.assertTrue(test_5end_size_in_range(result),
                            msg="Primers do not have sufficient 5 end size!")