From 1f27d5e0f6c65908d021d0c38f0b2e0671a63f5d Mon Sep 17 00:00:00 2001 From: Daniel Himmelstein Date: Wed, 5 Oct 2016 18:25:03 -0400 Subject: [PATCH] Rerun with fixed entrez_gene_id bug --- 6.differential-expression.ipynb | 12 ++++++------ scripts/6.differential-expression.py | 18 +++++++++++++----- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/6.differential-expression.ipynb b/6.differential-expression.ipynb index b0355c7..deca7d5 100644 --- a/6.differential-expression.ipynb +++ b/6.differential-expression.ipynb @@ -192,7 +192,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 5, "metadata": { "collapsed": false }, @@ -233,7 +233,7 @@ }, { "cell_type": "code", - "execution_count": 39, + "execution_count": 6, "metadata": { "collapsed": false }, @@ -244,7 +244,7 @@ "22973" ] }, - "execution_count": 39, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -259,7 +259,7 @@ }, { "cell_type": "code", - "execution_count": 42, + "execution_count": 7, "metadata": { "collapsed": false }, @@ -364,7 +364,7 @@ "349009 -1.196275 0.557971 SLC25A5-AS1 " ] }, - "execution_count": 42, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -376,7 +376,7 @@ }, { "cell_type": "code", - "execution_count": 43, + "execution_count": 8, "metadata": { "collapsed": false }, diff --git a/scripts/6.differential-expression.py b/scripts/6.differential-expression.py index 655969f..c0a02c0 100644 --- a/scripts/6.differential-expression.py +++ b/scripts/6.differential-expression.py @@ -57,7 +57,7 @@ def get_diffex(subtype_df): ttest = ttest_1samp(diffex_df, popmean=0, axis=0) df = pandas.DataFrame.from_items([ - ('entrez_gene_id', diffex_df.columns.astype(int)), + ('entrez_gene_id', diffex_df.columns), ('patients', len(diffex_df)), ('tumor_mean', tumor_df.mean()), ('normal_mean', normal_df.mean()), @@ -67,21 +67,29 @@ def get_diffex(subtype_df): ]) return df -diffex_df = type_df.groupby('acronym').apply(get_diffex).reset_index('acronym') +diffex_df = (type_df + .groupby('acronym') + .apply(get_diffex) + .reset_index('acronym') + .query("patients >= 5") +) + +diffex_df.entrez_gene_id = diffex_df.entrez_gene_id.astype(int) # In[6]: # Add gene symbols path = os.path.join('data', 'genes.tsv') -gene_df = pandas.read_table(path) +gene_df = pandas.read_table(path, low_memory=False) gene_df = gene_df[['entrez_gene_id', 'symbol']] -diffex_df = gene_df.merge(diffex_df, how='right') +len(gene_df) # In[7]: -diffex_df.head() +diffex_df = diffex_df.merge(gene_df, how='left') +diffex_df.tail() # In[8]: