Skip to content

Commit

Permalink
only one iteration of propagation, alpha fixed by PPI network edge nu…
Browse files Browse the repository at this point in the history
…mber
  • Loading branch information
0m1n0 committed Dec 5, 2019
1 parent 8737509 commit 705b98a
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 54 deletions.
30 changes: 17 additions & 13 deletions stratipy/filtering_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def propagation(M, adj, alpha, tol=10e-6): # TODO equation, M, alpha
adj : sparse matrix
Adjacency matrice.
alpha : float, default: 0.7
alpha : float
Diffusion/propagation factor with 0 <= alpha <= 1.
For alpha = 0 : no diffusion.
For alpha = 1 :
Expand All @@ -76,13 +76,16 @@ def propagation(M, adj, alpha, tol=10e-6): # TODO equation, M, alpha

X1 = M.astype(np.float32)
X2 = alpha * X1.dot(A) + (1-alpha) * M
i = 0
while norm(X2-X1) > tol:
X1 = X2
X2 = alpha * X1.dot(A) + (1-alpha) * M
i += 1
print(' Propagation iteration = {} ----- {}'.format(
i, datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")))

if tol:
i = 0
while norm(X2-X1) > tol:
X1 = X2
X2 = alpha * X1.dot(A) + (1-alpha) * M
i += 1
print(' Propagation iteration = {} ----- {}'.format(
i, datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")),
flush=True)
return X2


Expand Down Expand Up @@ -151,9 +154,9 @@ def compare_ij_ji(ppi, out_min=True, out_max=True):


# @profile
def calcul_final_influence(M, adj, result_folder, influence_weight='min',
def calcul_final_influence(M, adj, result_folder, alpha, influence_weight='min',
simplification=True, compute=False, overwrite=False,
alpha=0.7, tol=10e-6):
tol=10e-6):
"""Compute network influence score
Network propagation iterative process is applied on PPI. (1) The network
Expand Down Expand Up @@ -197,7 +200,7 @@ def calcul_final_influence(M, adj, result_folder, influence_weight='min',
If True, new network influence score will be computed even if the file
which same parameters already exists in the directory.
alpha : float, default: 0.7
alpha : float
Diffusion (propagation) factor with 0 <= alpha <= 1.
For alpha = 0 : no diffusion.
For alpha = 1 :
Expand All @@ -224,7 +227,7 @@ def calcul_final_influence(M, adj, result_folder, influence_weight='min',

existance_same_param = os.path.exists(final_influence_file)
# TODO overwrite condition

print("+++++", final_influence_file)
# check if same parameters file exists in directory
if existance_same_param:
final_influence_data = loadmat(final_influence_file)
Expand All @@ -239,6 +242,7 @@ def calcul_final_influence(M, adj, result_folder, influence_weight='min',
if compute:
# check if influence distance file exists
existance_same_influence = os.path.exists(influence_distance_file)
print("+++++", influence_distance_file)
if existance_same_influence:
influence_data = loadmat(influence_distance_file)
influence = influence_data['influence_distance']
Expand Down Expand Up @@ -496,7 +500,7 @@ def filtering(ppi_filt, result_folder, influence_weight, simplification,
keep_singletons, min_mutation, max_mutation, mut_type):
final_influence = (calcul_final_influence(
sp.eye(ppi_filt.shape[0], dtype=np.float32), ppi_filt, result_folder,
influence_weight, simplification, compute, overwrite, alpha, tol))
alpha, influence_weight, simplification, compute, overwrite, tol))

ppi_final, mut_final = filter_ppi_patients(
result_folder, influence_weight, simplification, alpha, tol, ppi_total,
Expand Down
91 changes: 50 additions & 41 deletions stratipy/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,54 @@


# TODO PPI type param
param_grid = {'data_folder': ['../data/'],
'patient_data': ['SSC'],
'ssc_mutation_data': ['MAF50_LoF_mis15'],
# 'ssc_subgroups': ['SSC1_probands', 'SSC1_siblings',
# 'SSC2_probands', 'SSC2_siblings'],
'ssc_subgroups': ['SSC1', 'SSC2'],
# 'ssc_subgroups': ['SSC1'],
# 'ssc_subgroups': ['SSC1', 'SSC2'],
# 'ssc_subgroups': ['SSC', 'SSC1', 'SSC2'],
# 'gene_data': ['all', 'pli', 'sfari', 'brain1SD', 'brain2SD'],
'gene_data': ['all', 'BrainSfariPli'],
'ppi_data': ['APID', 'STRING'],
# 'ppi_data': ['STRING'],
'influence_weight': ['min'],
'simplification': [True],
'compute': [True],
'overwrite': [False],
'alpha': [0.3],
'tol': [10e-3],
'ngh_max': [11],
'keep_singletons': [False],
'min_mutation': [0],
'max_mutation': [20000],
'mut_type': ['raw', 'diff', 'mean_qn', 'median_qn'],
# 'n_components': [2],
'n_components': range(2, 51),
# 'n_permutations': [1000],
'n_permutations': [300],
'sub_perm': [1],
'run_bootstrap': ['split'],
# 'run_bootstrap': ['full', 'split', None],
'run_consensus': [True],
'lambd': [0],
# 'lambd': [200],
# 'lambd': [0, 200],
'tol_nmf': [1e-3],
'compute_gene_clustering': [True],
'linkage_method': ['average'],
'p_val_threshold': [0.05]
param_grid = {
'mut_type': ['raw', 'propagated', 'mean_qn', 'median_qn'],
# 'mut_type': ['raw'],

'ppi_data': ['APID', 'STRING'],
# 'ppi_data': ['STRING'],

# 'n_components': [2],
'n_components': range(2, 21),

# 'ssc_subgroups': ['SSC1_probands', 'SSC1_siblings', 'SSC2_probands', 'SSC2_siblings'],
# 'ssc_subgroups': ['SSC1', 'SSC2'],
'ssc_subgroups': ['SSC_all', 'SSC_male', 'SSC_female'],
# 'ssc_subgroups': ['SSC', 'SSC1', 'SSC2', 'SSC_all', 'SSC_male', 'SSC_female'],

# 'gene_data': ['all', 'pli', 'sfari', 'brain1SD', 'brain2SD'],
'gene_data': ['allGenes'],

'ssc_mutation_data': ['MAF1_LoF_mis15'],
# 'ssc_mutation_data': ['MAF1_LoF_mis30'],

'sub_perm': [1],
# 'run_bootstrap': ['split'],
'run_bootstrap': ['full'],

'lambd': [0],
# 'lambd': [200],
# 'lambd': [0, 200],

'data_folder': ['../data/'],
'patient_data': ['SSC'],
'influence_weight': ['min'],
'simplification': [True],
'compute': [True],
'overwrite': [False],
# 'alpha': [0.7],
'tol': [10e-3],
'ngh_max': [11],
'keep_singletons': [False],
'min_mutation': [0],
'max_mutation': [20000],
# 'n_permutations': [1000],
'n_permutations': [300],
'run_consensus': [True],
'tol_nmf': [1e-3],
'compute_gene_clustering': [True],
'linkage_method': ['average'],
'p_val_threshold': [0.05]
}


Expand All @@ -65,7 +74,7 @@ def get_params(i):
compute = d.get('compute')
overwrite = d.get('overwrite')

alpha = d.get('alpha')
# alpha = d.get('alpha')
tol = d.get('tol')
ngh_max = d.get('ngh_max')
keep_singletons = d.get('keep_singletons')
Expand All @@ -90,7 +99,7 @@ def get_params(i):

return (data_folder, patient_data, ssc_mutation_data, ssc_subgroups,
gene_data, ppi_data, influence_weight, simplification, compute,
overwrite, alpha, tol, ngh_max, keep_singletons, min_mutation,
overwrite, tol, ngh_max, keep_singletons, min_mutation,
max_mutation, mut_type, n_components, n_permutations, sub_perm, sub_perm,
run_bootstrap, run_consensus, lambd, tol_nmf,
compute_gene_clustering, linkage_method, p_val_threshold)

0 comments on commit 705b98a

Please sign in to comment.