Ejemplo n.º 1
0
class FoodPetResult(ToolResult):        # pylint: disable=too-few-public-methods
    """Food/Pet tool's result type."""

    # DictFields are of the form: {<sample_id>: <sample_value>}
    vegetables = mongoDB.DictField(default={})
    fruits = mongoDB.DictField(default={})
    pets = mongoDB.DictField(default={})
    meats = mongoDB.DictField(default={})

    total_reads = mongoDB.IntField()
Ejemplo n.º 2
0
class SampleSimilarityResult(mdb.EmbeddedDocument):     # pylint: disable=too-few-public-methods
    """Sample Similarity document type."""

    # Categories dict is of the form: {<category_name>: [<category_value>, ...]}
    categories = mdb.MapField(field=StringList, required=True)
    # Tools dict is of the form: {<tool_name>: <ToolDocument>}
    tools = mdb.MapField(field=EmbeddedDoc(ToolDocument), required=True)
    data_records = mdb.ListField(mdb.DictField(), required=True)

    def clean(self):
        """Ensure that `data_records` contain valid records."""
        category_names = self.categories.keys()
        tool_names = self.tools.keys()

        for record in self.data_records:
            for category_name in category_names:
                if category_name not in record:
                    msg = 'Record must have all categories.'
                    raise ValidationError(msg)
            for tool_name in tool_names:
                xname = '{}_x'.format(tool_name)
                yname = '{}_y'.format(tool_name)
                if (xname not in record) or (yname not in record):
                    msg = 'Record must x and y for all tools.'
                    raise ValidationError(msg)
Ejemplo n.º 3
0
class BetaDiversityToolResult(GroupToolResult):  # pylint: disable=too-few-public-methods
    """Beta Diversity result type."""

    # Accept any JSON
    # Data: {<genus>: {<metric>: {<tool>: {<sample_name>: {<sample_name>: <value>}}}}}
    data = mongoDB.DictField(required=True)

    def clean(self):
        """Ensure data blob meets minimum requirements."""
        ranks = self.data
        for metric in ranks.values():
            for tool in metric.values():
                for entry in tool.values():
                    validate_entry(entry)
class BaseSample(Document):
    """Sample model."""

    uuid = mongoDB.UUIDField(required=True,
                             primary_key=True,
                             binary=False,
                             default=uuid4)
    name = mongoDB.StringField(unique=True)
    metadata = mongoDB.DictField(default={})
    analysis_result = mongoDB.LazyReferenceField(AnalysisResultMeta)
    theme = mongoDB.StringField(default='')
    created_at = mongoDB.DateTimeField(default=datetime.datetime.utcnow)

    meta = {'allow_inheritance': True}

    @property
    def tool_result_names(self):
        """Return a list of all tool results present for this Sample."""
        all_fields = [mod.name() for mod in all_tool_results]
        return [
            field for field in all_fields
            if getattr(self, field, None) is not None
        ]

    def fetch_safe(self, tools=None):
        """Return the sample with all tool result documents fetched and jsonified."""
        if not tools:
            tools = self.tool_result_names
        safe_sample = {
            tool: jsonify(getattr(self, tool).fetch())
            for tool in tools
        }
        safe_sample['name'] = self.name
        safe_sample['metadata'] = self.metadata
        safe_sample['theme'] = self.theme
        if self.analysis_result:
            safe_sample['analysis_result'] = str(self.analysis_result.pk)
        return safe_sample
Ejemplo n.º 5
0
class BetaDiversityResult(mdb.EmbeddedDocument):
    """Set of beta diversity results."""

    data = mdb.DictField(required=True)
Ejemplo n.º 6
0
class MicrobeDirectoryResult(mdb.EmbeddedDocument):  # pylint: disable=too-few-public-methods
    """Set of microbe directory results."""

    samples = mdb.DictField(required=True)