Esempio n. 1
0
def create_abrf_analysis_result(save=False):
    """Generate ABRF analysis result."""
    sample_similarity = AnalysisResultWrapper(
        status='S', data=load_sample_similarity()).save()
    ags = AnalysisResultWrapper(status='S', data=load_ags()).save()
    analysis_result = AnalysisResultMeta(sample_similarity=sample_similarity,
                                         average_genome_size=ags)
    if save:
        analysis_result.save()
    return analysis_result
 def test_add_ags(self):
     """Ensure Average Genome Size model is created correctly."""
     ags = AGSResult(categories=CATEGORIES, distributions=DISTRIBUTIONS)
     wrapper = AnalysisResultWrapper(data=ags).save()
     result = AnalysisResultMeta(average_genome_size=wrapper).save()
     self.assertTrue(result.id)
     self.assertTrue(result.average_genome_size)
 def test_add_missing_category(self):
     """Ensure saving model fails if category is missing from `data`."""
     hmp = HMPResult(categories=fake_categories(),
                     sites=fake_sites(),
                     data={})
     wrapper = AnalysisResultWrapper(data=hmp)
     self.assertRaises(ValidationError, wrapper.save)
 def test_add_sample_similarity(self):
     """Ensure Sample Similarity model is created correctly."""
     sample_similarity_result = SampleSimilarityResult(
         categories=CATEGORIES, tools=TOOLS, data_records=DATA_RECORDS)
     wrapper = AnalysisResultWrapper(data=sample_similarity_result).save()
     result = AnalysisResultMeta(sample_similarity=wrapper).save()
     self.assertTrue(result.id)
     self.assertTrue(result.sample_similarity)
 def test_result_types(self):
     """Ensure sample group model is created correctly."""
     ags_result = AnalysisResultWrapper(status='S',
                                        data=AGSFactory()).save()
     analysis_result = AnalysisResultMeta()
     setattr(analysis_result, MODULE_NAME, ags_result)
     analysis_result.save()
     self.assertEqual(len(analysis_result.result_types), 1)
     self.assertIn(MODULE_NAME, analysis_result.result_types)
 def test_add_missing_category(self):
     """Ensure saving model fails if sample similarity record is missing category."""
     categories = {
         'city': ['Montevideo', 'Sacramento'],
     }
     data_records = [{
         'SampleID': 'MetaSUB_Pilot__01_cZ__unknown__seq1end',
     }]
     sample_similarity_result = SampleSimilarityResult(
         categories=categories, tools={}, data_records=data_records)
     wrapper = AnalysisResultWrapper(data=sample_similarity_result)
     self.assertRaises(ValidationError, wrapper.save)
Esempio n. 7
0
 def test_add_taxon_abundance(self):
     """Ensure Taxon Abundance model is created correctly."""
     taxon_abundance = TaxonAbundanceResult(
         **
         {'by_tool': {
             'kraken': flow_model(),
             'metaphlan2': flow_model()
         }})
     wrapper = AnalysisResultWrapper(data=taxon_abundance).save()
     result = AnalysisResultMeta(taxon_abundance=wrapper).save()
     self.assertTrue(result.id)
     self.assertTrue(result.taxon_abundance)
    def test_persist_result_helper(self):
        """Ensure persist_result_helper works as intended."""
        wrapper = AnalysisResultWrapper().save()
        analysis_result = AnalysisResultMeta(sample_similarity=wrapper).save()
        sample_similarity = create_mvp_sample_similarity()

        persist_result_helper(sample_similarity, analysis_result.uuid,
                              'sample_similarity')
        analysis_result.reload()
        self.assertIn('sample_similarity', analysis_result)
        wrapper = getattr(analysis_result, 'sample_similarity').fetch()
        self.assertIn('status', wrapper)
        self.assertEqual('S', wrapper.status)
 def test_add_unordered_distribution(self):
     """Ensure saving model fails if distribution record is unordered."""
     unordered_distributions = DISTRIBUTIONS.copy()
     bad_distribution = DistributionResult(min_val=4,
                                           q1_val=1,
                                           mean_val=2,
                                           q3_val=3,
                                           max_val=0)
     unordered_distributions['foo']['bar'] = bad_distribution
     ags = AGSResult(categories=CATEGORIES,
                     distributions=unordered_distributions)
     wrapper = AnalysisResultWrapper(data=ags)
     self.assertRaises(ValidationError, wrapper.save)
