Skip to content

Commit 71d0a5a

Browse files
committed
Added Dockefile w/ python 3
1 parent 001b1cd commit 71d0a5a

File tree

9 files changed

+252
-300
lines changed

9 files changed

+252
-300
lines changed

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM jupyter/scipy-notebook:latest
2+
3+
COPY requirements.txt /tmp/
4+
RUN pip install --requirement /tmp/requirements.txt && \
5+
fix-permissions $CONDA_DIR && \
6+
fix-permissions /home/$NB_USER
7+
8+
WORKDIR /usr/src/work

classification.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import numpy as np
2-
from tools import ProgressBar, mask_diagonal
2+
from tqdm import tqdm
3+
from tools import mask_diagonal
34
from joblib import Parallel, delayed
45

56
# Replace with a more basic sklearn function
67
from neurosynth.analysis.classify import classify
78

89

910
def classify_parallel(classifier, scoring, region_data, importance_function):
10-
""" Parallel classification function. Used to classify for each region if study
11+
""" Parallel classification function. Used to classify for each region if study
1112
was activated or not (typically based on neurosynth features)
1213
classifier: sklearn classifier
1314
scoring: sklearn scoring function
@@ -31,15 +32,15 @@ def log_odds_ratio(clf):
3132

3233
class RegionalClassifier(object):
3334

34-
"""" Object used to classify on a region by region basis (from a cluster solution)
35-
if studies activated a region using Neurosynth features (e.g. topics)
35+
"""" Object used to classify on a region by region basis (from a cluster solution)
36+
if studies activated a region using Neurosynth features (e.g. topics)
3637
as classification features """
3738

3839
def __init__(self, dataset, mask_img, classifier=None, cv='4-Fold',
3940
thresh=0.05, thresh_low=0):
4041
"""
4142
dataset - Neurosynth dataset
42-
mask_img - Path to Nifti image containing discrete regions coded as levels
43+
mask_img - Path to Nifti image containing discrete regions coded as levels
4344
classifier - sklearn classifier
4445
cv - cross validation strategy
4546
thresh - Threshold used to determine if a study is considered to have activated a region
@@ -109,18 +110,15 @@ def classify(self, scoring='accuracy', n_jobs=1, importance_function=None):
109110
self.initalize_containers()
110111

111112
print("Classifying...")
112-
pb = ProgressBar(self.n_regions, start=True)
113113

114-
for index, output in enumerate(Parallel(n_jobs=n_jobs)(
115-
delayed(classify_parallel)(
116-
self.classifier, scoring, region_data, importance_function) for region_data in self.data)):
114+
for index, output in enumerate(
115+
tqdm(Parallel(n_jobs=n_jobs)(delayed(classify_parallel)(self.classifier, scoring, region_data, importance_function) for region_data in self.data))):
117116
self.class_score[index] = output['score']
118117
self.importance[index] = output['importance']
119118
self.predictions[index] = output['predictions']
120-
pb.next()
121119

