opencb / cellbase

High-Performance NoSQL database and RESTful web services to access to most relevant biological data
Apache License 2.0
89 stars 53 forks source link

Clients: use script to autogenerate #527

Open julie-sullivan opened 4 years ago

julie-sullivan commented 4 years ago

I'd like to use the opencga script to autogenerate the clients for CellBase.

Can we use the same script, or do we need to modify the current one?

julie-sullivan commented 4 years ago

Here are the changes I made so far:

# java_client_generator.py
+            'Admin': 'Admin',
+            'Clinical': 'Clinical',
+            'Gene': 'Gene',
+            'Chromosome': 'Genome Sequence',
+            'Protein': 'Protein',
+            'Region': 'Region',
+            'Regulation': 'Regulation',
+            'Species': 'Species',
+            'TFBS': 'TF',
+            'Transcript': 'Transcript',
+            'Variant': 'Variant',
+            'Xref': 'Id'

The version number is hardcoded:

# rest_client_generator.py

-            server_url + '/webservices/rest/v2/meta/about'
+            server_url + '/webservices/rest/v5/meta/about'

-        for category in requests.get(self.server_url + '/webservices/rest/v2/meta/api').json()['responses'][0]['results'][0]:
+        for category in requests.get(self.server_url + '/webservices/rest/v5/meta/api').json()['responses'][0]['results'][0]:

Also CellBase uses version instead of apiVersion

-        return category['path'].replace('/{apiVersion}/', '')
+        return category['path'].replace('/{apiVersion}/', '').replace('/{version}/', '')

-        return endpoint['path'].replace('/{apiVersion}/', '')
+        return endpoint['path'].replace('/{apiVersion}/', '').replace('/{version}/', '')
julie-sullivan commented 4 years ago

The error I am working on now is that CellBase has /{species} prepended to most end points, OpenCGA does not have this.

~/git/opencga/opencga-app/app/misc/clients (develop) $ python3 java_client_generator.py http://127.0.1.1:9090/cellbase /tmp
Processing {species}/clinical/variant/search
Traceback (most recent call last):
  File "java_client_generator.py", line 307, in <module>
    sys.exit(main())
  File "java_client_generator.py", line 304, in main
    client_generator.create_rest_clients()
  File "/home/julie/git/opencga/opencga-app/app/misc/clients/rest_client_generator.py", line 199, in create_rest_clients
    text.append(self.get_method_definition(category, endpoint))
  File "java_client_generator.py", line 126, in get_method_definition
    typed_parameters.append(self.get_parameter_type(parameter) + ' ' + parameter)
  File "java_client_generator.py", line 206, in get_parameter_type
    param_type = super().get_parameter_type(parameter)
  File "/home/julie/git/opencga/opencga-app/app/misc/clients/rest_client_generator.py", line 83, in get_parameter_type
    return self.parameters[parameter]['type']
KeyError: 'species'
julie-sullivan commented 4 years ago

I've added the scripts to CellBase (with the changes I listed above):

https://github.com/opencb/cellbase/tree/develop/cellbase-app/app/clients

imedina commented 4 years ago

Just worth mentioning the clients to be generated include Java, Python, R and Javascript, is this right?

julie-sullivan commented 4 years ago

Yes! That is correct.