示例#1
0
    def _create_relation(self,
                         relation_type,
                         samples,
                         positions=[],
                         label=None):
        """Create group relation with the given samples and positions."""
        if not isinstance(samples, list):
            raise ValueError("`samples` argument must be list.")

        if not isinstance(positions, list):
            raise ValueError("`positions` argument must be list.")

        if positions:
            if len(samples) != len(positions):
                raise ValueError(
                    "`samples` and `positions` arguments must be of the same length."
                )

        relation_data = {
            'type': relation_type,
            'collection': self.id,
            'entities': []
        }

        for sample, position in zip_longest(samples, positions):
            entity_dict = {'entity': get_sample_id(sample)}
            if position:
                entity_dict['position'] = position

            relation_data['entities'].append(entity_dict)

        if label:
            relation_data['label'] = label

        return self.resolwe.relation.create(**relation_data)
示例#2
0
    def _create_relation(self,
                         relation_type,
                         category,
                         samples,
                         positions=[],
                         labels=[]):
        """Create relation."""
        if not isinstance(samples, list):
            raise ValueError("`samples` argument must be list.")

        if not isinstance(positions, list):
            raise ValueError("`positions` argument must be list.")

        if not isinstance(labels, list):
            raise ValueError("`labels` argument must be list.")

        if positions and labels and not len(samples) == len(positions) == len(
                labels):
            raise ValueError(
                "`samples`, `positions` and `labels` arguments must be of the same length."
            )
        elif labels and not len(samples) == len(labels):
            raise ValueError(
                "`samples` and `labels` arguments must be of the same length.")
        elif positions and not len(samples) == len(positions):
            raise ValueError(
                "`samples` and `positions` arguments must be of the same length."
            )

        relation_data = {
            'type': relation_type,
            'collection': self.id,
            'category': category,
            'partitions': []
        }

        for sample, position, label in zip_longest(samples, positions, labels):
            partition = {'entity': get_sample_id(sample)}
            if position:
                partition['position'] = position
            if label:
                partition['label'] = label

            relation_data['partitions'].append(partition)

        return self.resolwe.relation.create(**relation_data)
示例#3
0
    def _create_relation(
        self, relation_type, category, samples, positions=[], labels=[]
    ):
        """Create relation."""
        if not isinstance(samples, list):
            raise ValueError("`samples` argument must be list.")

        if not isinstance(positions, list):
            raise ValueError("`positions` argument must be list.")

        if not isinstance(labels, list):
            raise ValueError("`labels` argument must be list.")

        if positions and labels and not len(samples) == len(positions) == len(labels):
            raise ValueError(
                "`samples`, `positions` and `labels` arguments must be of the same length."
            )
        elif labels and not len(samples) == len(labels):
            raise ValueError(
                "`samples` and `labels` arguments must be of the same length."
            )
        elif positions and not len(samples) == len(positions):
            raise ValueError(
                "`samples` and `positions` arguments must be of the same length."
            )

        relation_data = {
            "type": relation_type,
            "collection": self.id,
            "category": category,
            "partitions": [],
        }

        for sample, position, label in zip_longest(samples, positions, labels):
            partition = {"entity": get_sample_id(sample)}
            if position:
                partition["position"] = position
            if label:
                partition["label"] = label

            relation_data["partitions"].append(partition)

        return self.resolwe.relation.create(**relation_data)
    def _create_relation(self, relation_type, category, samples, positions=[], labels=[]):
        """Create relation."""
        if not isinstance(samples, list):
            raise ValueError("`samples` argument must be list.")

        if not isinstance(positions, list):
            raise ValueError("`positions` argument must be list.")

        if not isinstance(labels, list):
            raise ValueError("`labels` argument must be list.")

        if positions and labels and not len(samples) == len(positions) == len(labels):
            raise ValueError(
                "`samples`, `positions` and `labels` arguments must be of the same length."
            )
        elif labels and not len(samples) == len(labels):
            raise ValueError("`samples` and `labels` arguments must be of the same length.")
        elif positions and not len(samples) == len(positions):
            raise ValueError("`samples` and `positions` arguments must be of the same length.")

        relation_data = {
            'type': relation_type,
            'collection': self.id,
            'category': category,
            'partitions': []
        }

        for sample, position, label in zip_longest(samples, positions, labels):
            partition = {'entity': get_sample_id(sample)}
            if position:
                partition['position'] = position
            if label:
                partition['label'] = label

            relation_data['partitions'].append(partition)

        return self.resolwe.relation.create(**relation_data)
示例#5
0
    def test_get_sample_id(self):
        sample = Sample(id=1, resolwe=MagicMock())
        sample.id = 1  # this is overriden when initialized
        self.assertEqual(get_sample_id(sample), 1)

        self.assertEqual(get_sample_id(2), 2)
示例#6
0
    def test_get_sample_id(self):
        sample = Sample(id=1, resolwe=MagicMock())
        sample.id = 1  # this is overriden when initialized
        self.assertEqual(get_sample_id(sample), 1)

        self.assertEqual(get_sample_id(2), 2)