Mercurial > repos > bgruening > flexynesis
annotate flexynesis_utils.py @ 3:0a8fe19cebeb draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
| author | bgruening | 
|---|---|
| date | Tue, 24 Jun 2025 05:56:31 +0000 | 
| parents | |
| children | 9450286c42ab | 
| rev | line source | 
|---|---|
| 
3
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
1 #!/usr/bin/env python | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
2 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
3 import argparse | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
4 import os | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
5 import sys | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
6 from pathlib import Path | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
7 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
8 import pandas as pd | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
9 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
10 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
11 def read_data(data_input, index=False): | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
12 """Load CSV or TSV data file.""" | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
13 try: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
14 file_ext = Path(data_input).suffix.lower() | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
15 sep = ',' if file_ext == '.csv' else '\t' | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
16 index_col = 0 if index else None | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
17 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
18 if file_ext in ['.csv', '.tsv', '.txt', '.tab', '.tabular']: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
19 return pd.read_csv(data_input, sep=sep, index_col=index_col) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
20 else: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
21 raise ValueError(f"Unsupported file extension: {file_ext}") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
22 except Exception as e: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
23 raise ValueError(f"Error loading data from {data_input}: {e}") from e | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
24 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
25 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
26 def binarize_mutations(df, gene_idx=1, sample_idx=2): | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
27 """ | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
28 Binarize mutation data by creating a matrix of gene x sample with 1/0 values. | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
29 """ | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
30 # galaxy index is 1-based, convert to zero-based | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
31 gene_idx -= 1 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
32 sample_idx -= 1 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
33 # check idx | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
34 if gene_idx >= len(df.columns) or sample_idx >= len(df.columns): | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
35 raise ValueError(f"Column indices out of bounds. DataFrame has {len(df.columns)} columns, " | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
36 f"but requested indices are {gene_idx} and {sample_idx}") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
37 if gene_idx == sample_idx: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
38 raise ValueError("Gene and sample column indices must be different") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
39 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
40 # Get column names by index | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
41 gene_col = df.columns[gene_idx] | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
42 print(f"Using gene column: {gene_col} (index {gene_idx})") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
43 sample_col = df.columns[sample_idx] | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
44 print(f"Using sample column: {sample_col} (index {sample_idx})") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
45 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
46 # Check if columns contain data | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
47 if df[gene_col].isna().all(): | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
48 raise ValueError(f"Gene column (index {gene_idx}) contains only NaN values.") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
49 if df[sample_col].isna().all(): | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
50 raise ValueError(f"Sample column (index {sample_idx}) contains only NaN values.") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
51 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
52 # Group by gene and sample, count mutations | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
53 mutation_counts = df.groupby([gene_col, sample_col]).size().reset_index(name='count') | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
54 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
55 # Create pivot table | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
56 mutation_matrix = mutation_counts.pivot(index=gene_col, columns=sample_col, values='count').fillna(0) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
57 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
58 # Binarize: convert any count > 0 to 1 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
59 mutation_matrix[mutation_matrix > 0] = 1 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
60 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
61 return mutation_matrix | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
62 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
63 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
64 def make_data_dict(clin_path, omics_paths): | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
65 """Read clinical and omics data files into a dictionary.""" | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
66 data = {} | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
67 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
68 # Read clinical data | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
69 print(f"Reading clinical data from {clin_path}") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
70 try: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
71 clin = read_data(clin_path, index=True) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
72 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
73 if clin.empty: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
74 raise ValueError(f"Clinical file {clin_path} is empty") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
75 data['clin'] = clin | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
76 print(f"Loaded clinical data: {clin.shape[0]} samples, {clin.shape[1]} features") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
77 except Exception as e: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
78 raise ValueError(f"Error reading clinical file {clin_path}: {e}") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
79 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
80 # Read omics data | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
81 print(f"Reading omics data from {', '.join(omics_paths)}") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
82 for path in omics_paths: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
83 try: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
84 name = os.path.splitext(os.path.basename(path))[0] | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
85 df = read_data(path, index=True) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
86 if df.empty: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
87 print(f"Warning: Omics file {path} is empty, skipping") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
88 continue | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
89 data[name] = df | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
90 print(f"Loaded {name}: {df.shape[0]} features, {df.shape[1]} samples") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
91 except Exception as e: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
92 print(f"Warning: Error reading omics file {path}: {e}") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
93 continue | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
94 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
95 if len(data) == 1: # Only clinical data loaded | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
96 raise ValueError("No omics data was successfully loaded") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
97 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
98 return data | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
99 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
100 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
101 def validate_data_consistency(data): | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
102 """Validate that clinical and omics data have consistent samples.""" | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
103 clin_samples = set(data['clin'].index) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
104 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
105 for name, df in data.items(): | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
106 if name == 'clin': | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
107 continue | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
108 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
109 omics_samples = set(df.columns) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
110 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
111 # Check for sample overlap | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
112 common_samples = clin_samples.intersection(omics_samples) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
113 if len(common_samples) == 0: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
114 raise ValueError(f"No common samples between clinical data and {name}") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
115 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
116 missing_in_omics = clin_samples - omics_samples | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
117 missing_in_clin = omics_samples - clin_samples | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
118 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
119 if missing_in_omics: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
120 print(f"Warning: {len(missing_in_omics)} clinical samples not found in {name}") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
121 if missing_in_clin: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
122 print(f"Warning: {len(missing_in_clin)} samples in {name} not found in clinical data") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
123 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
124 return True | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
125 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
126 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
127 def split_and_save_data(data, ratio=0.7, output_dir='.'): | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
128 """Split data into train/test sets and save to files.""" | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
129 # Validate data consistency first | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
130 validate_data_consistency(data) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
131 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
132 samples = data['clin'].index.tolist() | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
133 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
134 train_samples = list(pd.Series(samples).sample(frac=ratio, random_state=42)) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
135 test_samples = list(set(samples) - set(train_samples)) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
136 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
137 train_data = {} | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
138 test_data = {} | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
139 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
140 for key, df in data.items(): | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
141 try: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
142 if key == 'clin': | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
143 train_data[key] = df.loc[df.index.intersection(train_samples)] | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
144 test_data[key] = df.loc[df.index.intersection(test_samples)] | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
145 else: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
146 train_data[key] = df.loc[:, df.columns.intersection(train_samples)] | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
147 test_data[key] = df.loc[:, df.columns.intersection(test_samples)] | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
148 except Exception as e: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
149 print(f"Error splitting data {key}: {e}") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
150 continue | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
151 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
152 # Create output directories | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
153 os.makedirs(os.path.join(output_dir, 'train'), exist_ok=True) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
154 os.makedirs(os.path.join(output_dir, 'test'), exist_ok=True) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
155 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
156 # Save train and test data | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
157 for key in data.keys(): | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
158 try: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
159 train_data[key].to_csv(os.path.join(output_dir, 'train', f'{key}.csv')) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
160 test_data[key].to_csv(os.path.join(output_dir, 'test', f'{key}.csv')) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
161 except Exception as e: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
162 print(f"Error saving {key}: {e}") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
163 continue | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
164 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
165 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
166 def main(): | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
167 parser = argparse.ArgumentParser(description='Flexynesis extra utilities') | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
168 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
169 parser.add_argument("--util", type=str, required=True, | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
170 choices=['split', 'binarize'], | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
171 help="Utility function: 'split' for spiting data to train and test, 'binarize' for creating a binarized matrix from a mutation data") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
172 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
173 # Arguments for split | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
174 parser.add_argument('--clin', required=False, | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
175 help='Path to clinical data CSV file (samples in rows)') | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
176 parser.add_argument('--omics', required=False, | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
177 help='Comma-separated list of omics CSV files (samples in columns)') | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
178 parser.add_argument('--split', type=float, default=0.7, | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
179 help='Train split ratio (default: 0.7)') | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
180 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
181 # Arguments for binarize | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
182 parser.add_argument('--mutations', type=str, required=False, | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
183 help='Path to mutation data CSV file (samples in rows, genes in columns)') | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
184 parser.add_argument('--gene_idx', type=int, default=0, | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
185 help='Column index for genes in mutation data (default: 0)') | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
186 parser.add_argument('--sample_idx', type=int, default=1, | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
187 help='Column index for samples in mutation data (default: 1)') | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
188 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
189 # common arguments | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
190 parser.add_argument('--out', default='.', | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
191 help='Output directory (default: current directory)') | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
192 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
193 args = parser.parse_args() | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
194 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
195 try: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
196 # validate utility function | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
197 if not args.util: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
198 raise ValueError("Utility function must be specified") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
199 if args.util not in ['split', 'binarize']: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
200 raise ValueError(f"Invalid utility function: {args.util}") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
201 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
202 if args.util == 'split': | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
203 # Validate inputs | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
204 if not args.clin: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
205 raise ValueError("Clinical data file must be provided") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
206 if not args.omics: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
207 raise ValueError("At least one omics file must be provided") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
208 if not os.path.isfile(args.clin): | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
209 raise FileNotFoundError(f"Clinical file not found: {args.clin}") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
210 # Validate split ratio | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
211 if not 0 < args.split < 1: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
212 raise ValueError(f"Split ratio must be between 0 and 1, got {args.split}") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
213 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
214 elif args.util == 'binarize': | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
215 # Validate mutation data file | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
216 if not args.mutations: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
217 raise ValueError("Mutation data file must be provided") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
218 if not os.path.isfile(args.mutations): | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
219 raise FileNotFoundError(f"Mutation data file not found: {args.mutations}") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
220 # Validate gene and sample indices | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
221 if args.gene_idx < 0 or args.sample_idx < 0: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
222 raise ValueError("Gene and sample indices must be non-negative integers") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
223 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
224 # Create output directory if it doesn't exist | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
225 if not os.path.exists(args.out): | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
226 os.makedirs(args.out) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
227 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
228 if args.util == 'split': | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
229 # Parse omics files | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
230 omics_files = [f.strip() for f in args.omics.split(',') if f.strip()] | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
231 if not omics_files: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
232 raise ValueError("At least one omics file must be provided") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
233 # Check omics files exist | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
234 for f in omics_files: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
235 if not os.path.isfile(f): | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
236 raise FileNotFoundError(f"Omics file not found: {f}") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
237 data = make_data_dict(args.clin, omics_files) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
238 split_and_save_data(data, ratio=args.split, output_dir=args.out) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
239 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
240 elif args.util == 'binarize': | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
241 mutations_df = read_data(args.mutations, index=False) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
242 if mutations_df.empty: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
243 raise ValueError("Mutation data file is empty") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
244 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
245 binarized_matrix = binarize_mutations(mutations_df, gene_idx=args.gene_idx, sample_idx=args.sample_idx) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
246 # Save binarized matrix | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
247 output_file = os.path.join(args.out, 'binarized_mutations.csv') | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
248 binarized_matrix.to_csv(output_file) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
249 print(f"Binarized mutation matrix saved to {output_file}") | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
250 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
251 except Exception as e: | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
252 print(f"Error: {e}", file=sys.stderr) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
253 sys.exit(1) | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
254 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
255 | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
256 if __name__ == "__main__": | 
| 
 
0a8fe19cebeb
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/flexynesis commit b2463fb68d0ae54864d87718ee72f5e063aa4587
 
bgruening 
parents:  
diff
changeset
 | 
257 main() | 
