11from pathlib import Path
2+ from typing import Optional
23
34import pandas as pd
5+ from pydantic import BaseModel , ConfigDict
46
57from spras .config .container_schema import ProcessedContainerSettings
68from spras .containers import prepare_volume , run_container_and_log
1113from spras .prm import PRM
1214from spras .util import add_rank_column , duplicate_edges , raw_pathway_df
1315
14- __all__ = ["TieDIE" ]
16+ __all__ = ["TieDIE" , "TieDIEParams" ]
1517
16- class TieDIE (PRM ):
18+ class TieDIEParams (BaseModel ):
19+ s : float = 1
20+ """Network size control factor"""
21+
22+ d_expr : Optional [str ] = None
23+ """List of significantly differentially expressed genes,
24+ along with log-FC or FC values (i.e. by edgeR for RNA-Seq or SAM for microarray data.)
25+ Generated by a sample-dichotomy of interest."""
26+
27+ a : Optional [float ] = None
28+ """Linker Cutoff (overrides the Size factor)"""
29+
30+ c : int = 3
31+ """Search depth for causal paths"""
32+
33+ p : int = 1000
34+ """Number of random permutations performed for significance analysis"""
35+
36+ pagerank : bool = False
37+ """Use Personalized PageRank to Diffuse """
38+
39+ all_paths : bool = False
40+ """Use all paths instead of only causal paths"""
41+
42+ model_config = ConfigDict (extra = 'forbid' , use_attribute_docstrings = True )
43+
44+ class TieDIE (PRM [TieDIEParams ]):
1745 # we need edges (weighted), source set (with prizes), and target set (with prizes).
1846 required_inputs = ["edges" , "sources" , "targets" ]
1947 dois = ["10.1093/bioinformatics/btt471" ]
@@ -24,6 +52,9 @@ def generate_inputs(data, filename_map):
2452 Access fields from the dataset and write the required input files
2553 @param data: dataset
2654 @param filename_map: a dict mapping file types in the required_inputs to the filename for that type
55+ - source: input node types with sources (required)
56+ - target: input node types with targets (required)
57+ - edges: input edges file (required)
2758 """
2859 # ensures the required input are within the filename_map
2960 for input_type in TieDIE .required_inputs :
@@ -62,39 +93,22 @@ def generate_inputs(data, filename_map):
6293
6394 # Skips parameter validation step
6495 @staticmethod
65- def run (edges = None , sources = None , targets = None , output_file = None , s : float = 1.0 , c : int = 3 , p : int = 1000 , pagerank : bool = False , all_paths : bool = False , container_settings = None ):
66- """
67- Run TieDIE with Docker
68- @param source: input node types with sources (required)
69- @param target: input node types with targets (required)
70- @param edges: input edges file (required)
71- @param output_file: path to the output pathway file (required)
72- @param s: Network size control factor (optional) (default 1)
73- @param d_expr: List of significantly differentially expressed genes, along with log-FC or FC values (i.e. by edgeR for RNA-Seq or SAM for microarray data.) Generated by a sample-dichotomy of interest. (optional)
74- @param a: Linker Cutoff (overrides the Size factor) (optional)
75- @param c: Search depth for causal paths (optional) (default 3)
76- @param p: Number of random permutations performed for significance analysis (optional) (default 1000)
77- @param pagerank: Use Personalized PageRank to Diffuse (optional)
78- @param all_paths: Use all paths instead of only causal paths (optional) (default False)
79- @param singularity: if True, run using the Singularity container instead of the Docker container
80- """
81-
96+ def run (inputs , output_file , args = None , container_settings = None ):
97+ if not args : args = TieDIEParams ()
8298 if not container_settings : container_settings = ProcessedContainerSettings ()
83- if not edges or not sources or not targets or not output_file :
84- raise ValueError ("Required TieDIE arguments are missing" )
8599
86100 work_dir = "/spras"
87101
88102 # Each volume is a tuple (src, dest) - data generated by Docker
89103 volumes = list ()
90104
91- bind_path , edges_file = prepare_volume (edges , work_dir , container_settings )
105+ bind_path , edges_file = prepare_volume (inputs [ " edges" ] , work_dir , container_settings )
92106 volumes .append (bind_path )
93107
94- bind_path , sources_file = prepare_volume (sources , work_dir , container_settings )
108+ bind_path , sources_file = prepare_volume (inputs [ " sources" ] , work_dir , container_settings )
95109 volumes .append (bind_path )
96110
97- bind_path , targets_file = prepare_volume (targets , work_dir , container_settings )
111+ bind_path , targets_file = prepare_volume (inputs [ " targets" ] , work_dir , container_settings )
98112 volumes .append (bind_path )
99113
100114 out_dir = Path (output_file ).parent
@@ -110,11 +124,11 @@ def run(edges=None, sources=None, targets=None, output_file=None, s: float = 1.0
110124 "--up_heats" , sources_file ,
111125 "--down_heats" , targets_file ,
112126 "--network" , edges_file ,
113- "--size" , str (s ),
114- "--depth" , str (c ),
115- "--permute" , str (p ),
116- "--pagerank" , "True" if pagerank else "False" ,
117- "--all_paths" , "False" if all_paths else "False" ,
127+ "--size" , str (args . s ),
128+ "--depth" , str (args . c ),
129+ "--permute" , str (args . p ),
130+ "--pagerank" , "True" if args . pagerank else "False" ,
131+ "--all_paths" , "False" if args . all_paths else "False" ,
118132 "--output_folder" , mapped_out_dir ,
119133 ]
120134
0 commit comments