Universe normalizes an interaction source into the DataFrame schema consumed
by Network. Built-in adapters cover OmniPath, SIGNOR, HuRI, and
PhosphoSitePlus; a custom DataFrame can be supplied directly.
def__init__(self,resources:Literal['omnipath']|pd.DataFrame=None,**param):""" Load and preprocess a generic network from databases or files. """self._resources={}self._directed={}self._resource=resourcesself.interactions=Noneself.add_resources(resources,**param)self.build()
@staticmethoddefmerge(df1:pd.DataFrame,df2:pd.DataFrame)->pd.DataFrame:""" This function concatenates the provided df with the existing one in the resources object, aligning columns and filling in missing data with NaN. Parameters: df1 (pd.DataFrame): The DataFrame to be added. df2 (pd.DataFrame): The DataFrame to be added. Raises: ValueError: If the 'df' parameter is not a pandas DataFrame. Returns: None """# Align columns of both dataframes, filling missing columns with NaNall_columns=set(df1.columns).union(set(df2.columns))df1=df1.reindex(columns=all_columns,fill_value=None)df2=df2.reindex(columns=all_columns,fill_value=None)df1=pd.concat([df1,df2])returndf1.copy()
defcheck(self)->bool:""" The network is loaded and contains the mandatory variables. """return(hasattr(self,'_network')andnot_REQUIRED_COLS-set(self._network.columns))
Generic networks from databases, files and standard formats.
Args:
resource:
Name of the resource or a ready data frame to bypass the built-in
loading method.
kwargs:
Passed to the source specific method. See the specific methods in
this module for details.
Note: currently OmniPath PPI is the single available option and serves
as a placeholder. Later we will dispatch all inputs through this API.
defnetwork_universe(resource:Literal['omnipath']|pd.DataFrame='omnipath',**kwargs)->Universe:""" Generic networks from databases, files and standard formats. Args: resource: Name of the resource or a ready data frame to bypass the built-in loading method. kwargs: Passed to the source specific method. See the specific methods in this module for details. Note: currently OmniPath PPI is the single available option and serves as a placeholder. Later we will dispatch all inputs through this API. """returnUniverse(resource,**kwargs)
defsignor(path:str|None=None,**kwargs)->Universe:# A missing legacy path falls back to NeKo's validated SIGNOR cache. The# adapter downloads and populates that cache only when it has no usable# cached release.ifpathandos.path.exists(path):returnUniverse(_signor.signor(path,**kwargs))else:ifpath:logging.warning('SIGNOR path does not exist: %s. Falling back to the ''managed NeKo cache.',os.path.abspath(path),)returnUniverse(_signor.signor(**kwargs))