Code Monkey home page Code Monkey logo

erythroid-genes's People

Contributors

daler avatar

Watchers

 avatar  avatar

Forkers

alenzhao

erythroid-genes's Issues

Last block launched with errors

Hi,
I appreciate all your works and especially this on getting genes list. I have got one error at the end of the script. The error is as below (that one from snakemake execution but I am getting same when I run notebook alone)
`jupyter nbconvert --execute erythroid-genes/erythroid-gene-lists.ipynb
[NbConvertApp] Converting notebook erythroid-genes/erythroid-gene-lists.ipynb to html
[NbConvertApp] Executing notebook with kernel: python3
[NbConvertApp] ERROR | Error while converting 'erythroid-genes/erythroid-gene-lists.ipynb'
Traceback (most recent call last):
File "/home/sergio/miniconda3/lib/python3.5/site-packages/nbconvert/nbconvertapp.py", line 373, in export_single_notebook
output, resources = self.exporter.from_filename(notebook_filename, resources=resources)
File "/home/sergio/miniconda3/lib/python3.5/site-packages/nbconvert/exporters/exporter.py", line 171, in from_filename
return self.from_file(f, resources=resources, **kw)
File "/home/sergio/miniconda3/lib/python3.5/site-packages/nbconvert/exporters/exporter.py", line 189, in from_file
return self.from_notebook_node(nbformat.read(file_stream, as_version=4), resources=resources, **kw)
File "/home/sergio/miniconda3/lib/python3.5/site-packages/nbconvert/exporters/html.py", line 69, in from_notebook_node
return super(HTMLExporter, self).from_notebook_node(nb, resources, **kw)
File "/home/sergio/miniconda3/lib/python3.5/site-packages/nbconvert/exporters/templateexporter.py", line 236, in from_notebook_node
nb_copy, resources = super(TemplateExporter, self).from_notebook_node(nb, resources, **kw)
File "/home/sergio/miniconda3/lib/python3.5/site-packages/nbconvert/exporters/exporter.py", line 131, in from_notebook_node
nb_copy, resources = self._preprocess(nb_copy, resources)
File "/home/sergio/miniconda3/lib/python3.5/site-packages/nbconvert/exporters/exporter.py", line 308, in _preprocess
nbc, resc = preprocessor(nbc, resc)
File "/home/sergio/miniconda3/lib/python3.5/site-packages/nbconvert/preprocessors/base.py", line 47, in call
return self.preprocess(nb,resources)
File "/home/sergio/miniconda3/lib/python3.5/site-packages/nbconvert/preprocessors/execute.py", line 211, in preprocess
nb, resources = super(ExecutePreprocessor, self).preprocess(nb, resources)
File "/home/sergio/miniconda3/lib/python3.5/site-packages/nbconvert/preprocessors/base.py", line 70, in preprocess
nb.cells[index], resources = self.preprocess_cell(cell, resources, index)
File "/home/sergio/miniconda3/lib/python3.5/site-packages/nbconvert/preprocessors/execute.py", line 242, in preprocess_cell
raise CellExecutionError(msg)
nbconvert.preprocessors.execute.CellExecutionError: An error occurred while executing the following cell:

def get_human_genes(ids):
"""
Given a list of MyGene.info IDs:

    - Query MyGene.info to retrieve Homologene entries
    - extract human homologs from the Homologene results
    - re-query MyGene.info using the human homologs, and attach
      additional fields
    - return the human homolog dataframe
    
If `ids` is a DataFrame, then use the `_id` field. Otherwise
expect a list of MyGene.info IDs.
"""

if isinstance(ids, pandas.DataFrame):
    ids = list(ids._id)

# Just ask for the homologene genes
results = mg.querymany(
    ids,
    fields='homologene.genes',
    species='mouse',
    as_dataframe=True,
    verbose=False,
)

# Homologene results come back as lists of items. Multiple orthologs 
# from the same species will manifest as multiple entries in the list.
human_orthologs = []
human_taxon_id = 9606
for x in results['homologene.genes']:
    if isinstance(x, list):
        for i in x:
            if i[0] == human_taxon_id:
                human_orthologs.append(i[1])

# Re-query, using the human genes.
return mg.querymany(
    human_orthologs,
    species='human',
    fields='symbol,name,alias,entrezgene,ensembl.gene',
    as_dataframe=True,
    verbose=False)

intersection of both lists

found_in_both = li[li._id.isin(hughes._id)]

union of both lists

found_in_either = pandas.concat((li, hughes)).drop_duplicates('_id')

human orthologs of each

human_found_in_both = get_human_genes(found_in_both)
human_found_in_either = get_human_genes(found_in_either)
human_li = get_human_genes(li)
human_hughes = get_human_genes(hughes)

def export_gene_lists(df, label, prefix='gene-lists/',
fields=['_id', 'entrezgene', 'ensembl.gene', 'symbol', 'alias']):
"""
For each of the specified fields, creates a new file named after
the pattern

    <prefix><label>-<field>.txt

containing the unique set of identifiers for that field.
"""

for field in fields:
    filename = prefix + label + '-' + field + '.txt'
    df2 = df[field].dropna()
    with open(filename, 'w') as fout:
        for i in df2:
            if isinstance(i, list):
                i = i = '|'.join(i)
            fout.write('%s\n' % i)

import os
if not os.path.exists('gene-lists'):
os.makedirs('gene-lists')

export_gene_lists(li, 'li')
export_gene_lists(human_li, 'li_human_orthologs')
export_gene_lists(hughes, 'hughes')
export_gene_lists(human_hughes, 'hughes_human_orthologs')
export_gene_lists(found_in_either, 'union')
export_gene_lists(human_found_in_either, 'union_human_orthologs')
export_gene_lists(found_in_both, 'intersection')
export_gene_lists(human_found_in_both, 'intersection_human_orthologs')

KeyError: 'homologene.genes'
`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.