Skip to content

Commit

Permalink
second commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Cedric (Huchuan) Xia committed Mar 8, 2018
1 parent 73fafe7 commit 37cff51
Show file tree
Hide file tree
Showing 15 changed files with 5,099 additions and 0 deletions.
76 changes: 76 additions & 0 deletions .ipynb_checkpoints/Cedric_gene_functions-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[NbConvertApp] Converting notebook Cedric_gene_functions.ipynb to script\n",
"[NbConvertApp] Writing 5930 bytes to Cedric_gene_functions.py\n"
]
}
],
"source": [
"!jupyter nbconvert --to script Cedric_gene_functions.ipynb"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## geneMNItoSchaefer"
]
},
{
"cell_type": "code",
"execution_count": 76,
Expand Down Expand Up @@ -97,6 +122,57 @@
" print 'Saved variables at ' + variables_filename + '\\n'\n",
" print 'Saved csv at ' + csv_filename + '\\n'"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## selectProbe"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def selectProbe (donor):\n",
" import os\n",
" import pandas as pd\n",
" \n",
" # Set up the working directory\n",
" # All paths after this are relative path to the root of chead\n",
"\n",
" wk_dir = '/Users/hxia/Desktop/BBL/' # this is where I have mounted chead to on my laptop. \n",
" # Change the above to an empty string if working directly on chead \n",
"\n",
" # Set up the project directory\n",
" project_path = os.path.join(wk_dir,'data/joy/BBL/projects/prsConnectivity')\n",
" \n",
" # set paths\n",
" donor_path = os.path.join(project_path,'ABI','normalized_microarray_donor%s' % donor)\n",
" probes_info = pd.read_csv(os.path.join(donor_path,'Probes.csv'))\n",
" gene_expr = pd.read_csv(os.path.join(donor_path,'MicroarrayExpression.csv'),header=None)\n",
" sample_info = pd.read_csv(os.path.join(donor_path,'SampleAnnot.csv'))\n",
" \n",
" # get probes with available gene names\n",
" valid_probes = probes_info['entrez_id']>0\n",
" gene_expr = gene_expr[valid_probes]\n",
" probes_info = probes_info[valid_probes]\n",
" \n",
" # collapse rows\n",
" probe_names = probes_info['gene_symbol'][probes_info['probe_id'] == gene_expr[0]]\n",
" datCollapsed = gene_expr.groupby(probe_names).max()\n",
" \n",
" # create column names\n",
" gene_col_names = ['probe_id']\n",
" structure_ids = list(sample_info['structure_id'].astype(str))\n",
" gene_col_names.extend(structure_ids)\n",
" datCollapsed.columns = gene_col_names\n",
" \n",
" # output\n",
" return datCollapsed"
]
}
],
"metadata": {
Expand Down
6 changes: 6 additions & 0 deletions .ipynb_checkpoints/Select_Probes-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}
200 changes: 200 additions & 0 deletions .ipynb_checkpoints/forOne_PlotGenesOnBrain-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%gui qt4"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import os.path as op\n",
"import numpy as np\n",
"from numpy import arange\n",
"from numpy.random import permutation\n",
"import nibabel as nib\n",
"from surfer import Brain\n",
"import pickle\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Set up the working directory\n",
"# All paths after this are relative path to the root of chead\n",
"\n",
"wk_dir = '/Users/hxia/Desktop/BBL/' # this is where I have mounted chead to on my laptop. \n",
"# Change the above to an empty string if working directly on chead \n",
"\n",
"# Set up the project directory\n",
"project_path = os.path.join(wk_dir,'data/joy/BBL/projects/prsConnectivity')"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"donor = 15496\n",
"numParcel = 100\n",
"numNetwork = 7\n",
"mm = 1\n",
"parcel_annot_file = os.path.join(wk_dir,'data/joy/BBL/studies/pnc/template/Schaefer/FreeSurfer5.3/fsaverage/label',\\\n",
" 'lh.Schaefer2018_%sParcels_%sNetworks_order.annot' % (numParcel,numNetwork))\n",
"gene_coord_file = os.path.join(project_path,'ABI','gene_mapping','%sdonor_%sParcels_%sNetwork_%smm.pkl'\\\n",
" % (donor, numParcel, numNetwork, mm))\n",
"gene_coord = pickle.load( open( gene_coord_file, \"rb\" ) )\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['Cont', 'Default', 'DorsAttn', 'Limbic', 'NotAssigned',\n",
" 'SalVentAttn', 'SomMot', 'Vis'], dtype='|S11')"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"community_list = np.unique(gene_coord[4].values())\n",
"community_color_list = ['orange','red','green','lightgreen','black',\\\n",
" 'violet','blue','purple']\n",
"\n",
"#community_color_list = ['orange','red','green','lightgreen',\\\n",
"# 'violet','blue','purple','orchid','salmon','black'\\\n",
"# 'teal','gold','darkblue','crimson','beige','plum','silver']\n",
"community_list"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"brain = Brain('fsaverage', \"lh\", \"inflated\",background='white',alpha=1)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"brain = Brain('fsaverage','lh', \"inflated\",views=['lat','med'], background='white',alpha=1)"
]
},
{
"cell_type": "code",
"execution_count": 268,
"metadata": {},
"outputs": [],
"source": [
"brain = Brain('fsaverage', \"lh\", \"sphere\", background='white',alpha=1)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"for idx, community in enumerate(community_list):\n",
" if community != 'NotAssigned':\n",
" filtered_dict = {k:v for k,v in gene_coord[4].iteritems() if community in v}\n",
" brain.add_foci(pd.DataFrame.as_matrix(gene_coord[0].loc[filtered_dict.keys()]),hemi='lh',map_surface='pial',\\\n",
" color=community_color_list[idx],scale_factor=0.5)"
]
},
{
"cell_type": "code",
"execution_count": 269,
"metadata": {},
"outputs": [],
"source": [
"brain = Brain('fsaverage', \"lh\", \"sphere\",background='white')\n",
"for idx, community in enumerate(community_list):\n",
" if community != 'NotAssigned':\n",
" filtered_dict = {k:v for k,v in gene_coord[4].iteritems() if community in v}\n",
" brain.add_foci(pd.DataFrame.as_matrix(gene_coord[0].loc[filtered_dict.keys()]),map_surface='sphere',\\\n",
" color=community_color_list[idx],scale_factor=0.5)"
]
},
{
"cell_type": "code",
"execution_count": 294,
"metadata": {},
"outputs": [],
"source": [
"brain.add_annotation(parcel_annot_file, borders=False,alpha=0.5)"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"brain.add_annotation(parcel_annot_file, borders=False,alpha=0.5, hemi='lh')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"brain = Brain"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "myenv2",
"language": "python",
"name": "myenv2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit 37cff51

Please sign in to comment.