def test_get_observations(mocked_config, mocked_responses):
    constraint = {'type': 'true'}
    api = TransmartRestClient(mocked_config)
    response: Hypercube = api.get_observations(constraint)
    dimension_declaration = response.dimensionDeclarations
    cells = response.cells
    dimension_elements = response.dimensionElements
    assert len(dimension_declaration) == 12
    assert len(cells) == 3
    assert len(dimension_elements) == 9
 def setup(self):
     api = TransmartRestClient(self.mocked_config)
     constraint = {'type': 'true'}
     test_query_result = QueryResults(api.get_observations(constraint),
                                      api.get_tree_nodes(),
                                      api.get_dimensions(),
                                      api.get_studies(),
                                      api.get_relation_types(),
                                      api.get_relations())
     mapper = TransmartLoaderMapper()
     self.qr_collection = mapper.map_query_results(test_query_result)
Beispiel #3
0
    def copy_slice(self, constraint: Dict, output_dir: Path) -> None:
        """
        Reads data from a TranSMART instance using the input constraint
        and writes transmart-copy staging files to the output directory.

        :param constraint the constraint to use when reading data
        :param output_dir the directory to write staging files to
        """
        Console.info('Reading data from tranSMART...')
        transmart_client = TransmartRestClient(self.config)
        query_results = QueryResults(
            transmart_client.get_observations(constraint),
            transmart_client.get_tree_nodes(depth=0, tags=True),
            transmart_client.get_dimensions(), transmart_client.get_studies(),
            transmart_client.get_relation_types(),
            transmart_client.get_relations())

        collection: DataCollection = TransmartLoaderMapper().map_query_results(
            query_results)

        Console.info('Writing files to {}'.format(output_dir))
        copy_writer = TransmartCopyWriter(str(output_dir))
        copy_writer.write_collection(collection)
        Console.info('Done.')
def test_get_relation_types(mocked_config, mocked_responses):
    api = TransmartRestClient(mocked_config)
    response: RelationTypes = api.get_relation_types()
    assert len(response.relationTypes) == 7
def test_get_studies(mocked_config, mocked_responses):
    api = TransmartRestClient(mocked_config)
    response: Studies = api.get_studies()
    assert len(response.studies) == 1
def test_get_dimensions(mocked_config, mocked_responses):
    api = TransmartRestClient(mocked_config)
    response: Dimensions = api.get_dimensions()
    assert len(response.dimensions) == 10
def test_get_tree_nodes(mocked_config, mocked_responses):
    api = TransmartRestClient(mocked_config)
    response: TreeNodes = api.get_tree_nodes()
    assert len(response.tree_nodes) == 1
    assert len(response.tree_nodes[0].children) == 1
    assert len(TreeNode(**response.tree_nodes[0].children[0]).children) == 3