Exemple #1
0
 def test_run_taxa_tree_sample(self):  # pylint: disable=invalid-name
     """Ensure TaxaTree run_sample produces correct results."""
     kwargs = {
         KrakenResultModule.name(): create_kraken(),
         KrakenHLLResultModule.name(): create_krakenhll(),
         Metaphlan2ResultModule.name(): create_metaphlan2(),
     }
     self.generic_run_sample_test(kwargs, TaxaTreeDisplayModule)
Exemple #2
0
 def create_sample(i):
     """Create unique sample for index i."""
     return Sample(
         **{
             'name': f'Sample{i}',
             'metadata': {
                 'foobar': f'baz{i}'
             },
             KrakenResultModule.name(): create_kraken(),
             KrakenHLLResultModule.name(): create_krakenhll(),
             Metaphlan2ResultModule.name(): create_metaphlan2(),
         }).save()
def trees_from_sample(sample):
    """Build taxa trees for a given sample."""
    metaphlan2 = sample[Metaphlan2ResultModule.name()]
    metaphlan2 = reduce_taxa_list(metaphlan2['taxa'])
    kraken = sample[KrakenResultModule.name()]
    kraken = reduce_taxa_list(kraken['taxa'])
    krakenhll = sample[KrakenHLLResultModule.name()]
    krakenhll = reduce_taxa_list(krakenhll['taxa'])
    return {
        'kraken': kraken,
        'metaphlan2': metaphlan2,
        'krakenhll': krakenhll,
    }
Exemple #4
0
    def run_sample_group(cls, sample_group, samples):
        """Gather samples and process."""
        reducer = sample_similarity_reducer.s(samples)
        persist_task = persist_result.s(sample_group.analysis_result_uuid)

        categories_task = categories_from_metadata.s(samples)
        kraken_task = taxa_tool_tsne.s(samples, KrakenResultModule.name())
        krakenhll_task = taxa_tool_tsne.s(samples,
                                          KrakenHLLResultModule.name())
        metaphlan2_task = taxa_tool_tsne.s(samples,
                                           Metaphlan2ResultModule.name())
        middle_tasks = [
            categories_task, kraken_task, krakenhll_task, metaphlan2_task
        ]

        return chord(middle_tasks)(reducer | persist_task)
def make_all_flows(samples):
    """Determine flows by tool."""
    flow_tbl = {}
    tool_names = [
        Metaphlan2ResultModule.name(),
        KrakenResultModule.name(),
        KrakenHLLResultModule.name(),
    ]
    for tool_name in tool_names:
        taxa_tbl = make_taxa_table(samples, tool_name)
        save_tool_name = 'kraken'
        if 'metaphlan2' in tool_name:
            save_tool_name = 'metaphlan2'
        elif 'krakenhll' in tool_name:
            save_tool_name = 'krakenhll'

        flow_tbl[save_tool_name] = make_flow(taxa_tbl)

    return {'by_tool': flow_tbl}
def sample_similarity_reducer(args, samples):
    """Combine Sample Similarity components."""
    categories = args[0]
    kraken_tool, kraken_labeled = args[1]
    krakenhll_tool, krakenhll_labeled = args[2]
    metaphlan_tool, metaphlan_labeled = args[3]

    data_records = update_data_records(samples, categories, kraken_labeled,
                                       krakenhll_labeled, metaphlan_labeled)

    tools = {
        KrakenResultModule.name(): kraken_tool,
        KrakenHLLResultModule.name(): krakenhll_tool,
        Metaphlan2ResultModule.name(): metaphlan_tool,
    }

    result_data = {
        'categories': categories,
        'tools': tools,
        'data_records': data_records,
    }
    return result_data
Exemple #7
0
from app import db
from app.display_modules.sample_similarity import SampleSimilarityDisplayModule
from app.display_modules.sample_similarity.wrangler import SampleSimilarityWrangler
from app.samples.sample_models import Sample
from app.tool_results.kraken import KrakenResultModule
from app.tool_results.kraken.tests.factory import create_kraken
from app.tool_results.krakenhll import KrakenHLLResultModule
from app.tool_results.krakenhll.tests.factory import create_krakenhll
from app.tool_results.metaphlan2 import Metaphlan2ResultModule
from app.tool_results.metaphlan2.tests.factory import create_metaphlan2

from tests.base import BaseTestCase
from tests.utils import add_sample_group

KRAKEN_NAME = KrakenResultModule.name()
KRAKENHLL_NAME = KrakenHLLResultModule.name()
METAPHLAN2_NAME = Metaphlan2ResultModule.name()


class TestSampleSimilarityWrangler(BaseTestCase):
    """Test suite for Sample Similarity Wrangler."""
    def test_run_sample_group(self):
        """Ensure run_sample_group produces correct results."""
        def create_sample(i):
            """Create unique sample for index i."""
            metadata = {'foobar': f'baz{i}'}
            sample_data = {
                'name': f'Sample{i}',
                'metadata': metadata,
                KRAKEN_NAME: create_kraken(),
                KRAKENHLL_NAME: create_krakenhll(),