122120
def get_formatted_importances(self, feature_names=None):
123-
""" Returns a pandas table of importances for each feature for each region.
121+
""" Returns a pandas table of importances for each feature for each region.
124122
Optionally takes new names for each feature (i.e. nickanames) """
125123
import pandas as pd
126124
if feature_names is None:

clustering.ipynb

Lines changed: 40 additions & 79 deletions
Large diffs are not rendered by default.

coactivation.ipynb

Lines changed: 145 additions & 118 deletions
Large diffs are not rendered by default.

coactivation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def coactivation_contrast(dataset, infile, regions=None, target_thresh=0.05,
3737

3838
affine = image.get_affine()
3939

40-
stat="pFgA_z_FDR_%s" % str(q)
40+
stat="association-test_z_FDR_%s" % str(q)
4141

4242
if regions == None:
4343
regions = np.arange(1, image.get_data().max() + 1)

index.ipynb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@
2222
},
2323
{
2424
"cell_type": "code",
25-
"execution_count": null,
26-
"metadata": {
27-
"collapsed": true,
28-
"deletable": true,
29-
"editable": true
30-
},
25+
"execution_count": 1,
26+
"metadata": {},
3127
"outputs": [],
3228
"source": [
3329
"import zipfile\n",
@@ -63,7 +59,7 @@
6359
"name": "python",
6460
"nbconvert_exporter": "python",
6561
"pygments_lexer": "ipython3",
66-
"version": "3.5.2"
62+
"version": "3.6.8"
6763
}
6864
},
6965
"nbformat": 4,

profiles.ipynb

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,9 @@
2323
{
2424
"cell_type": "code",
2525
"execution_count": 1,
26-
"metadata": {
27-
"collapsed": true
28-
},
26+
"metadata": {},
2927
"outputs": [],
30-
"source": ["%matplotlib inline\n",
28+
"source": [
3129
"# Load a neurosynth dataset. If you generate your own dataset, you can try this with fewer or greater number of topics\n",
3230
"from neurosynth.base.dataset import Dataset\n",
3331
"dataset = Dataset.load(\"data/neurosynth_60_0.4.pkl\")"
@@ -36,9 +34,7 @@
3634
{
3735
"cell_type": "code",
3836
"execution_count": 2,
39-
"metadata": {
40-
"collapsed": false
41-
},
37+
"metadata": {},
4238
"outputs": [],
4339
"source": [
4440
"from sklearn.naive_bayes import GaussianNB\n",
@@ -56,16 +52,31 @@
5652
{
5753
"cell_type": "code",
5854
"execution_count": 3,
59-
"metadata": {
60-
"collapsed": false
61-
},
55+
"metadata": {},
6256
"outputs": [
57+
{
58+
"name": "stderr",
59+
"output_type": "stream",
60+
"text": [
61+
"/opt/conda/lib/python3.6/site-packages/sklearn/cross_validation.py:44: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.\n",
62+
" \"This module will be removed in 0.20.\", DeprecationWarning)\n",
63+
"/opt/conda/lib/python3.6/site-packages/sklearn/grid_search.py:43: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. This module will be removed in 0.20.\n",
64+
" DeprecationWarning)\n",
65+
"100%|██████████| 3/3 [00:00<00:00, 8405.42it/s]"
66+
]
67+
},
6368
{
6469
"name": "stdout",
6570
"output_type": "stream",
6671
"text": [
67-
"Classifying...\n",
68-
"[##########] 100%\n"
72+
"Classifying...\n"
73+
]
74+
},
75+
{
76+
"name": "stderr",
77+
"output_type": "stream",
78+
"text": [
79+
"\n"
6980
]
7081
}
7182
],
@@ -85,14 +96,12 @@
8596
{
8697
"cell_type": "code",
8798
"execution_count": 4,
88-
"metadata": {
89-
"collapsed": false
90-
},
99+
"metadata": {},
91100
"outputs": [
92101
{
93102
"data": {
94103
"text/plain": [
95-
"array([ 0.63252944, 0.63061157, 0.68145715])"
104+
"array([ 0.63538912, 0.6304816 , 0.67899716])"
96105
]
97106
},
98107
"execution_count": 4,
@@ -120,10 +129,8 @@
120129
},
121130
{
122131
"cell_type": "code",
123-
"execution_count": 5,
124-
"metadata": {
125-
"collapsed": false
126-
},
132+
"execution_count": 4,
133+
"metadata": {},
127134
"outputs": [],
128135
"source": [
129136
"import pandas as pd\n",
@@ -168,9 +175,7 @@
168175
{
169176
"cell_type": "code",
170177
"execution_count": 8,
171-
"metadata": {
172-
"collapsed": false
173-
},
178+
"metadata": {},
174179
"outputs": [
175180
{
176181
"name": "stderr",
@@ -204,9 +209,7 @@
204209
{
205210
"cell_type": "code",
206211
"execution_count": 9,
207-
"metadata": {
208-
"collapsed": false
209-
},
212+
"metadata": {},
210213
"outputs": [
211214
{
212215
"data": {
@@ -226,9 +229,7 @@
226229
{
227230
"cell_type": "code",
228231
"execution_count": 10,
229-
"metadata": {
230-
"collapsed": false
231-
},
232+
"metadata": {},
232233
"outputs": [
233234
{
234235
"data": {
@@ -278,9 +279,7 @@
278279
{
279280
"cell_type": "code",
280281
"execution_count": 11,
281-
"metadata": {
282-
"collapsed": false
283-
},
282+
"metadata": {},
284283
"outputs": [
285284
{
286285
"name": "stdout",
@@ -324,9 +323,7 @@
324323
{
325324
"cell_type": "code",
326325
"execution_count": 15,
327-
"metadata": {
328-
"collapsed": false
329-
},
326+
"metadata": {},
330327
"outputs": [
331328
{
332329
"data": {
@@ -347,9 +344,7 @@
347344
{
348345
"cell_type": "code",
349346
"execution_count": 16,
350-
"metadata": {
351-
"collapsed": false
352-
},
347+
"metadata": {},
353348
"outputs": [
354349
{
355350
"data": {
@@ -370,9 +365,7 @@
370365
{
371366
"cell_type": "code",
372367
"execution_count": 17,
373-
"metadata": {
374-
"collapsed": false
375-
},
368+
"metadata": {},
376369
"outputs": [
377370
{
378371
"data": {
@@ -404,23 +397,23 @@
404397
],
405398
"metadata": {
406399
"kernelspec": {
407-
"display_name": "Python 2",
400+
"display_name": "Python 3",
408401
"language": "python",
409-
"name": "python2"
402+
"name": "python3"
410403
},
411404
"language_info": {
412405
"codemirror_mode": {
413406
"name": "ipython",
414-
"version": 2
407+
"version": 3
415408
},
416409
"file_extension": ".py",
417410
"mimetype": "text/x-python",
418411
"name": "python",
419412
"nbconvert_exporter": "python",
420-
"pygments_lexer": "ipython2",
421-
"version": "2.7.11"
413+
"pygments_lexer": "ipython3",
414+
"version": "3.6.8"
422415
}
423416
},
424417
"nbformat": 4,
425-
"nbformat_minor": 0
418+
"nbformat_minor": 1
426419
}

requirements.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
-e git://github.com/neurosynth/neurosynth.git#egg=neurosynth
1+
neurosynth
22
nibabel==1.3.0
3-
numpy
3+
nilearn==0.3.1
4+
matplotlib==2.0
45
joblib
56
pandas
6-
nilearn
77
seaborn
8+
scikit-learn==0.17
9+
tqdm

tools.py

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,6 @@
11
from sys import stdout
22
import numpy as np
33

4-
class ProgressBar():
5-
"""" Custom Progress Bar used during classification process """
6-
def __init__(self, total, start=False):
7-
"""
8-
total - total number of events
9-
start - automatically start when created?
10-
"""
11-
self.total = total
12-
self.current = 0.0
13-
self.last_int = 0
14-
if start:
15-
self.next()
16-
17-
def update_progress(self, progress):
18-
display = '\r[{0}] {1}%'.format('#' * (progress / 10), progress)
19-
stdout.write(display)
20-
stdout.flush()
21-
22-
def next(self):
23-
""" Increment progress bar"""
24-
if not self.last_int == int((self.current) / self.total * 100):
25-
self.update_progress(int((self.current) / self.total * 100))
26-
self.last_int = int((self.current) / self.total * 100)
27-
28-
if self.current == self.total:
29-
self.reset()
30-
else:
31-
self.current = self.current + 1
32-
33-
def reset(self):
34-
print ""
35-
self.current = 0.0
36-
374
def mask_diagonal(masked_array):
385
""" Given a masked array, it returns the same array with the diagonals masked"""
396
if len(masked_array.shape) == 3:
@@ -45,4 +12,4 @@ def mask_diagonal(masked_array):
4512
*map(np.arange, masked_array.shape), indexing='ij')
4613
masked_array.mask = (i == j)
4714

48-
return masked_array
15+
return masked_array

0 commit comments

Comments
 (0)