Exemple #1
0
    def test_list_object_with_sets(self):
        ws_name1 = self.createWs()
        reads_obj_ref = self.__class__.example_reads_ref
        set_obj_name = "MyReadsSet.1"
        sapi = SetAPI(self.__class__.serviceWizardURL, token=self.getContext()['token'],
                      service_ver=self.__class__.SetAPI_version)
        sapi.save_reads_set_v1({'workspace': ws_name1, 'output_object_name': set_obj_name,
                                'data': {'description': '', 'items': [{'ref': reads_obj_ref}]}})
        list_ret = self.getImpl().list_objects_with_sets(self.getContext(),
                                                         {"ws_name": ws_name1})[0]
        ret = list_ret['data']
        self.assertTrue(len(ret) > 0)
        set_count = 0
        for item in ret:
            self.assertTrue("object_info" in item)
            if "set_items" in item:
                set_count += 1
                set_items = item["set_items"]["set_items_info"]
                self.assertEqual(1, len(set_items))
        self.assertEqual(1, set_count)
        self.assertNotIn('data_palette_refs', list_ret)
        ws_id = self.getWsClient().get_workspace_info({"workspace": ws_name1})[0]

        list_ret = self.getImpl().list_objects_with_sets(self.getContext(),
                                                         {"ws_name": ws_name1,
                                                          "include_data_palettes": 1})[0]
        ret = list_ret['data']
        self.assertTrue(len(ret) > 0)
        set_count = 0
        for item in ret:
            self.assertTrue("object_info" in item)
            if "set_items" in item:
                set_count += 1
                set_items = item["set_items"]["set_items_info"]
                self.assertEqual(1, len(set_items))
        self.assertEqual(1, set_count)
        self.assertIn('data_palette_refs', list_ret)
        ws_id = self.getWsClient().get_workspace_info({"workspace": ws_name1})[0]


        ret2 = self.getImpl().list_objects_with_sets(self.getContext(),
                                                     {"ws_id": ws_id})[0]["data"]
        self.assertEqual(len(ret), len(ret2))
        type_filter = "KBaseSets.ReadsSet"
        ret3 = self.getImpl().list_objects_with_sets(self.getContext(),
                                                     {"types": [type_filter],
                                                     "workspaces": [str(ws_id)]})[0]["data"]
        self.assertTrue(len(ret3) > 0)
        for item in ret3:
            info = item['object_info']
            obj_type = info[2].split('-')[0]
            self.assertEqual(type_filter, obj_type)
        type_filter = "KBaseGenomes.Genome"
        ret4 = self.getImpl().list_objects_with_sets(self.getContext(),
                                                     {"types": [type_filter],
                                                     "workspaces": [str(ws_id)]})[0]["data"]
        self.assertTrue(len(ret4) == 0)
Exemple #2
0
    def loadReadsSet(self, fwd_reads, rev_reads, params):
        if hasattr(self.__class__, 'reads_set_ref'):
            return self.__class__.reads_set_ref
        pe_reads_ref = self.loadPairedEndReads(fwd_reads, rev_reads, params)
        reads_set_name = 'TestReadsSet'
        # create the set object

        reads_set_data = {
            'description': 'Reads Set for testing Bwa',
            'items': [{
                'ref': pe_reads_ref,
                'label': 'rs1'
            }]
        }
        # test a save
        set_api = SetAPI(self.srv_wiz_url)
        res = set_api.save_reads_set_v1({
            'data': reads_set_data,
            'output_object_name': reads_set_name,
            'workspace': params["workspace_name"]
        })
        reads_set_ref = res['set_ref']

        # reads_set_ref = '5264/52/1'
        print('Loaded ReadsSet: ' + reads_set_ref)
        return reads_set_ref
