Utility Functions

utils.data_parsing(DATA_PATH, MODALITIES, TARGET, INDEX_COL, PROCESSED=True)[source]

Parses multiple data modalities into a unified structure, handling metadata alignment and preprocessing steps.

Parameters:
  • DATA_PATH (str) – The directory path where the data files are stored.

  • MODALITIES (list) – A list of modality names to parse.

  • TARGET (str) – The column name in metadata that indicates the target or label.

  • INDEX_COL (str) – The column used as the index for merging and aligning data.

  • PROCESSED (bool, optional) – Whether to load processed or preprocessed data.

Returns:

A dictionary of DataFrames, one for each modality. pd.Series: Metadata series indexed by INDEX_COL and containing TARGET values.

Return type:

dict

utils.get_gpu_memory()[source]

Retrieves and prints the current GPU memory usage statistics including total, reserved, and allocated memory amounts.

Returns:

None

utils.indices_removal_adjust(idx_to_swap, all_idx, new_idx)[source]

Adjusts and filters indices after some have been removed, mapping old indices to new indices post-removal.

Parameters:
  • idx_to_swap (array-like) – Indices that potentially need adjustment after an update.

  • all_idx (pd.Index) – The complete set of original indices.

  • new_idx (array-like) – The updated list of indices after some removals.

Returns:

Adjusted indices reflecting the new index placement.

Return type:

np.array

utils.init_weights(m)[source]

Initializes weights for PyTorch layers within a model.

Parameters:

m (torch.nn.Module) – The model or layer to initialize.

Effects:

Applied in-situ: Adjusts the weights of the model passed based on the type of layer.

utils.merge_dfs(left_df, right_df)[source]

Merges two DataFrames on their indexes with an outer join method.

Parameters:
  • left_df (pd.DataFrame) – The left DataFrame to merge.

  • right_df (pd.DataFrame) – The right DataFrame to merge.

Returns:

The resulting DataFrame after merging.

Return type:

pd.DataFrame

utils.network_from_csv(NETWORK_PATH, no_psn, weighted=False)[source]

Constructs a NetworkX graph from a CSV file containing network data.

Parameters:
  • NETWORK_PATH (str) – The file path to the CSV containing the network data.

  • no_psn (bool) – If True, performs special handling specific to pseudonetworks.

  • weighted (bool) – Indicates if the network edges should consider weights (true for weighted edges).

Returns:

The constructed NetworkX graph.

Return type:

nx.Graph