File size: 7,490 Bytes
264e00c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
"""Path configuration utilities for GEOAgent."""
from abc import ABC, abstractmethod
from dataclasses import dataclass
class PathConfig(ABC):
"""Abstract base class for path configurations used in data analysis."""
@abstractmethod
def get_setup_code(self) -> str:
"""Generate Python code for setting up paths in the CodeExecutor namespace."""
pass
@abstractmethod
def get_setup_prompt(self) -> str:
"""Generate the path setup section for the prompt."""
pass
@dataclass
class GEOPathConfig(PathConfig):
"""Container for all path configurations used in preprocessing GEO data."""
# Context identifiers
trait: str
cohort: str
# Input paths
in_trait_dir: str
in_cohort_dir: str
# Output paths
out_data_file: str
out_gene_data_file: str
out_clinical_data_file: str
json_path: str
def get_setup_code(self) -> str:
"""Generate Python code for setting up paths in the CodeExecutor namespace."""
return f"""# Path Configuration
from tools.preprocess import *
# Processing context
trait = "{self.trait}"
cohort = "{self.cohort}"
# Input paths
in_trait_dir = "{self.in_trait_dir}"
in_cohort_dir = "{self.in_cohort_dir}"
# Output paths
out_data_file = "{self.out_data_file}"
out_gene_data_file = "{self.out_gene_data_file}"
out_clinical_data_file = "{self.out_clinical_data_file}"
json_path = "{self.json_path}"
"""
def get_setup_prompt(self) -> str:
"""Generate the path setup section for the prompt."""
return f"""
1. Path Configuration
The following variables have been pre-configured in your execution environment,
to maintain consistent file organization:
Context Variables:
- trait: "{self.trait}"
The current trait being processed.
Use this instead of hardcoding the trait name in your code.
- cohort: "{self.cohort}"
The current cohort being processed.
Use this instead of hardcoding the cohort name.
Input Paths:
- in_trait_dir: "{self.in_trait_dir}"
The directory containing raw data of all cohorts for the current trait.
- in_cohort_dir: "{self.in_cohort_dir}"
The directory containing raw data for the current cohort.
Output Paths:
- out_data_file: "{self.out_data_file}"
Where to save the processed linked data.
- out_gene_data_file: "{self.out_gene_data_file}"
Where to save the processed gene expression data.
- out_clinical_data_file: "{self.out_clinical_data_file}"
Where to save the processed clinical data.
- json_path: "{self.json_path}"
Where to save cohort metadata about data usability and quality.
2. Pre-executed Setup Code
The following code has been automatically executed to prepare your environment.
All functions from tools.preprocess have been imported and are ready to use.
You can use these variables and functions directly in your code without importing or defining them.
```python
{self.get_setup_code()}```
"""
@dataclass
class TCGAPathConfig(PathConfig):
"""Container for all path configurations used in preprocessing TCGA data."""
# Context identifiers
trait: str
# Input paths
tcga_root_dir: str
# Output paths
out_data_file: str
out_gene_data_file: str
out_clinical_data_file: str
json_path: str
def get_setup_code(self) -> str:
"""Generate Python code for setting up paths in the CodeExecutor namespace."""
return f"""# Path Configuration
from tools.preprocess import *
# Processing context
trait = "{self.trait}"
# Input paths
tcga_root_dir = "{self.tcga_root_dir}"
# Output paths
out_data_file = "{self.out_data_file}"
out_gene_data_file = "{self.out_gene_data_file}"
out_clinical_data_file = "{self.out_clinical_data_file}"
json_path = "{self.json_path}"
"""
def get_setup_prompt(self) -> str:
"""Generate the path setup section for the prompt."""
return f"""
1. Path Configuration
The following variables have been pre-configured in your execution environment,
to maintain consistent file organization:
Context Variables:
- trait: "{self.trait}"
The current trait being processed.
Use this instead of hardcoding the trait name in your code.
Input Paths:
- tcga_root_dir: "{self.tcga_root_dir}"
The root directory of the TCGA Xena dataset.
Output Paths:
- out_data_file: "{self.out_data_file}"
Where to save the processed linked data.
- out_gene_data_file: "{self.out_gene_data_file}"
Where to save the processed gene expression data.
- out_clinical_data_file: "{self.out_clinical_data_file}"
Where to save the processed clinical data.
- json_path: "{self.json_path}"
Where to save cohort metadata about data usability and quality.
2. Pre-executed Setup Code
The following code has been automatically executed to prepare your environment.
All functions from tools.preprocess have been imported and are ready to use.
You can use these variables and functions directly in your code without importing or defining them.
```python
{self.get_setup_code()}```
"""
# TO DO: for statistician
"""
Setups:
1. All input data are stored in the directory: '{data_root}'.
2. The output should be saved to the directory '{output_root}', under a subdirectory named after the trait.
3. External knowledge about genes related to each trait is available in a file '{gene_info_path}'.
"""
@dataclass
class StatisticianPathConfig(PathConfig):
"""Container for all path configurations used in Statistical analysis."""
# Context identifiers
trait: str
condition: str
# Input paths
in_data_root: str
gene_info_file: str
# Output paths
output_root: str
def get_setup_code(self) -> str:
"""Generate Python code for setting up paths in the CodeExecutor namespace."""
condition_str = "None" if self.condition is None else f'"{self.condition}"'
return f"""# Path Configuration
from tools.statistics import *
from sklearn.linear_model import LogisticRegression, LinearRegression
# Processing context
trait = "{self.trait}"
condition = {condition_str}
# Input paths
in_data_root = "{self.in_data_root}"
gene_info_file = "{self.gene_info_file}"
# Output paths
output_root = "{self.output_root}"
"""
def get_setup_prompt(self) -> str:
"""Generate the path setup section for the prompt."""
condition_str = "None" if self.condition is None else f'"{self.condition}"'
return f"""
1. Path Configuration
The following variables have been pre-configured in your execution environment,
to maintain consistent file organization:
Context Variables:
- trait: "{self.trait}"
The trait in the current question being addressed.
Use this instead of hardcoding the trait name in your code.
- condition: {condition_str}
The condition in the current question being addressed.
Use this instead of hardcoding the condition name.
Input Paths:
- in_data_root: "{self.in_data_root}"
The directory containing all the preprocessed data for statistical analysis.
- gene_info_file: "{self.gene_info_file}"
The file containing external knowledge about genes related to each trait.
Output Paths:
- output_root: "{self.output_root}"
Where to save all the analysis results.
2. Pre-executed Setup Code
The following code has been automatically executed to prepare your environment.
All functions from tools.statistics have been imported and are ready to use.
You can use these variables and functions directly in your code without importing or defining them.
```python
{self.get_setup_code()}```
""" |