Skip to content

Commit

Permalink
changed naming convention to bids: structural:diff, functional:func, …
Browse files Browse the repository at this point in the history
…anatomical:anat
  • Loading branch information
arefks committed Nov 15, 2023
1 parent 788e6fb commit 1d2749a
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 66 deletions.
72 changes: 36 additions & 36 deletions scripts/FeatureCheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ def CheckingRawFeatures(Path):
Names =[]
for file in glob.glob(os.path.join(Path, '*addreses*.csv')) :

if "anatomical" in file :
if "anat" in file :
t2w_path= file
t2w_addreses= pd.read_csv(t2w_path)
Abook.append(t2w_addreses)
Names.append("anatomical")
Names.append("anat")

elif "structural" in file:
elif "diff" in file:
dti_path= file
dti_addreses= pd.read_csv(dti_path)
Abook.append(dti_addreses)
Names.append("structural")
elif "functional" in file :
Names.append("diff")
elif "func" in file :
fmri_path= file
fmri_addreses= pd.read_csv(fmri_path)
Abook.append(fmri_addreses)
Names.append("functional")
Names.append("func")

ErorrList = []
saving_path = Path
Expand Down Expand Up @@ -156,7 +156,7 @@ def CheckingRawFeatures(Path):
GMetric = GoastCheck(input_file)


if N == 'anatomical':
if N == 'anat':

# Signal 2 noise ratio
snrCh = snrCalclualtor_chang(input_file)
Expand All @@ -168,7 +168,7 @@ def CheckingRawFeatures(Path):
snr_normal_vec.append(snr_normal)
snrCh_vec.append(snrCh)

elif N == 'structural':
elif N == 'diff':
# Signal 2 noise ratio
#print(tf)
snrCh = snrCalclualtor_chang(input_file)
Expand All @@ -183,7 +183,7 @@ def CheckingRawFeatures(Path):
snr_normal_vec.append(snr_normal)
snrCh_vec.append(snrCh)

elif N == 'functional':
elif N == 'func':
#temporal signal 2 noise ratio
#print(tf)
tSNR = TsnrCalclualtor(input_file)
Expand Down Expand Up @@ -214,31 +214,31 @@ def CheckingRawFeatures(Path):
df['Goasting'] = np.array(GMetric_vec)


if N == 'anatomical':
if N == 'anat':
df['SNR Chang'] = np.array(snrCh_vec)
df['SNR Normal'] = np.array(snr_normal_vec)

elif N == 'structural':
elif N == 'diff':
df['SNR Chang'] = np.array(snrCh_vec)
df['SNR Normal'] = np.array(snr_normal_vec)
df['Displacement factor (std of Mutual information)']=np.array(LMV_all)
#df['Maximal displacement']=AR[4]

elif N == "functional":
elif N == "func":
df['tSNR (Averaged Brain ROI)'] = np.array(tsnr_vec)
df['Displacement factor (std of Mutual information)']=np.array(LMV_all)
#df['Maximal displacement']=AR[4]

if N=="anatomical":
t2w_result= os.path.join(Path,"caculated_features_anatomical.csv")
if N=="anat":
t2w_result= os.path.join(Path,"caculated_features_anat.csv")
df.to_csv( t2w_result)

elif N=="structural":
dti_result= os.path.join(Path,"caculated_features_structural.csv")
elif N=="diff":
dti_result= os.path.join(Path,"caculated_features_diff.csv")
df.to_csv( dti_result)

elif N=="functional":
fmri_result= os.path.join(Path,"caculated_features_functional.csv")
elif N=="func":
fmri_result= os.path.join(Path,"caculated_features_func.csv")
df.to_csv(fmri_result)

if ErorrList:
Expand All @@ -258,21 +258,21 @@ def CheckingNiftiFeatures(Path):
Names =[]
for file in glob.glob(os.path.join(Path, '*addreses*.csv')) :

if "anatomical" in file :
if "anat" in file :
t2w_path= file
t2w_addreses= pd.read_csv(t2w_path)
Abook.append(t2w_addreses)
Names.append("anatomical")
elif "structural" in file:
Names.append("anat")
elif "diff" in file:
dti_path= file
dti_addreses= pd.read_csv(dti_path)
Abook.append(dti_addreses)
Names.append("structural")
elif "functional" in file :
Names.append("diff")
elif "func" in file :
fmri_path= file
fmri_addreses= pd.read_csv(fmri_path)
Abook.append(fmri_addreses)
Names.append("functional")
Names.append("func")