Esempio n. 10
0
 def test_get_pending_average_genome_size(self):  # pylint: disable=invalid-name
     """Ensure getting a pending AGS behaves correctly."""
     average_genome_size = AGSFactory()
     wrapper = AnalysisResultWrapper(data=average_genome_size).save()
     analysis_result = AnalysisResultMeta(
         average_genome_size=wrapper).save()
     with self.client:
         response = self.client.get(
             f'/api/v1/analysis_results/{analysis_result.uuid}/average_genome_size',
             content_type='application/json',
         )
         data = json.loads(response.data.decode())
         self.assertEqual(response.status_code, 200)
         self.assertIn('success', data['status'])
         self.assertEqual(data['data']['status'], 'P')
Esempio n. 11
0
 def generic_getter_test(self, data, endpt, verify_fields=('samples',)):
     """Check that we can get an analysis result."""
     wrapper = AnalysisResultWrapper(data=data, status='S').save()
     analysis_result = AnalysisResultMeta(**{endpt: wrapper}).save()
     with self.client:
         response = self.client.get(
             f'/api/v1/analysis_results/{analysis_result.uuid}/{endpt}',
             content_type='application/json',
         )
         data = json.loads(response.data.decode())
         self.assertEqual(response.status_code, 200)
         self.assertIn('success', data['status'])
         analysis_result = data['data']
         self.assertEqual(analysis_result['status'], 'S')
         for field in verify_fields:
             self.assertIn(field, analysis_result['data'])
    def test_add_malformed_tool(self):
        """Ensure saving model fails if sample similarity tool is malformed."""
        tools = {
            'metaphlan2': {
                'x_label': 'metaphlan2 tsne x',
            }
        }

        data_records = [{
            'SampleID': 'MetaSUB_Pilot__01_cZ__unknown__seq1end',
            'metaphlan2_x': 0.15631940943278633,
        }]

        sample_similarity_result = SampleSimilarityResult(
            categories={}, tools=tools, data_records=data_records)
        wrapper = AnalysisResultWrapper(data=sample_similarity_result)
        self.assertRaises(ValidationError, wrapper.save)
Esempio n. 13
0
 def test_get_ags(self):
     """Ensure getting a single AGS result works correctly."""
     average_genome_size = AGSFactory()
     wrapper = AnalysisResultWrapper(data=average_genome_size,
                                     status='S').save()
     analysis_result = AnalysisResultMeta(
         average_genome_size=wrapper).save()
     with self.client:
         response = self.client.get(
             f'/api/v1/analysis_results/{analysis_result.id}/average_genome_size',
             content_type='application/json',
         )
         self.assertEqual(response.status_code, 200)
         data = json.loads(response.data.decode())
         self.assertIn('success', data['status'])
         self.assertEqual(data['data']['status'], 'S')
         self.assertIn('data', data['data'])
         ags_result = data['data']['data']
         self.assertIn('categories', ags_result)
         self.assertIn('distributions', ags_result)
         self.assertTrue(len(ags_result['distributions']) > 0)
Esempio n. 14
0
# pylint: disable=invalid-name

"""MetaGenScope seed data from ARBF 2017."""

from app.analysis_results.analysis_result_models import AnalysisResultMeta, AnalysisResultWrapper

from .loader import (
    load_sample_similarity,
    load_taxon_abundance,
    load_reads_classified,
    load_hmp,
    load_ags,
)


sample_similarity = AnalysisResultWrapper(status='S', data=load_sample_similarity()).save()
taxon_abundance = AnalysisResultWrapper(status='S', data=load_taxon_abundance()).save()
hmp = AnalysisResultWrapper(status='S', data=load_hmp()).save()
ags = AnalysisResultWrapper(status='S', data=load_ags()).save()

abrf_analysis_result = AnalysisResultMeta(sample_similarity=sample_similarity,
                                          taxon_abundance=taxon_abundance,
                                          hmp=hmp,
                                          average_genome_size=ags)
Esempio n. 15
0
# pylint: disable=invalid-name
"""MetaGenScope seed data from UW Madison Project."""

from app.analysis_results.analysis_result_models import AnalysisResultMeta, AnalysisResultWrapper

from .loader import load_reads_classified

reads_classified = AnalysisResultWrapper(status='S',
                                         data=load_reads_classified()).save()

uw_analysis_result = AnalysisResultMeta(reads_classified=reads_classified)
Esempio n. 16
0
 def generic_adder_test(self, data, endpt):
     """Check that we can add an analysis result."""
     wrapper = AnalysisResultWrapper(data=data).save()
     result = AnalysisResultMeta(**{endpt: wrapper}).save()
     self.assertTrue(result.uuid)
     self.assertTrue(getattr(result, endpt))
Esempio n. 17
0
def wrap_result(result):
    """Wrap display result in status wrapper."""
    return AnalysisResultWrapper(status='S', data=result).save()