Python
MOLGENIS Python API allows access to your MOLGENIS data from python. It is available on every MOLGENIS with version 1.14.0 and up on the URL
http://molgenis.mydomain.example/molgenis.py.
As an example, let's create a plot for publicly available ASE data available on https://molgenis56.target.rug.nl/. For a description of the data, take a look at http://molgenis.org/ase.
We'll be creating a scatter plot so if you haven't already, install matplotlib from the commandline:
pip install matplotlibDownload the python api from a molgenis server, for instance https://molgenis01.target.rug.nl/molgenis.py and save it in molgenis.py.
Start an interactive python shell and create a molgenis connection:
import molgenisThis imports the molgenis package.
session = molgenis.Session("https://molgenis56.target.rug.nl/api/")Instantiates a new Session pointing at the molgenis56 server. If you take a look at the connection by typing
dir(session)you should see, amongst others, the methods you can call:
[...,'add', 'add_all', 'delete', 'get', 'get_attribute_meta_data', 'get_entity_meta_data', 'login', 'logout',...]Let's load some data from the server using session.get:
session.get("ASE")This retrieves the top 1000 rows from the ASE entity.
[{u'Alternative_allele': u'A', u'P_Value': 2.06504739339637e-17, u'Genes': {u'href': u'/api/v1/ASE/rs9901673/Genes'}, u'Fraction_alternative_allele': 0.479, u'Pos': 7484101, u'Reference_allele': u'C', u'Chr': u'17', u'href': u'/api/v1/ASE/rs9901673', u'Samples': u'145', u'Likelihood_ratio_test_D': 72.0813644150712, u'SNP_ID': u'rs9901673'}, {u'Alternative_allele': u'T', u'P_Value': 8.78109735398113e-18, u'Genes': {u'href': u'/api/v1/ASE/rs2597775/Genes'}, u'Fraction_alternative_allele': 0.479, u'Pos': 17503382, u'Reference_allele': u'C', u'Chr': u'4', u'href': u'/api/v1/ASE/rs2597775', u'Samples': u'359', u'Likelihood_ratio_test_D': 73.769089117417, u'SNP_ID': u'rs2597775'}, {u'Alternative_allele': u'C', u'P_Value': 1.4917458949834e-18, u'Genes': {u'href': u'/api/v1/ASE/rs3216/Genes'}, u'Fraction_alternative_allele': 0.479, u'Pos': 214421, u'Reference_allele': u'G', u'Chr': u'11', u'href': u'/api/v1/ASE/rs3216', u'Samples': u'301', u'Likelihood_ratio_test_D': 77.2691957930797, u'SNP_ID': u'rs3216'}, [...],{u'Alternative_allele': u'T', u'P_Value': 0.000132500824069775, u'Genes': {u'href': u'/api/v1/ASE/rs1056019/Genes'}, u'Fraction_alternative_allele': 0.482, u'Pos': 41337435, u'Reference_allele': u'C', u'Chr': u'12', u'href': u'/api/v1/ASE/rs1056019', u'Samples': u'47', u'Likelihood_ratio_test_D': 14.605874945467, u'SNP_ID': u'rs1056019'}]Let's retrieve a specific SNP from the ASE entity:
This SNP has a mild but significant allele-specific expression, based on expression counts in 21 samples.
Let's retrieve the samples for this SNP:
There they are.
Let's format the expression counts
Let's plot the expression counts in these samples in a scatter plot.
And add a line for the non-specific expression.

Last updated