<commit_before>""" Tests of common_schemy protein abundance queries

:Author: <NAME> <<EMAIL>>
:Date: 2017-09-19
:Copyright: 2017, Karr Lab
:License: MIT
"""

from kinetic_datanator.core import data_model
from kinetic_datanator.data_query import protein_abundance
from kinetic_datanator.core import models, flask_common_schema
import tempfile
import shutil
import unittest

class TestProteinAbundanceQuery(unittest.TestCase):

    @classmethod
    def setUpClass(self):
        self.cache_dirname = tempfile.mkdtemp()
        flk = flask_common_schema.FlaskCommonSchema(cache_dirname=self.cache_dirname)

        self.protein_P00323 = flk.session.query(models.ProteinSubunit).filter_by(uniprot_id = 'P00323').first()
        self.protein_Q42025 = flk.session.query(models.ProteinSubunit).filter_by(uniprot_id = 'Q42025').first()
        self.q = protein_abundance.ProteinAbundanceQuery(cache_dirname=self.cache_dirname)

    @classmethod
    def tearDownClass(self):
        shutil.rmtree(self.cache_dirname)

    def test_filter_observed_results(self):

        vals = self.q.get_observed_result(self.protein_P00323)

        for items in vals:
            self.assertEqual(items.units, 'PPM')
            self.assertEqual(items.observable.specie.sequence, self.protein_P00323.canonical_sequence)
            if items.observable.specie.cross_references[0].id == '882/882-Desulfo_Form_Exp_SC_zhang_2006.txt':
                self.assertEqual(items.value, 1003.0)



<commit_msg>more extensive tests for protein abundance<commit_after>""" Tests of common_schemy protein abundance queries

:Author: <NAME> <<EMAIL>>
:Date: 2017-09-19
:Copyright: 2017, Karr Lab
:License: MIT
"""

from kinetic_datanator.core import data_model
from kinetic_datanator.data_query import protein_abundance
from kinetic_datanator.core import models, flask_common_schema
import tempfile
import shutil
import unittest

class TestProteinAbundanceQuery(unittest.TestCase):

    @classmethod
    def setUpClass(self):
        self.cache_dirname = tempfile.mkdtemp()
        flk = flask_common_schema.FlaskCommonSchema(cache_dirname=self.cache_dirname)

        self.protein_P00323 = flk.session.query(models.ProteinSubunit).filter_by(uniprot_id = 'P00323').first()
        self.protein_Q42025 = flk.session.query(models.ProteinSubunit).filter_by(uniprot_id = 'Q42025').first()
        self.q = protein_abundance.ProteinAbundanceQuery(cache_dirname=self.cache_dirname)

    @classmethod
    def tearDownClass(self):
        shutil.rmtree(self.cache_dirname)

    def test_filter_observed_results(self):

        vals = self.q.get_observed_result(self.protein_P00323)
        self.assertEqual(set(items.value for items in vals), set([1003.0, 1100.0, 2323.0, 1336.0, 639.0]))
        self.assertEqual(set(items.units for items in vals), set(['PPM']))

        for items in vals:
            self.assertEqual(items.observable.specie.name, self.protein_P00323.subunit_name)
            self.assertEqual(items.observable.specie.uniprot_id, self.protein_P00323.uniprot_id)
            self.assertEqual(items.observable.specie.entrez_id, self.protein_P00323.entrez_id)
            self.assertEqual(items.observable.specie.gene_name, self.protein_P00323.gene_name)
            self.assertEqual(items.observable.specie.length, self.protein_P00323.length)
            self.assertEqual(items.observable.specie.mass, self.protein_P00323.mass)
            self.assertEqual(items.observable.specie.sequence, self.protein_P00323.canonical_sequence)
            if items.observable.specie.cross_references[0].id == '882/882-Desulfo_Form_Exp_SC_zhang_2006.txt':
                self.assertEqual(items.value, 1003.0)

        vals = self.q.get_observed_result(self.protein_Q42025)
        self.assertEqual(set(items.value for items in vals), set([240.0, 140.0, 358.0]))
        self.assertEqual(set(items.units for items in vals), set(['PPM']))

        for items in vals:
            self.assertEqual(items.observable.specie.name, self.protein_Q42025.subunit_name)
            self.assertEqual(items.observable.specie.uniprot_id, self.protein_Q42025.uniprot_id)
            self.assertEqual(items.observable.specie.entrez_id, self.protein_Q42025.entrez_id)
            self.assertEqual(items.observable.specie.gene_name, self.protein_Q42025.gene_name)
            self.assertEqual(items.observable.specie.length, self.protein_Q42025.length)
            self.assertEqual(items.observable.specie.mass, self.protein_Q42025.mass)
            self.assertEqual(items.observable.specie.sequence, self.protein_Q42025.canonical_sequence)
            if items.observable.specie.cross_references[0].id == '3702/3702-2.1ArabidopsisLeaf_waterDefict_SOW.txt':
                self.assertEqual(items.value, 140.0)


{'fraction_non_alphanumeric': 0.10183042289080581, 'fraction_numerical': 0.04986324426677888, 'mean_word_length': 3.946930280957336, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '121903', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1507, 'n_words': 220}