def get_transcript(self, ensg): """Takes ENSG and RefSeq codes to find Ensembl transcript ID and peptide ID. :param ensg: ENSG number. :param refseq: RefSeq NM_ code. :return: transcript and protein IDs. """ # 1) Connect to BioMart server. server = BiomartServer("http://www.ensembl.org/biomart") server.verbose = True # provides setting up details new_list = [] # 2) Select dataset to check against. Not essential but quicker so BioMart doesn't need to search. hs_genes = server.datasets['hsapiens_gene_ensembl'] # 3) This is like clicking Results on the BioMart website. Filter by ENSG and RefSeq to get transcript & peptide results = hs_genes.search({ 'filters': {'ensembl_gene_id': '%s' % ensg, 'refseq_mrna': '%s' % self.refseq}, 'attributes': ['ensembl_transcript_id', 'ensembl_peptide_id'] }, header=1) # 4) Convert to readable format and add relevant information to a list. for line in results.iter_lines(): line = line.decode('utf-8') new_list.append(line.split()) uni_transcript = new_list[1] transcript = uni_transcript[0] protein = uni_transcript[1] return transcript, protein
def serverConnection(proxy=None, verbose=True): server = BiomartServer("http://ensembl.gramene.org/biomart") # if you are behind a proxy if proxy is not None: server.http_proxy = os.environ.get('http_proxy', proxy) # set verbose to True to get some messages server.verbose = verbose return server
def server_connect(self): connected = False while not connected: try: server = BiomartServer("http://grch37.ensembl.org/biomart") connected = True except requests.exceptions.ConnectionError: connected = False print('Connection error') server.verbose = True self.hsapiens_snp = server.datasets['hsapiens_snp']
def GOquery(query, organism, gene_id): # connect to server server = BiomartServer("http://www.biomart.org/biomart") # set verbose to True to get some messages server.verbose = True db = server.datasets[organism + '_gene_ensembl'] response = db.search({ 'filters': { gene_id: query }, 'attributes': [gene_id, 'with_go'] }) return response
def get_transcript(ensg, refseq): server = BiomartServer("http://www.ensembl.org/biomart") server.verbose = True new_list = [] hs_genes = server.datasets['hsapiens_gene_ensembl'] results = hs_genes.search({ 'filters': {'ensembl_gene_id': '%s' % ensg, 'refseq_mrna': '%s' % refseq}, 'attributes': ['ensembl_transcript_id', 'ensembl_peptide_id'] }, header=1) for line in results.iter_lines(): line = line.decode('utf-8') new_list.append(line.split()) uni_transcript = new_list[1] transcript = uni_transcript[0] protein = uni_transcript[1] return transcript, protein
def searchDataset(chrom, start, end): from biomart import BiomartServer server = BiomartServer("http://asia.ensembl.org/biomart") server.verbose = True ccrigri = server.datasets["ccrigri_gene_ensembl"] response = ccrigri.search({ "filters": { "chromosome_name": chrom, "start": start, "end": end }, "attributes": [ "ensembl_gene_id", "ensembl_transcript_id", "refseq_mrna", "external_gene_name", "start_position", "end_position", "wikigene_description" ] }) for i in response.iter_lines(): i = i.decode("utf-8") return i
# RUN ========================================================================== # GENE LIST # ------------------------------------------------------------------------------ # Read gene list gene_list = pd.read_csv(gene_list_file, header=None)[0].tolist() # BioMaRt # Connect to the server and prepare for querying # ------------------------------------------------------------------------------ # Connect to biomart server = BiomartServer("http://www.ensembl.org/biomart") server.verbose = False # Check available databases #server.show_databases() # Select Genes database db = server.databases['ENSEMBL_MART_ENSEMBL'] # Check available datasets (species) #db.show_datasets() # Select H. sapiens dataset ds = db.datasets['hsapiens_gene_ensembl'] # show all available filters and attributes of the 'uniprot' dataset #ds.show_filters()
from biomart import BiomartServer server = BiomartServer( "http://www.biomart.org/biomart" ) # if not behind a proxy, otherwise see: https://pypi.python.org/pypi/biomart/0.8.0 server.verbose = True # set verbose to True to get some messages # run a search with custom filters and attributes (no header) response = uniprot.search({ 'filters': { 'accession': ['Q9FMA1', 'Q8LFJ9'] }, 'attributes': [ 'accession', 'protein_name' ] })
#!/usr/bin/env python # https://pypi.python.org/pypi/biomart from biomart import BiomartServer #Connect to a Biomart Server server = BiomartServer( "http://www.biomart.org/biomart" ) # set verbose to True to get some messages server.verbose = True