Mercurial > repos > bgruening > flexynesis
comparison flexynesis_plot.py @ 5:466b593fd87e draft default tip
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit 1afbaf45449e25238935e222f983da62392c067a
author | bgruening |
---|---|
date | Fri, 04 Jul 2025 14:57:40 +0000 |
parents | 525c661a7fdc |
children |
comparison
equal
deleted
inserted
replaced
4:1a5f8cedda43 | 5:466b593fd87e |
---|---|
212 | 212 |
213 | 213 |
214 def generate_dimred_plots(embeddings, matched_labels, args, output_dir, output_name_base): | 214 def generate_dimred_plots(embeddings, matched_labels, args, output_dir, output_name_base): |
215 """Generate dimensionality reduction plots""" | 215 """Generate dimensionality reduction plots""" |
216 | 216 |
217 # Parse target variables | 217 # Parse target values from comma-separated string |
218 target_vars = [var.strip() for var in args.target_variables.split(',')] | 218 if args.target_value: |
219 | 219 target_values = [val.strip() for val in args.target_value.split(',')] |
220 print(f"Generating {args.method.upper()} plots for {len(target_vars)} target variable(s): {', '.join(target_vars)}") | 220 else: |
221 # If no target values specified, use all unique variables | |
222 target_values = matched_labels['variable'].unique().tolist() | |
223 | |
224 print(f"Generating {args.method.upper()} plots for {len(target_values)} target variable(s): {', '.join(target_values)}") | |
221 | 225 |
222 # Check variables | 226 # Check variables |
223 available_vars = matched_labels['variable'].unique() | 227 available_vars = matched_labels['variable'].unique() |
224 missing_vars = [var for var in target_vars if var not in available_vars] | 228 missing_vars = [var for var in target_values if var not in available_vars] |
225 | 229 |
226 if missing_vars: | 230 if missing_vars: |
227 print(f"Warning: The following target variables were not found in the data: {', '.join(missing_vars)}") | 231 print(f"Warning: The following target variables were not found in the data: {', '.join(missing_vars)}") |
228 print(f"Available variables: {', '.join(available_vars)}") | 232 print(f"Available variables: {', '.join(available_vars)}") |
229 | 233 |
230 # Filter to only process available variables | 234 # Filter to only process available variables |
231 valid_vars = [var for var in target_vars if var in available_vars] | 235 valid_vars = [var for var in target_values if var in available_vars] |
232 | 236 |
233 if not valid_vars: | 237 if not valid_vars: |
234 raise ValueError(f"None of the specified target variables were found in the data. Available: {', '.join(available_vars)}") | 238 raise ValueError(f"None of the specified target variables were found in the data. Available: {', '.join(available_vars)}") |
235 | 239 |
236 # Generate plots for each valid target variable | 240 # Generate plots for each valid target variable |
987 # Arguments for dimensionality reduction | 991 # Arguments for dimensionality reduction |
988 parser.add_argument("--embeddings", type=str, | 992 parser.add_argument("--embeddings", type=str, |
989 help="Path to input data embeddings file (CSV or tabular format). Required for dimred plots.") | 993 help="Path to input data embeddings file (CSV or tabular format). Required for dimred plots.") |
990 parser.add_argument("--method", type=str, default='pca', choices=['pca', 'umap'], | 994 parser.add_argument("--method", type=str, default='pca', choices=['pca', 'umap'], |
991 help="Transformation method ('pca' or 'umap'). Default is 'pca'. Used for dimred plots.") | 995 help="Transformation method ('pca' or 'umap'). Default is 'pca'. Used for dimred plots.") |
992 parser.add_argument("--target_variables", type=str, required=False, | |
993 help="Comma-separated list of target variables to plot.") | |
994 | 996 |
995 # Arguments for Kaplan-Meier | 997 # Arguments for Kaplan-Meier |
996 parser.add_argument("--survival_data", type=str, | 998 parser.add_argument("--survival_data", type=str, |
997 help="Path to survival data file with columns: duration and event. Required for kaplan_meier plots.") | 999 help="Path to survival data file with columns: duration and event. Required for kaplan_meier plots.") |
998 parser.add_argument("--surv_time_var", type=str, required=False, | 1000 parser.add_argument("--surv_time_var", type=str, required=False, |
1022 parser.add_argument("--n_splits", type=int, default=5, | 1024 parser.add_argument("--n_splits", type=int, default=5, |
1023 help="Number of folds for cross-validation. Default is 5") | 1025 help="Number of folds for cross-validation. Default is 5") |
1024 parser.add_argument("--random_state", type=int, default=42, | 1026 parser.add_argument("--random_state", type=int, default=42, |
1025 help="Random seed for reproducibility. Default is 42") | 1027 help="Random seed for reproducibility. Default is 42") |
1026 | 1028 |
1027 # Arguments for scatter plot, heatmap, PR curves, ROC curves, and box plots | 1029 # Arguments for dimred, scatter plot, heatmap, PR curves, ROC curves, and box plots |
1028 parser.add_argument("--target_value", type=str, default=None, | 1030 parser.add_argument("--target_value", type=str, default=None, |
1029 help="Target value for scatter plot.") | 1031 help="Target value for scatter plot.") |
1030 | 1032 |
1031 # Common arguments | 1033 # Common arguments |
1032 parser.add_argument("--output_dir", type=str, default='output', | 1034 parser.add_argument("--output_dir", type=str, default='output', |
1055 raise FileNotFoundError(f"embeddings file not found: {args.embeddings}") | 1057 raise FileNotFoundError(f"embeddings file not found: {args.embeddings}") |
1056 if not args.labels: | 1058 if not args.labels: |
1057 raise ValueError("--labels is required for dimensionality reduction plots") | 1059 raise ValueError("--labels is required for dimensionality reduction plots") |
1058 if not args.method: | 1060 if not args.method: |
1059 raise ValueError("--method is required for dimensionality reduction plots") | 1061 raise ValueError("--method is required for dimensionality reduction plots") |
1060 if not args.target_variables: | |
1061 raise ValueError("--target_variables is required for dimensionality reduction plots") | |
1062 | 1062 |
1063 if args.plot_type in ['kaplan_meier']: | 1063 if args.plot_type in ['kaplan_meier']: |
1064 if not args.survival_data: | 1064 if not args.survival_data: |
1065 raise ValueError("--survival_data is required when plot_type is 'kaplan_meier'") | 1065 raise ValueError("--survival_data is required when plot_type is 'kaplan_meier'") |
1066 if not os.path.isfile(args.survival_data): | 1066 if not os.path.isfile(args.survival_data): |