Exemple #3
0
 def test_two_users_set_inside_dp(self):
     ws_name1_1 = self.createWs()
     # Injecting reads object (real copy) into workspace1
     orig_reads_obj_ref = self.__class__.example_reads_ref
     reads_obj_name = "TestReads"
     self.getWsClient().copy_object({'from': {'ref': orig_reads_obj_ref},
                                     'to': {'workspace': ws_name1_1,
                                            'name': reads_obj_name}})
     copy_reads_obj_ref = ws_name1_1 + '/' + reads_obj_name
     ws_name1_2 = self.createWs()
     set_obj_name = "MyReadsSet.1"
     sapi = SetAPI(self.__class__.serviceWizardURL, token=self.getContext()['token'],
                   service_ver=self.__class__.SetAPI_version)
     sapi.save_reads_set_v1({'workspace': ws_name1_2, 'output_object_name': set_obj_name,
                             'data': {'description': '', 'items': [{'ref': copy_reads_obj_ref}]}})
     orig_set_ref = ws_name1_2 + '/' + set_obj_name
     # Making DP-copy of reads set object by user2
     ws_name2 = self.createWs2()
     # Let's share workspace containing set with user2
     self.getWsClient().set_permissions({'workspace': ws_name1_2, 'new_permission': 'r',
                                         'users': [self.getContext2()['user_id']]})
     # Import reads set ref into DataPalette of third workspace
     dps = DataPaletteService(self.__class__.serviceWizardURL,
                               token=self.getContext2()['token'],
                               service_ver=self.__class__.DataPalette_version)
     dps.add_to_palette({'workspace': ws_name2, 'new_refs': [{'ref': orig_set_ref}]})
     dp_ref_map = dps.list_data({'workspaces': [ws_name2]})['data_palette_refs']
     set_ref_path = next(iter(dp_ref_map.values())) + ';' + orig_set_ref
     reads_ref_path = set_ref_path + ';' + copy_reads_obj_ref
     # Un-share original workspace
     self.getWsClient().set_permissions({'workspace': ws_name1_2, 'new_permission': 'n',
                                         'users': [self.getContext2()['user_id']]})
     # Let's check that we can list set and see reads object as set item
     ret = self.getImpl().list_objects_with_sets(self.getContext2(),
                                                 {"ws_name": ws_name2})[0]["data"]
     self.assertEqual(1, len(ret))
     item = ret[0]
     self.assertTrue('set_items' in item)
     self.assertTrue('set_items_info' in item['set_items'])
     self.assertEqual(1, len(item['set_items']['set_items_info']))
     # Check access to reads and to set objects
     info = self.getWsClient2().get_object_info_new({'objects': [{'ref': set_ref_path}]})[0]
     self.assertEqual(set_obj_name, info[1])
     info = self.getWsClient2().get_object_info_new({'objects': [{'ref': reads_ref_path}]})[0]
     self.assertEqual(reads_obj_name, info[1])
Exemple #4
0
 def test_unique_items(self):
     # Create original workspace with reads object + ReadsSet object
     ws_name1 = self.createWs()
     foft = FakeObjectsForTests(os.environ['SDK_CALLBACK_URL'])
     reads_obj_name = "testreads1"
     foft.create_fake_reads({'ws_name': ws_name1, 'obj_names': [reads_obj_name]})
     reads_obj_ref = ws_name1 + '/' + reads_obj_name
     set_obj_name = "testreads_set1"
     sapi = SetAPI(self.__class__.serviceWizardURL, token=self.getContext()['token'],
                   service_ver=self.__class__.SetAPI_version)
     sapi.save_reads_set_v1({'workspace': ws_name1, 'output_object_name': set_obj_name,
                             'data': {'description': '', 'items': [{'ref': reads_obj_ref}]}})
     set_obj_ref = ws_name1 + '/' + set_obj_name
     # Create workspace with DataPalette copy of Reads object and copy of ReadsSet
     ws_name2 = self.createWs()
     dps = DataPaletteService(self.__class__.serviceWizardURL, token=self.getContext()['token'],
                              service_ver=self.__class__.DataPalette_version)
     dps.add_to_palette({'workspace': ws_name2, 'new_refs': [{'ref': reads_obj_ref},
                                                             {'ref': set_obj_ref}]})
     # Check if listing in both these workspaces at the same time gives unique items
     ret = self.getImpl().list_objects_with_sets(self.getContext(),
                                                 {"workspaces": [ws_name1, ws_name2]})[0]["data"]
     self.assertEqual(2, len(ret))
Exemple #5
0
def load_reads_set(srv_wiz_url, ws_name, reads_set, target_name):
    """
    Combine a list of reads references into a ReadsSet.
    if file_rev is None or not a present key, then this is treated as a single end reads.
    """
    set_client = SetAPI(srv_wiz_url)
    set_output = set_client.save_reads_set_v1({
        "workspace": ws_name,
        "output_object_name": target_name,
        "data": {
            "description": "reads set for testing",
            "items": reads_set
        }
    })
    return set_output["set_ref"]