-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge from Haji's fork into main fork #125
base: analysis
Are you sure you want to change the base?
Changes from all commits
233ee58
6e1c456
90d848b
eb0dd7a
c9bcae5
a4acd3f
6d20697
c8d7813
2ae6b5c
d9b187c
b404ad3
529989f
f89d59f
ed3ff6d
5a1dcc6
21384d1
18e2251
3d4a3c5
8e8c0a1
f18597d
70b8763
4fb58f7
c8c5436
e6e3f14
0dd057a
bd510e3
27a97cd
a4768c1
2dfc506
82c4a3b
492f593
d33ea47
adbd5b4
70cf9de
096f571
0d40d9a
3d01075
936c818
ad82147
46b0b9b
ce30c2c
a4be221
f6b406f
5476c43
f8a0933
a0dfee8
c8fc036
eebd087
3210e85
0bbda24
e1b1b5a
b2a57dd
0de299d
39fbd64
2b419a3
dee6543
61fa87d
baf3b7a
75f9d3b
94f16b5
9be3d57
9bc6610
254a13c
e556dac
d2fe7c4
9325aaa
ff67066
3048bca
811c349
db5048d
4e4d38b
c20e8da
c8461a4
2af4368
1d13c4c
fff3d7d
b3a8bdf
3479171
2512f21
e693e5c
30b8f57
03e3bff
eda9ab7
37e8b13
b6dcf24
c9f8f6f
85dfcb1
2f414b0
5ebf1db
f1893e4
e300cf7
0775684
e9d3649
a4d784f
d01533a
eefab1d
651259d
6e2a874
8c8d481
8a7dd81
350309f
55f6436
56fe7bf
4dd339b
51e7782
423f9a5
bdc33f3
5cebc08
268b3d3
780980c
9604f10
c5b400b
ed0bbdd
67dd5f7
98010de
64ae5a3
71eb4c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import os | ||
import sys | ||
import numpy as np | ||
import pandas as pd | ||
import matplotlib as mpl | ||
configfile: | ||
"config.json" | ||
os.environ['HCPANNOT_LOAD_PATH'] = config['CACHE_DIR'] | ||
|
||
# The cache directories: | ||
from visualization import * | ||
RATERS = ['BrendaQiu', 'bogengsong', 'JiyeongHa', 'lindazelinzhao', 'nourahboujaber', 'jennifertepan'] | ||
ROIS = ['hV4', 'VO1', 'VO2'] | ||
HEMIS = ['lh','rh'] | ||
|
||
|
||
rule get_subj_ids_for_rater: | ||
output: | ||
subj_ids = os.path.join(config['CACHE_DIR'], 'subj_ids', "rater-{rater}_hemi-{hemi}_roi-{roi}.txt") | ||
params: | ||
trace_save_path = config['OUTPUT_DIR'] | ||
run: | ||
subj_ids = viscontours.get_trace_list_drawn_by_rater(params.trace_save_path, wildcards.hemi, wildcards.roi, wildcards.rater) | ||
with open(output.subj_ids,'w') as fp: | ||
for item in subj_ids: | ||
# write each item on a new line | ||
fp.write("%s," % item) | ||
|
||
rule save_trace_cache: | ||
output: | ||
os.path.join(config['PROC_DIR'],'fsaverage', "{rater}", "{sid}", "{hemi}.roi-{roi}_space-fsaverage_npoints-{n_points}.mgz") | ||
params: | ||
data_dir = config['DATA_DIR'], | ||
proc_dir = config['PROC_DIR'] | ||
run: | ||
x, y = viscontours.make_fsaverage_coords(rater=wildcards.rater, | ||
hemi=wildcards.hemi, | ||
roi=wildcards.roi, | ||
subject=int(wildcards.sid), | ||
n_points=int(wildcards.n_points), | ||
data_dir=params.data_dir, | ||
proc_dir=params.proc_dir, | ||
save_path=output[0]) | ||
|
||
|
||
def get_subj_ids(wildcards, all=False): | ||
if all is False: | ||
subj_ids = viscontours.get_trace_list_drawn_by_rater(config['TRACE_DIR'], | ||
wildcards.hemi, | ||
wildcards.roi, | ||
wildcards.rater) | ||
else: | ||
import neuropythy as ny | ||
subj_ids = ny.data['hcp_lines'].subject_list | ||
return subj_ids | ||
|
||
|
||
rule all: | ||
input: | ||
lambda wildcards: expand(os.path.join(config['PROC_DIR'],'fsaverage', "{rater}", "{sid}", "{hemi}.roi-{roi}_space-fsaverage_npoints-{n_points}.mgz"), rater=['JiyeongHa', 'BrendaQiu'], hemi=HEMIS, roi=ROIS, sid=get_subj_ids(wildcards, all=True), n_points=[500]) | ||
|
||
|
||
def convert_txt_to_list(wildcards): | ||
text_file = os.path.join(config['PATH_SAVE_DIR'], f"rater-{wildcards.rater}_hemi-{wildcards.hemi}_roi-{wildcards.roi}.txt") | ||
with open(text_file,'r') as fp: | ||
fd_list = fp.read().split(',') | ||
return fd_list[:-1] | ||
|
||
def get_trace_file_names(wildcards, all): | ||
ids_list = get_subj_ids(wildcards, all) | ||
all_files = [] | ||
for sid in ids_list: | ||
f = os.path.join(config['PATH_SAVE_DIR'], f"contour-path_space-fsaverage_rater-{wildcards.rater}_sid-{sid}_hemi-{wildcards.hemi}_roi-{wildcards.roi}_npoints-{wildcards.n_points}.mgz") | ||
all_files.append(f) | ||
return all_files | ||
|
||
|
||
rule save_hcp_subject_list: | ||
input: | ||
all_files = lambda wildcards: get_trace_file_names(wildcards, all=True) | ||
output: | ||
os.path.join(config['OUTPUT_DIR'], "subject_list", "hcp_subject_list.txt") | ||
run: | ||
import neuropythy as ny | ||
test = ny.data['hcp_lines'].subject_list | ||
with open(output[0],'w') as f: | ||
f.write('\n'.join(str(i) for i in test)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"CACHE_DIR": "/Volumes/server/Projects/annot-vc/hcpannot-cache", | ||
"DATA_DIR": "/Volumes/server/Projects/annot-vc/data_branch/save", | ||
"PROC_DIR": "/Volumes/server/Projects/annot-vc/derivatives/proc", | ||
"OUTPUT_DIR": "/Volumes/server/Projects/annot-vc/derivatives" | ||
} |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
import os, json | ||
from collections.abc import Mapping | ||
from pathlib import Path | ||
|
||
import pandas | ||
import numpy as np | ||
import neuropythy as ny | ||
|
||
|
@@ -929,23 +929,26 @@ def load_report(region, rater, sid, h, reports_path=None): | |
except Exception as e: | ||
pass | ||
return data | ||
|
||
def load_allreports(region, | ||
reports_path=None, | ||
include_mean=True, | ||
sids=subject_list): | ||
sids=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
if sids is None:
sids = subject_list |
||
"""Loads all reports for a region and returns a dataframe of them. | ||
|
||
This runs `load_report` over all raters, subjects, and hemispheres and | ||
returns a dataframe of all the reports. If a report file is not found, | ||
then the row is left with NaNs indicating missing data. | ||
""" | ||
from .config import raters_by_region | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! |
||
|
||
if include_mean: | ||
if include_mean == True: | ||
include_mean = 'mean' | ||
include_mean = [include_mean] | ||
else: | ||
include_mean = [] | ||
raters = (region_raters[region] + include_mean) | ||
raters = (raters_by_region[region] + include_mean) | ||
return pandas.DataFrame( | ||
[load_report(region, rater, sid, h, reports_path=reports_path) | ||
for rater in raters | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how this got here, but not needed.