def test_invalid_organism(self, cache_backup, requests_mock, tsv_data: bytes): url = urljoin(options.url, Enzsub._query_type.endpoint) requests_mock.register_uri( "GET", f"{url}?fields=curation_effort%2Creferences%2Csources&format=tsv", content=tsv_data, ) with pytest.raises( ValueError, match=r"Invalid value `foobarbaz` for `Organism`. Valid options are:", ): Enzsub.get(organism="foobarbaz") assert not requests_mock.called_once
def test_no_dtype_conversion(self, cache_backup, requests_mock, tsv_data: bytes): url = urljoin(options.url, Enzsub._query_type.endpoint) options.convert_dtypes = False requests_mock.register_uri( "GET", f"{url}?fields=curation_effort%2Creferences%2Csources&format=tsv", content=tsv_data, ) res = Enzsub.get() assert is_object_dtype(res["modification"]) options.convert_dtypes = True res = Enzsub.get() assert is_categorical_dtype(res["modification"]) assert requests_mock.called_once
def test_field_injection(self, cache_backup, requests_mock, tsv_data: bytes): url = urljoin(options.url, Enzsub._query_type.endpoint) requests_mock.register_uri( "GET", f"{url}?fields=Alpha%2Cbeta%2Ccuration_effort%2Creferences%2Csources&format=tsv", content=tsv_data, ) _ = Enzsub.get(fields=("beta", "Alpha", "Alpha")) assert requests_mock.called_once
def test_genesymbols_dont_matter( self, cache_backup, requests_mock, tsv_data: bytes ): url = urljoin(options.url, Enzsub._query_type.endpoint) requests_mock.register_uri( "GET", f"{url}?fields=curation_effort%2Creferences%2Csources&format=tsv", content=tsv_data, ) _ = Enzsub.get(genesymbol=True) assert requests_mock.called_once
def get( cls, ptms: Optional[pd.DataFrame] = None, interactions: Optional[pd.DataFrame] = None, ) -> pd.DataFrame: """ Get signs for enzyme-PTM interactions. Parameters ---------- ptms Data generated by :meth:`omnipath.requests.Enzsub.get`. If `None`, a new request will be performed. interactions Data generated by :meth:`omnipath.interactions.OmniPath.get`. If `None`, a new request will be performed. Returns ------- :class:`pandas.DataFrame` The signed PTMs with columns **'is_inhibition'** and **'is_stimulation'**. """ from omnipath.requests import Enzsub from omnipath.interactions import OmniPath ptms = Enzsub.get() if ptms is None else ptms interactions = OmniPath.get() if interactions is None else interactions if not isinstance(ptms, pd.DataFrame): raise TypeError( f"Expected `ptms` to be of type `pandas.DataFrame`, found `{type(ptms).__name__}`." ) if not isinstance(interactions, pd.DataFrame): raise TypeError( f"Expected `interactions` to be of type `pandas.DataFrame`, found `{type(ptms).__name__}`." ) if ptms.empty: raise ValueError(_ERROR_EMPTY_FMT.format(obj="PTMs")) if interactions.empty: raise ValueError(_ERROR_EMPTY_FMT.format(obj="interactions")) return pd.merge( ptms, interactions[[ "source", "target", "is_stimulation", "is_inhibition" ]], left_on=["enzyme", "substrate"], right_on=["source", "target"], how="left", )
def test_valid_params(self, cache_backup, requests_mock, tsv_data: bytes, caplog): url = urljoin(options.url, Enzsub._query_type.endpoint) df = pd.read_csv(StringIO(tsv_data.decode("utf-8")), sep="\t") requests_mock.register_uri( "GET", f"{url}?fields=curation_effort%2Creferences%2Csources&format=tsv&license=academic", content=tsv_data, ) with caplog.at_level(logging.WARNING): res = Enzsub.get(license="academic", format="text") assert f"Invalid `{Key.FORMAT.s}='text'`" in caplog.text np.testing.assert_array_equal(res.index, df.index) np.testing.assert_array_equal(res.columns, df.columns) np.testing.assert_array_equal(res.values, df.values) assert requests_mock.called_once
def test_invalid_format(self): with pytest.raises(ValueError, match=r"Invalid value `bar` for `Format`."): Enzsub.get(format="bar")
def test_invalid_license(self): with pytest.raises(ValueError, match=r"Invalid value `bar` for `License`."): Enzsub.get(license="bar")
def test_invalid_params(self): with pytest.raises(ValueError, match=r"Invalid value `foo` for `EnzsubQuery`."): Enzsub.get(foo="bar")