Mercurial > repos > bimib > cobraxy
comparison COBRAxy/utils/general_utils.py @ 427:4a385fdb9e58 draft
Uploaded
author | francesco_lapi |
---|---|
date | Wed, 10 Sep 2025 11:38:08 +0000 |
parents | ed2c1f9e20ba |
children | a6e45049c1b9 |
comparison
equal
deleted
inserted
replaced
426:00a78da611ba | 427:4a385fdb9e58 |
---|---|
502 | 502 |
503 Returns: | 503 Returns: |
504 List[List[str]] : list of rows from the file, each parsed as a list of strings originally separated by commas. | 504 List[List[str]] : list of rows from the file, each parsed as a list of strings originally separated by commas. |
505 """ | 505 """ |
506 with open(path.show(), "r", newline = "") as fd: return list(csv.reader(fd, delimiter = delimiter))[skipHeader:] | 506 with open(path.show(), "r", newline = "") as fd: return list(csv.reader(fd, delimiter = delimiter))[skipHeader:] |
507 | |
508 def findIdxByName(header: List[str], name: str, colName="name") -> Optional[int]: | |
509 """ | |
510 Find the indices of the 'ReactionID' column and a user-specified column name | |
511 within the header row of a tabular file. | |
512 | |
513 Args: | |
514 header (List[str]): The header row, as a list of column names. | |
515 name (str): The name of the column to look for (e.g. 'GPR'). | |
516 colName (str, optional): Label used in error messages for clarity. Defaults to "name". | |
517 | |
518 Returns: | |
519 Tuple[int, int]: A tuple containing: | |
520 - The index of the 'ReactionID' column. | |
521 - The index of the requested column `name`. | |
522 | |
523 Raises: | |
524 ValueError: If 'ReactionID' or the requested column `name` is not found in the header. | |
525 | |
526 Notes: | |
527 Both 'ReactionID' and the requested column are mandatory for downstream processing. | |
528 """ | |
529 | |
530 col_index = {col_name: idx for idx, col_name in enumerate(header)} | |
531 | |
532 if name not in col_index or "ReactionID" not in col_index: | |
533 raise ValueError(f"Tabular file must contain 'ReactionID' and {name} columns.") | |
534 | |
535 id_idx = col_index["ReactionID"] | |
536 idx_gpr = col_index[name] | |
537 | |
538 return id_idx, idx_gpr | |
539 | |
507 | 540 |
508 def readSvg(path :FilePath, customErr :Optional[Exception] = None) -> ET.ElementTree: | 541 def readSvg(path :FilePath, customErr :Optional[Exception] = None) -> ET.ElementTree: |
509 """ | 542 """ |
510 Reads the contents of a .svg file, which needs to exist at the given path. | 543 Reads the contents of a .svg file, which needs to exist at the given path. |
511 | 544 |