ErorrList = []
saving_path = os.path.dirname(Path)
Expand Down Expand Up @@ -360,7 +360,7 @@ def CheckingNiftiFeatures(Path):
SpatRes = ResCalculator(input_file)
GMetric = GoastCheck(input_file)

if N == "anatomical":
if N == "anat":
# Signal 2 noise ratio
snrCh = snrCalclualtor_chang(input_file)
snr_normal = snrCalclualtor_normal(input_file)
Expand All @@ -371,7 +371,7 @@ def CheckingNiftiFeatures(Path):
snr_normal_vec.append(snr_normal)
snrCh_vec.append(snrCh)

elif N == "structural":
elif N == "diff":
# Signal 2 noise ratio

snrCh = snrCalclualtor_chang(input_file)
Expand All @@ -385,7 +385,7 @@ def CheckingNiftiFeatures(Path):
snr_normal_vec.append(snr_normal)
snrCh_vec.append(snrCh)

elif N == "functional":
elif N == "func":
#temporal signal 2 noise ratio
tSNR = TsnrCalclualtor(input_file)
Final,Max_mov_between,GMV,LMV = Ismotion(input_file)
Expand Down Expand Up @@ -424,31 +424,31 @@ def CheckingNiftiFeatures(Path):



if N == "anatomical":
if N == "anat":
df['SNR Chang'] = np.array(snrCh_vec)
df['SNR Normal'] = np.array(snr_normal_vec)

elif N == "structural":
elif N == "diff":
df['SNR Chang'] = np.array(snrCh_vec)
df['SNR Normal'] = np.array(snr_normal_vec)
df['Displacement factor (std of Mutual information)']=np.array(LMV_all)
#df['Maximal displacement']=AR[4]

elif N == "functional":
elif N == "func":
df['tSNR (Averaged Brain ROI)'] = np.array(tsnr_vec)
df['Displacement factor (std of Mutual information)']=np.array(LMV_all)
#df['Maximal displacement']=AR[4]

if N=="anatomical":
t2w_result= os.path.join(Path,"caculated_features_anatomical.csv")
if N=="anat":
t2w_result= os.path.join(Path,"caculated_features_anat.csv")
df.to_csv( t2w_result)

elif N=="structural":
dti_result= os.path.join(Path,"caculated_features_structural.csv")
elif N=="diff":
dti_result= os.path.join(Path,"caculated_features_diff.csv")
df.to_csv( dti_result)

elif N=="functional":
fmri_result= os.path.join(Path,"caculated_features_functional.csv")
elif N=="func":
fmri_result= os.path.join(Path,"caculated_features_func.csv")
df.to_csv(fmri_result)

if ErorrList:
Expand Down
24 changes: 12 additions & 12 deletions scripts/ParsingData.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

#Types = ['Dti','EPI','RARE']
#Types_new = ['DTI','rsfMRI','T2w']
type_strs = ['structural', 'functional', 'anatomical']
type_strs = ['diff', 'func', 'anat']

if format_type == "raw":

Expand All @@ -111,7 +111,7 @@
ABook[type_strs[i]] = []


with ap.alive_bar(kall, title='Extracting T1 or T2 weighted, structural and functional sequences:'.upper(),length=10,stats = False,spinner= 'wait') as bar:
with ap.alive_bar(kall, title='Extracting T1 or T2 weighted, diff and func sequences:'.upper(),length=10,stats = False,spinner= 'wait') as bar:

for p in text_files: #filling the Address Book with wanted files

Expand Down Expand Up @@ -142,22 +142,22 @@
if DateTemp not in CheckDates:

if Flag_struct and not Flag_notAllowed:
ABook["structural"].append(os.path.dirname(p))
ABook["diff"].append(os.path.dirname(p))
C = C+1
elif Flag_func and not Flag_notAllowed:
ABook["functional"].append(os.path.dirname(p)) #I know it is totally confusing with EPI as the col name for the ABook but sadly EPI can also be a DTI scan
ABook["func"].append(os.path.dirname(p)) #I know it is totally confusing with EPI as the col name for the ABook but sadly EPI can also be a DTI scan
C = C+1
elif Flag_anat and not Flag_notAllowed and not Flag_epi: #T2Star EPIS are usually rsfmri scans
ABook["anatomical"].append(os.path.dirname(p))
ABook["anat"].append(os.path.dirname(p))
C = C+1
elif Flag_epi and not Flag_notAllowed:
TP = NameTemp[1]["ACQ_time_points"]
MF = NameTemp[1]["ACQ_n_movie_frames"]
if MF != len(TP):
ABook["functional"].append(os.path.dirname(p)) #I know it is totally confusing with EPI as the col name for the ABook but sadly EPI can also be a DTI scan
ABook["func"].append(os.path.dirname(p)) #I know it is totally confusing with EPI as the col name for the ABook but sadly EPI can also be a DTI scan
C = C+1
elif MF == len(TP):
ABook["structural"].append(os.path.dirname(p))
ABook["diff"].append(os.path.dirname(p))
C = C+1


Expand Down Expand Up @@ -272,11 +272,11 @@


if Flag_struct and not Flag_notAllowed:
ABook["structural"].append(i)
if Flag_func and not Flag_notAllowed:
ABook["functional"].append(i)
if Flag_anat and not Flag_notAllowed:
ABook["anatomical"].append(i)
ABook["diff"].append(i)
elif Flag_func and not Flag_notAllowed:
ABook["func"].append(i)
elif Flag_anat and not Flag_notAllowed:
ABook["anat"].append(i)

#saving in csv file
for n,type_str in enumerate(type_strs):
Expand Down
36 changes: 18 additions & 18 deletions scripts/QC.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,21 +438,21 @@ def QCPlot(Path):
Names =[]
for file in glob.glob(os.path.join(Path, '*caculated_features*.csv')) :

if "structural" in file:
if "diff" in file:
dti_path= file
dti_features= pd.read_csv(dti_path)
Abook.append(dti_features)
Names.append("structural")
elif "functional" in file:
Names.append("diff")
elif "func" in file:
fmri_path= file
fmri_features= pd.read_csv(fmri_path)
Abook.append(fmri_features)
Names.append("functional")
elif "anatomical" in file:
Names.append("func")
elif "anat" in file:
t2w_path= file
t2w_features= pd.read_csv(t2w_path)
Abook.append(t2w_features)
Names.append("anatomical")
Names.append("anat")

ST = []
COE = []
Expand Down Expand Up @@ -631,16 +631,16 @@ def ML(Path, format_type) :
result[N]= np.dstack((result[N][0], result[N][1],result[N][2],result[N][3]))
result[N]= result[N][0]
result[N]= pd.DataFrame(result[N], columns = ['One_class_SVM',' EllipticEnvelope','IsolationForest',"LocalOutlierFactor"])
if "structural" in csv:
dti=["structural"]*len(result[N])
if "diff" in csv:
dti=["diff"]*len(result[N])
result[N]["sequence_type"] = dti

elif "functional" in csv:
fmri=["functional"]*len(result[N])
elif "func" in csv:
fmri=["func"]*len(result[N])
result[N]["sequence_type"] = fmri

elif "anatomical" in csv :
t2w=["anatomical"]*len(result[N])
elif "anat" in csv :
t2w=["anat"]*len(result[N])
result[N]["sequence_type"] = t2w

result[N]["Pathes"] = address
Expand All @@ -662,21 +662,21 @@ def QCtable(Path, format_type):
Names =[]
for file in glob.glob(os.path.join(Path, '*caculated_features*.csv')) :

if "structural" in file:
if "diff" in file:
dti_path= file
dti_features= pd.read_csv(dti_path)
Abook.append(dti_features)
Names.append("structural")
elif "functional" in file :
Names.append("diff")
elif "func" in file :
fmri_path= file
fmri_features= pd.read_csv(fmri_path)
Abook.append(fmri_features)
Names.append("functional")
elif "anatomical" in file :
Names.append("func")
elif "anat" in file :
t2w_path= file
t2w_features= pd.read_csv(t2w_path)
Abook.append(t2w_features)
Names.append("anatomical")
Names.append("anat")



Expand Down

0 comments on commit 1d2749a

Please sign in to comment.