Skip to content

Commit 4e42295

Browse files
committed
tested on various methods
1 parent 3998107 commit 4e42295

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

Snakefile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -389,22 +389,21 @@ rule evaluation:
389389
ensemble_file=lambda wildcards: f"{out_dir}{SEP}{get_dataset_label(wildcards)}-ml{SEP}ensemble-pathway.txt",
390390
pca_coordinates_file =lambda wildcards: f"{out_dir}{SEP}{get_dataset_label(wildcards)}-ml{SEP}pca-coordinates.txt"
391391
output:
392-
pr_file = SEP.join([out_dir, '{dataset_gold_standard_pairs}-eval', "precision-recall-per-pathway.txt"]),
393-
pr_png = SEP.join([out_dir, '{dataset_gold_standard_pairs}-eval', 'precision-recall-per-pathway.png']),
392+
pr_node_file = SEP.join([out_dir, '{dataset_gold_standard_pairs}-eval', "precision-recall-per-pathway.txt"]),
393+
pr_node_png = SEP.join([out_dir, '{dataset_gold_standard_pairs}-eval', 'precision-recall-per-pathway.png']),
394394
pr_edge_file = SEP.join([out_dir, '{dataset_gold_standard_pairs}-eval', "precision-recall-per-pathway_edge.txt"]),
395395
pr_edge_png = SEP.join([out_dir, '{dataset_gold_standard_pairs}-eval', 'precision-recall-per-pathway_edge.png']),
396396
pr_curve_png = SEP.join([out_dir, '{dataset_gold_standard_pairs}-eval', 'precision-recall-curve-ensemble-nodes.png']),
397397
pca_chosen_pr_file = SEP.join([out_dir, '{dataset_gold_standard_pairs}-eval', "precision-recall-pca-chosen-pathway.txt"]),
398398
run:
399399
node_table = Evaluation.from_file(input.gold_standard_file).node_table
400400
edge_table = Evaluation.from_file(input.gold_standard_file).edge_table
401-
Evaluation.precision_and_recall(input.pathways, node_table, algorithms, output.pr_file, output.pr_png)
401+
Evaluation.precision_and_recall_node(input.pathways, node_table, algorithms, output.pr_node_file, output.pr_node_png)
402402
Evaluation.precision_and_recall_edge(input.pathways, edge_table, algorithms, output.pr_edge_file, output.pr_edge_png)
403403
node_ensemble = Evaluation.edge_frequency_node_ensemble(input.ensemble_file)
404404
Evaluation.precision_recall_curve_node_ensemble(node_ensemble, node_table, output.pr_curve_png)
405405
pca_chosen_pathway = Evaluation.pca_chosen_pathway(input.pca_coordinates_file, out_dir)
406-
Evaluation.precision_and_recall(pca_chosen_pathway, node_table, algorithms, output.pca_chosen_pr_file)
407-
# Evaluation.precision_and_recall_edge(pca_chosen_pathway, edge_table, algorithms, output.pca_chosen_pr_file)
406+
Evaluation.precision_and_recall_node(pca_chosen_pathway, node_table, algorithms, output.pca_chosen_pr_file)
408407

409408

410409
# Returns all pathways for a specific algorithm and dataset
@@ -431,9 +430,13 @@ rule evaluation_per_algo_pathways:
431430
output:
432431
pr_file = SEP.join([out_dir, '{dataset_gold_standard_pairs}-eval', "{algorithm}-precision-recall-per-pathway.txt"]),
433432
pr_png = SEP.join([out_dir, '{dataset_gold_standard_pairs}-eval', '{algorithm}-precision-recall-per-pathway.png']),
433+
pr_edge_file = SEP.join([out_dir, '{dataset_gold_standard_pairs}-eval', "{algorithm}-precision-recall-per-pathway_edge.txt"]),
434+
pr_edge_png = SEP.join([out_dir, '{dataset_gold_standard_pairs}-eval', '{algorithm}-precision-recall-per-pathway_edge.png']),
434435
run:
435436
node_table = Evaluation.from_file(input.gold_standard_file).node_table
436-
Evaluation.precision_and_recall(input.pathways, node_table, algorithms, output.pr_file, output.pr_png)
437+
Evaluation.precision_and_recall_node(input.pathways, node_table, algorithms, output.pr_file, output.pr_png)
438+
edge_table = Evaluation.from_file(input.gold_standard_file).edge_table
439+
Evaluation.precision_and_recall_edge(input.pathways, edge_table, algorithms, output.pr_edge_file, output.pr_edge_png)
437440

