def test_get_samples(self):
        collection = Collection(id=1, resolwe=MagicMock())
        collection._samples = ['sample_1', 'sample_2']
        self.assertEqual(get_samples(collection), ['sample_1', 'sample_2'])

        collection_1 = Collection(id=1, resolwe=MagicMock())
        collection_1._samples = ['sample_1']
        collection_2 = Collection(id=2, resolwe=MagicMock())
        collection_2._samples = ['sample_2']
        self.assertEqual(get_samples([collection_1, collection_2]),
                         ['sample_1', 'sample_2'])

        data = Data(id=1, resolwe=MagicMock())
        data._sample = 'sample_1'
        self.assertEqual(get_samples(data), ['sample_1'])

        data1 = Data(id=1, resolwe=MagicMock())
        data1._sample = 'sample1'
        data2 = Data(id=2, resolwe=MagicMock())
        data2._sample = 'sample2'
        self.assertEqual(get_samples([data1, data2]), ['sample1', 'sample2'])

        data = Data(id=1,
                    resolwe=MagicMock(**{'sample.filter.return_value': None}))
        data._sample = None
        with self.assertRaises(TypeError):
            get_samples(data)

        sample = Sample(id=1, resolwe=MagicMock())
        self.assertEqual(get_samples(sample), [sample])

        sample_1 = Sample(id=1, resolwe=MagicMock())
        sample_2 = Sample(id=3, resolwe=MagicMock())
        self.assertEqual(get_samples([sample_1, sample_2]),
                         [sample_1, sample_2])
    def test_dehydrate_resources(self):
        # `Collection` is used because it is easier to use
        collection = Collection(id=100, resolwe=MagicMock())
        obj_1 = Collection(id=1, resolwe=MagicMock())
        obj_1.id = 1  # this is overriden when initialized

        self.assertEqual(collection._dehydrate_resources(obj_1), 1)
        self.assertEqual(collection._dehydrate_resources([obj_1]), [1])
        self.assertEqual(collection._dehydrate_resources({'key': obj_1}), {'key': 1})
        self.assertEqual(collection._dehydrate_resources({'key': [obj_1]}), {'key': [1]})
Exemple #3
0
    def test_get_samples(self):
        collection = Collection(id=1, resolwe=MagicMock())
        collection._samples = ['sample_1', 'sample_2']
        self.assertEqual(get_samples(collection), ['sample_1', 'sample_2'])

        collection_1 = Collection(id=1, resolwe=MagicMock())
        collection_1._samples = ['sample_1']
        collection_2 = Collection(id=2, resolwe=MagicMock())
        collection_2._samples = ['sample_2']
        self.assertEqual(get_samples([collection_1, collection_2]),
                         ['sample_1', 'sample_2'])

        sample = Sample(id=1, resolwe=MagicMock())
        self.assertEqual(get_samples(sample), [sample])

        sample_1 = Sample(id=1, resolwe=MagicMock())
        sample_2 = Sample(id=3, resolwe=MagicMock())
        self.assertEqual(get_samples([sample_1, sample_2]),
                         [sample_1, sample_2])
    def test_get_resource_collection(self):
        collection = Collection(id=1, resolwe=MagicMock())
        collection.id = 1  # this is overriden when initialized
        self.assertEqual(get_resource_collection(collection), 1)

        relation = Relation(id=1, resolwe=MagicMock())
        relation._hydrated_collection = Collection(id=2, resolwe=MagicMock())
        relation._hydrated_collection.id = 2  # this is overriden when initialized
        self.assertEqual(get_resource_collection(relation), 2)

        data = Data(id=1, resolwe=MagicMock())
        data._collections = [Collection(id=3, resolwe=MagicMock())]
        data._collections[0].id = 3  # this is overriden when initialized
        self.assertEqual(get_resource_collection(data), 3)

        sample = Sample(id=1, resolwe=MagicMock())
        sample._collections = [Collection(id=4, resolwe=MagicMock())]
        sample._collections[0].id = 4  # this is overriden when initialized
        self.assertEqual(get_resource_collection(sample), 4)

        sample = Sample(id=1, resolwe=MagicMock())
        sample._collections = [
            Collection(id=5, resolwe=MagicMock()),
            Collection(id=6, resolwe=MagicMock())
        ]
        sample._collections[0].id = 5  # this is overriden when initialized
        sample._collections[1].id = 6  # this is overriden when initialized
        self.assertEqual(get_resource_collection(sample), None)
        with self.assertRaises(LookupError):
            get_resource_collection(sample, fail_silently=False)
