Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
tlooden committed Jul 24, 2019
1 parent 38fa0fc commit 50a41b1
Showing 1 changed file with 42 additions and 45 deletions.
87 changes: 42 additions & 45 deletions normmod_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ def threshmat(inputfile, threshold='fdr', variant='comb'):
# Combine both matrices and sum over edges to get one value per subject
combthreshmat=posthreshmat+negthreshmat
return combthreshmat


#%%

"""
For generating abnormality scores for each subject using extreme-value
statistics to retrieve the mean value of the top % of deviant edges.
"""

def EVD(process_dir):
thr=0.01
Z=np.loadtxt(process_dir)

m=Z.shape
l=np.int(m[0]*thr)

T=np.sort(np.abs(Z),axis=0)[m[0]-l:m[0],:]
E=scipy.stats.trim_mean(T, 0.1)
return E

#%%

Expand Down Expand Up @@ -131,7 +150,7 @@ def threshmat(inputfile, threshold='fdr', variant='comb'):

# For TD vs ASDadhd- vs ASDadhd+

threshold=2
threshold=1.96
variant='comb'


Expand Down Expand Up @@ -165,23 +184,7 @@ def threshmat(inputfile, threshold='fdr', variant='comb'):
else:
e=np.hstack([e,d])

#%%

"""
For generating abnormality scores for each subject using extreme-value
statistics to retrieve the mean value of the top % of deviant edges.
"""

def EVD(process_dir):
thr=0.01
Z=np.loadtxt(process_dir)

m=Z.shape
l=np.int(m[0]*thr)

T=np.sort(np.abs(Z),axis=0)[m[0]-l:m[0],:]
E=scipy.stats.trim_mean(T, 0.1)
return E


#%%
"""
Expand All @@ -190,16 +193,17 @@ def EVD(process_dir):
"""


Z=nispat.fileio.load('/project/3015045.07/norm_mod/leap_potency_abs_harm/flanker/crossval/Z.txt')
Z=nispat.fileio.load('/project/3015045.07/norm_mod/leap_potency_harm/flanker/crossval/Z.txt')

threshold=0.01
limit=np.int(m[0]*threshold)
m=Z.shape
limit=np.int(m[0]*threshold)


#preload matrix in which to enter the deviant indices.
A=np.zeros(m)

indices=np.argsort(np.abs(X),axis=0)
indices=np.argsort(np.abs(Z),axis=0)
A[np.where(indices<=limit)]=1

#put back into matrix form
Expand All @@ -208,11 +212,6 @@ def EVD(process_dir):
B[np.triu_indices(168,1)]=np.sum(A,1)
C=B.T+B


#%%

C=B.T+B

abn_region=np.sum(C,0)


Expand All @@ -236,8 +235,8 @@ def EVD(process_dir):
df_comb=pd.DataFrame(e.T, columns=[ 'diagnosis', 'task','% deviant edges'])

# Rename variables inside the dataframe to meaningful terms.
df_comb['task']=df_neg['task'].replace({0: 'flanker', 1: 'hariri', 2: 'reward_m', 3: 'reward_s', 4 : 'tom'})
df_comb['diagnosis']=df_neg['diagnosis'].replace({0: 'TD', 1: 'ASD', 2:'ASDadhd'})
df_comb['task']=df_comb['task'].replace({0: 'flanker', 1: 'hariri', 2: 'reward_m', 3: 'reward_s', 4 : 'tom'})
df_comb['diagnosis']=df_comb['diagnosis'].replace({0: 'TD', 1: 'ASD', 2:'ASDadhd'})

#%%

Expand All @@ -255,36 +254,34 @@ def EVD(process_dir):
sns.violinplot(x='task',y='% deviant edges', hue='diagnosis',split=False, inner="quartile", data=df_comb)
plt.legend(loc='lower right')

plt.savefig("/home/mrstats/triloo/Workspace/Images/norm_mod/normmod_comb3.pdf")
#plt.savefig("/home/mrstats/triloo/Workspace/Images/norm_mod/normmod_comb3.pdf")



#%%

"""
Generate a list of indexes for the subjects with high ADHD scores corresponding
to each of the tasks. Can use this in the normmod script to separate these
groups """
import sklearn.decomposition

matsub_all=np.load('/home/mrstats/triloo/Workspace/Analysis/Aggregate_potency_matrices/matsub_all.npy', allow_pickle=True)
matsub_ADHD=np.loadtxt('/home/mrstats/triloo/Workspace/LEAP_info/ASDadhd+.txt')
pca=sklearn.decomposition.PCA(n_components=5)
pca.fit(A.T)

adhd_subindex=[[]for i in range(5)]
print(pca.explained_variance_ratio_)
Acomponents=pca.components_


"""
multiply components with subject values for the edges. Then get 5 values per sub (loadings).
Then, clustering for the subjects on those values. can also check if loadings
correlate with symptom scores (eg ADHD)
for t in range(5):
for n,i in enumerate(matsub_ADHD):
i=str(int(i))

try:
adhd_subindex[t].append(matsub_all[0][t].index(i))
except:
pass

"""




0 comments on commit 50a41b1

Please sign in to comment.