438441
rule evaluation_per_algo_ensemble_pr_curve:
439442
input:
@@ -455,7 +458,7 @@ rule evaluation_per_algo_pca_chosen:
455458
run:
456459
node_table = Evaluation.from_file(input.gold_standard_file).node_table
457460
pca_chosen_pathway = Evaluation.pca_chosen_pathway(input.pca_coordinates_file, out_dir)
458-
Evaluation.precision_and_recall(pca_chosen_pathway, node_table, algorithms, output.pca_chosen_pr_file)
461+
Evaluation.precision_and_recall_node(pca_chosen_pathway, node_table, algorithms, output.pca_chosen_pr_file)
459462

460463
# Remove the output directory
461464
rule clean:

config/synthetic.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ container_registry:
4545
algorithms:
4646
- name: "pathlinker"
4747
params:
48-
include: false
48+
include: true
4949
run1:
5050
k: range(100,201,100)
5151

@@ -69,26 +69,26 @@ algorithms:
6969

7070
- name: "meo"
7171
params:
72-
include: false
72+
include: true
7373
run1:
7474
max_path_length: [3]
7575
local_search: ["Yes"]
7676
rand_restarts: [10]
7777

7878
- name: "mincostflow"
7979
params:
80-
include: false
80+
include: true
8181
run1:
8282
flow: [1] # The flow must be an int
8383
capacity: [1]
8484

8585
- name: "allpairs"
8686
params:
87-
include: false
87+
include: true
8888

8989
- name: "domino"
9090
params:
91-
include: false
91+
include: true
9292
run1:
9393
slice_threshold: [0.3]
9494
module_threshold: [0.05]

spras/evaluation.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ def load_files_from_dict(self, gold_standard_dict: Dict):
8484
@staticmethod
8585
def precision_and_recall_edge(file_paths: Iterable[Path], edge_table: pd.DataFrame, algorithms: list, output_file: str, output_png:str=None):
8686
"""
87-
Takes in file paths for a specific dataset and an associated gold standard node table.
87+
Takes in file paths for a specific dataset and an associated gold standard edge table.
8888
Calculates precision and recall for each pathway file
8989
Returns output back to output_file
9090
@param file_paths: file paths of pathway reconstruction algorithm outputs
91-
@param node_table: the gold standard nodes
91+
@param edge_table: the gold standard edges
9292
@param algorithms: list of algorithms used in current run of SPRAS
9393
@param output_file: the filename to save the precision and recall of each pathway
9494
@param output_png (optional): the filename to plot the precision and recall of each pathway (not a PRC)
@@ -99,17 +99,12 @@ def precision_and_recall_edge(file_paths: Iterable[Path], edge_table: pd.DataFra
9999
results = []
100100
for file in file_paths:
101101
df = pd.read_table(file, sep="\t", header=0, usecols=["Node1", "Node2"])
102-
print(file)
103-
print(df)
104102
y_pred = set()
105103
for row in df.itertuples():
106104
y_pred.add((row[1], row[2]))
107105
all_edges = set(gs_edges.union(y_pred))
108106
y_true_binary = [1 if (edge[0], edge[1]) in gs_edges or (edge[1], edge[0]) in gs_edges else 0 for edge in all_edges]
109107
y_pred_binary = [1 if (edge[0], edge[1]) in y_pred or (edge[1], edge[0]) in y_pred else 0 for edge in all_edges]
110-
111-
# # default to 0.0 if there is a divide by 0 error
112-
# # not using precision_recall_curve because thresholds are binary (0 or 1); rather we are directly calculating precision and recall per pathway
113108
precision = precision_score(y_true_binary, y_pred_binary, zero_division=0.0)
114109
recall = recall_score(y_true_binary, y_pred_binary, zero_division=0.0)
115110
results.append({"Pathway": file, "Precision": precision, "Recall": recall})
@@ -152,7 +147,7 @@ def precision_and_recall_edge(file_paths: Iterable[Path], edge_table: pd.DataFra
152147
plt.savefig(output_png)
153148

154149
@staticmethod
155-
def precision_and_recall(file_paths: Iterable[Path], node_table: pd.DataFrame, algorithms: list, output_file: str, output_png:str=None):
150+
def precision_and_recall_node(file_paths: Iterable[Path], node_table: pd.DataFrame, algorithms: list, output_file: str, output_png:str=None):
156151
"""
157152
Takes in file paths for a specific dataset and an associated gold standard node table.
158153
Calculates precision and recall for each pathway file

0 commit comments

Comments
 (0)