Exemple #5
0
    def test_get_samples(self):
        collection = Collection(id=1, resolwe=MagicMock())
        collection._samples = ['sample_1', 'sample_2']
        self.assertEqual(get_samples(collection), ['sample_1', 'sample_2'])

        collection_1 = Collection(id=1, resolwe=MagicMock())
        collection_1._samples = ['sample_1']
        collection_2 = Collection(id=2, resolwe=MagicMock())
        collection_2._samples = ['sample_2']
        self.assertEqual(get_samples([collection_1, collection_2]),
                         ['sample_1', 'sample_2'])

        data = Data(id=1, resolwe=MagicMock())
        data.api(data.id).get = MagicMock(return_value={'entities': [7]})
        data.resolwe.sample.get = MagicMock(return_value='sample_1')
        self.assertEqual(get_samples(data), ['sample_1'])

        data1 = Data(id=1, resolwe=MagicMock())
        data1.api(data.id).get = MagicMock(return_value={'entities': [7]})
        data1.resolwe.sample.get = MagicMock(return_value='sample1')

        data2 = Data(id=2, resolwe=MagicMock())
        data2.api(data.id).get = MagicMock(return_value={'entities': [8]})
        data2.resolwe.sample.get = MagicMock(return_value='sample2')
        self.assertEqual(get_samples([data1, data2]), ['sample1', 'sample2'])

        data = Data(id=1,
                    resolwe=MagicMock(**{'sample.get.return_value': None}))
        data._sample = None
        with self.assertRaises(TypeError):
            get_samples(data)

        sample = Sample(id=1, resolwe=MagicMock())
        self.assertEqual(get_samples(sample), [sample])

        sample_1 = Sample(id=1, resolwe=MagicMock())
        sample_2 = Sample(id=3, resolwe=MagicMock())
        self.assertEqual(get_samples([sample_1, sample_2]),
                         [sample_1, sample_2])
    def test_dehydrate_collections(self, resolwe_mock):
        resolwe_mock.configure_mock(**{'_get_process.return_value': {'slug': 'some:prc:slug:'},
                                       '_process_inputs.return_value': {}})
        resolwe_mock.collection = MagicMock()
        resolwe_mock.api = MagicMock(**{'process.get.return_value': self.process_json,
                                        'data.post.return_value': {}})

        collection = Collection(id=1, resolwe=MagicMock())
        collection.id = 1  # this is overriden when initialized

        Resolwe.run(resolwe_mock, collections=[collection])
        resolwe_mock.api.data.post.assert_called_once_with(
            {'process': 'some:prc:slug:', 'input': {}, 'collections': [1]})
Exemple #7
0
    def setUp(self):
        self.res = resdk.Resolwe(EMAIL, PASSW, URL)
        self.reads = os.path.abspath(
            os.path.normpath(
                os.path.dirname(__file__) + "./../files/example.fastq"))
        self.data = self.res.run(slug='upload-fastq-single',
                                 input={'src': [self.reads]})
        wait_for_update(self.data, maxtime=20, step=2)
        self.contributor = self.data.contributor

        # Make collection and add self.data to it.
        json_data = self.res.api.collection.post(
            {u'name': 'testing_collection'})
        self.collection = Collection(model_data=json_data, resolwe=self.res)
Exemple #8
0
    def setUp(self):
        self.res = resdk.Resolwe(EMAIL, PASSW, URL)
        self.reads = os.path.abspath(
            os.path.normpath(
                os.path.dirname(__file__) + "./../files/example.fastq"))
        self.yaml_path = os.path.abspath(
            os.path.normpath(
                os.path.dirname(__file__) + "./../files/custom_process.yaml"))
        self.tool1_path = os.path.abspath(
            os.path.normpath(os.path.dirname(__file__) + "./../files/sum.py"))

        # # Make a collection:
        colllection_json = self.res.api.collection.post(
            {u'name': 'test_collection'})
        self.collection = Collection(model_data=colllection_json,
                                     resolwe=self.res)

        self.result = None
    def test_dehydrate_collection(self, resolwe_mock):
        resolwe_mock._get_process.return_value = Process(
            resolwe=MagicMock(), slug="process-slug"
        )
        resolwe_mock._process_inputs.return_value = {}
        resolwe_mock.api = MagicMock(**{"data.post.return_value": {}})

        Resolwe.run(
            self=resolwe_mock,
            slug="process-slug",
            collection=Collection(id=1, resolwe=MagicMock()),
        )
        resolwe_mock.api.data.post.assert_called_once_with(
            {
                "process": {"slug": "process-slug"},
                "input": {},
                "collection": {"id": 1},
            }
        )
    def test_dehydrate_collection(self, resolwe_mock):
        resolwe_mock._get_process.return_value = Process(resolwe=MagicMock(),
                                                         slug='process-slug')
        resolwe_mock._process_inputs.return_value = {}
        resolwe_mock.api = MagicMock(**{'data.post.return_value': {}})

        Resolwe.run(
            self=resolwe_mock,
            slug='process-slug',
            collection=Collection(id=1, resolwe=MagicMock()),
        )
        resolwe_mock.api.data.post.assert_called_once_with({
            'process': {
                'slug': 'process-slug'
            },
            'input': {},
            'collection': {
                'id': 1
            },
        })
Exemple #11
0
    def test_get_collection_id(self):
        collection = Collection(id=1, resolwe=MagicMock())
        collection.id = 1  # this is overriden when initialized
        self.assertEqual(get_collection_id(collection), 1)

        self.assertEqual(get_collection_id(2), 2)
Exemple #12
0
    header = next(sample_reader)
    for row in sample_reader:
        samples[row[0]] = {col: '' for col in header}
        for i, column in enumerate(row):
            if i == 0:
                continue  # skip sample name
            samples[row[0]] [header[i]] = column


for s in samples:

    collection_name = samples[s]['COLLECTION']
    try:
        collection = res.collection.get(name=collection_name)
    except LookupError:
        collection = Collection(resolwe=res)
        collection.name = collection_name
        collection.save()

    if samples[s]['PAIRED'] == '0':
        src = samples[s]['FASTQ_R1'].split(",")
        print('Uploading data for sample: {}'.format(s))
        reads = res.run('upload-fastq-single',
                        input={'src': src},
                        collections=[collection.id])

    elif samples[s]['PAIRED'] == '1':
        src1 = samples[s]['FASTQ_R1'].strip(',').split(',')
        src2 = samples[s]['FASTQ_R2'].strip(',').split(',')

        print('Uploading data for sample: {}'.format(s))