Help for a python BEGINNER
1
0
Entering edit mode
4.1 years ago
kjacobs8 ▴ 10

Please help, I am a python newbie, and I'm trying to figure how to convert a list of about a million ensembl gene ID's into gene symbols. I have imported pandas and numpy and have gotten to the point where I have the csv imported.

data = pd.read_csv("genes_affected_2.csv")

data.head()

I am trying to use a code like this:

ginfo = mg.querymany(ens, scopes='ensembl.gene')

for g in ginfo:
 for k, v in g.iteritems():
  print "- {0: <10}: {1}".format(k, v)
 print

but I can't figure out how to take the column values from the "genes_affected_2.csv" file and convert them.

mygene annotation python • 960 views
ADD COMMENT
0
Entering edit mode

What does data.head() return?

ADD REPLY
0
Entering edit mode

It just returns the first five lines of my table!

ADD REPLY
1
Entering edit mode
4.1 years ago

You could use the following example. You want to figure out building a list of genes from what data.head() tells you about column headers.

#!/usr/bin/env python

import sys
from mygene import MyGeneInfo

mg = MyGeneInfo()

genes = [
    "ENSG00000099308",
    "ENSG00000150676",
    "ENSG00000180776",
    "ENSG00000108848",
    "ENSG00000101473"
]

results = mg.querymany(genes, scopes=["ensembl.gene"], fields=["symbol"], species="human", verbose=False)

for res in results:
    q = res['query']
    s = 'NA'
    if 'symbol' in res:
        s = res['symbol']
    sys.stdout.write('{}\t{}\n'.format(q, s))

This example gives the response:

$ ./test.py
ENSG00000099308 MAST3
ENSG00000150676 CCDC83
ENSG00000180776 ZDHHC20
ENSG00000108848 LUC7L3
ENSG00000101473 ACOT8
ADD COMMENT
0
Entering edit mode

Wow! Yes, that is exactly what I need! How do I make it run that same thing for the entire document instead of the first five lines?

ADD REPLY
1
Entering edit mode

I just figured it out! Used the iloc code and a foreloop for the entire table. Thank you so much!!!! Honestly couldn't have done it without your help.

ADD REPLY

Login before adding your answer.

Traffic: 2398 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6