<commit_before>import unittest
from unittest import mock
from wqflask.api.mapping import initialize_parameters
from wqflask.api.mapping import do_mapping_for_api


class AttributeSetter:
    def __init__(self, obj):
        for key, value in obj.items():
            setattr(self, key, value)


class MockGroup(AttributeSetter):
    def get_marker(self):
        self.markers = []


class TestMapping(unittest.TestCase):

    def test_initialize_parameters(self):
        expected_results = {
            "format": "json",
            "limit_to": False,
            "mapping_method": "gemma",
            "maf": 0.01,
            "use_loco": True,
            "num_perm": 0,
            "perm_check": False,
            "genofile": False
        }

        results = initialize_parameters(
            start_vars={}, dataset={}, this_trait={})
        self.assertEqual(results, expected_results)

        start_vars = {
            "format": "F1",
            "limit_to": "1",
            "mapping_method": "rqtl",
            "control_marker": True,
            "pair_scan": "true",
            "interval_mapping": "true",
            "use_loco": "true",
            "num_perm": "14",
            "genofile": "BXD.8.geno"
        }

        results_2 = initialize_parameters(
            start_vars=start_vars, dataset={}, this_trait={})
        expected_results = {
            "format": "F1",
            "limit_to": 1,
            "mapping_method": "gemma",
            "maf": 0.01,
            "use_loco": True,
            "num_perm": 14,
            "perm_check": "ON",
            "genofile": "BXD.8.geno"
        }

        self.assertEqual(results_2, expected_results)

    @mock.patch("wqflask.api.mapping.rqtl_mapping.run_rqtl")
    @mock.patch("wqflask.api.mapping.gemma_mapping.run_gemma")
    @mock.patch("wqflask.api.mapping.initialize_parameters")
    @mock.patch("wqflask.api.mapping.retrieve_sample_data")
    @mock.patch("wqflask.api.mapping.create_trait")
    @mock.patch("wqflask.api.mapping.data_set.create_dataset")
    def test_do_mapping_for_api(self, mock_create_dataset, mock_trait, mock_retrieve_sample, mock_param, run_gemma, run_rqtl_geno):
        start_vars = {
            "db": "Temp",
            "trait_id": "dewf3232rff2",
            "format": "F1",
            "mapping_method": "gemma",
            "use_loco": True

        }
        sampleList = ["S1", "S2", "S3", "S4"]
        samplelist = ["S1", "S2", "S4"]
        dataset = AttributeSetter({"group": samplelist})
        this_trait = AttributeSetter({})
        trait_data = AttributeSetter({
            "data": {
                "item1": AttributeSetter({"name": "S1", "value": "S1_value"}),
                "item2": AttributeSetter({"name": "S2", "value": "S2_value"}),
                "item3": AttributeSetter({"name": "S3", "value": "S3_value"}),

            }<commit_msg>Add transform parameter to mapping api unit test<commit_after>import unittest
from unittest import mock
from wqflask.api.mapping import initialize_parameters
from wqflask.api.mapping import do_mapping_for_api


class AttributeSetter:
    def __init__(self, obj):
        for key, value in obj.items():
            setattr(self, key, value)


class MockGroup(AttributeSetter):
    def get_marker(self):
        self.markers = []


class TestMapping(unittest.TestCase):

    def test_initialize_parameters(self):
        expected_results = {
            "format": "json",
            "limit_to": False,
            "mapping_method": "gemma",
            "maf": 0.01,
            "use_loco": True,
            "num_perm": 0,
            "perm_check": False,
            "transform": False,
            "genofile": False
        }

        results = initialize_parameters(
            start_vars={}, dataset={}, this_trait={})
        self.assertEqual(results, expected_results)

        start_vars = {
            "format": "F1",
            "limit_to": "1",
            "mapping_method": "rqtl",
            "control_marker": True,
            "pair_scan": "true",
            "interval_mapping": "true",
            "use_loco": "true",
            "num_perm": "14",
            "transform": "qnorm",
            "genofile": "BXD.8.geno"
        }

        results_2 = initialize_parameters(
            start_vars=start_vars, dataset={}, this_trait={})
        expected_results = {
            "format": "F1",
            "limit_to": 1,
            "mapping_method": "gemma",
            "maf": 0.01,
            "use_loco": True,
            "num_perm": 14,
            "perm_check": "ON",
            "transform": "qnorm",
            "genofile": "BXD.8.geno"
        }

        self.assertEqual(results_2, expected_results)

    @mock.patch("wqflask.api.mapping.rqtl_mapping.run_rqtl")
    @mock.patch("wqflask.api.mapping.gemma_mapping.run_gemma")
    @mock.patch("wqflask.api.mapping.initialize_parameters")
    @mock.patch("wqflask.api.mapping.retrieve_sample_data")
    @mock.patch("wqflask.api.mapping.create_trait")
    @mock.patch("wqflask.api.mapping.data_set.create_dataset")
    def test_do_mapping_for_api(self, mock_create_dataset, mock_trait, mock_retrieve_sample, mock_param, run_gemma, run_rqtl_geno):
        start_vars = {
            "db": "Temp",
            "trait_id": "dewf3232rff2",
            "format": "F1",
            "mapping_method": "gemma",
            "use_loco": True

        }
        sampleList = ["S1", "S2", "S3", "S4"]
        samplelist = ["S1", "S2", "S4"]
        dataset = AttributeSetter({"group": samplelist})
        this_trait = AttributeSetter({})
        trait_data = AttributeSetter({
            "data": {
                "item1": AttributeSetter({"name": "S1", "value": "S1_value"}),
                "item2": AttributeSetter({"name": "S2", "value": "S2_value"}),
                "item3": AttributeSetter({"name": "S3", "value": "S3_value"}),

            }
{'fraction_non_alphanumeric': 0.1423475454391031, 'fraction_numerical': 0.013928996093086461, 'mean_word_length': 2.189599133261105, 'pattern_counts': {'":': 85, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5705966', 'n_tokens_mistral': 1901, 'n_tokens_neox': 1851, 'n_words': 333}