Skip to content

Commit 0f9bd3a

Browse files
committed
feat: process input data more pythonically
1 parent 3cc9bec commit 0f9bd3a

1 file changed

Lines changed: 8 additions & 27 deletions

File tree

main/como/proteomics_gen.py

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,15 @@
1515
# Load Proteomics
1616
def process_proteomics_data(path: Path) -> pd.DataFrame:
1717
"""Load proteomics data from a given context and filename."""
18-
config = Config()
19-
data_path = config.data_dir / "data_matrices" / context_name / datafilename
20-
logger.info(f"Data Matrix Path: {data_path}")
21-
22-
if data_path.exists():
23-
proteomics_data = pd.read_csv(data_path, header=0)
24-
else:
25-
logger.error(f"Error: file not found: {data_path}")
26-
27-
return None
28-
2918
# Preprocess data, drop na, duplicate ';' in symbol,
30-
proteomics_data["gene_symbol"] = proteomics_data["gene_symbol"].astype(str)
31-
proteomics_data.dropna(subset=["gene_symbol"], inplace=True)
32-
pluralnames = proteomics_data[proteomics_data["gene_symbol"].str.contains(";") == True] # noqa: E712
33-
34-
for idx, row in pluralnames.iterrows():
35-
names = row["gene_symbol"].split(";")
36-
rows = []
37-
38-
for name in names:
39-
rowcopy = row.copy()
40-
rowcopy["gene_symbol"] = name
41-
rows.append(rowcopy)
42-
proteomics_data.drop(index=idx, inplace=True)
43-
proteomics_data = pd.concat([proteomics_data, pd.DataFrame(rows)], ignore_index=True)
44-
45-
return proteomics_data
19+
matrix: pd.DataFrame = pd.read_csv(path)
20+
if "gene_symbol" not in matrix.columns:
21+
raise ValueError("No gene_symbol column found in proteomics data.")
22+
23+
matrix["gene_symbol"] = matrix["gene_symbol"].astype(str)
24+
matrix.dropna(subset=["gene_symbol"], inplace=True)
25+
matrix = matrix.assign(gene_symbol=matrix["gene_symbol"].str.split(";")).explode("gene_symbol")
26+
return matrix
4627

4728

4829
# read map to convert to entrez

0 commit comments

Comments
 (0)