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_resources(self, cache_backup, requests_mock, resources: bytes): url = urljoin(options.url, Endpoint.RESOURCES.s) requests_mock.register_uri("GET", f"{url}?format=json", content=resources) res = Enzsub.resources() assert res == ("quux",) assert 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 test_params_no_org_genesymbol(self): params = Enzsub.params() assert Key.ORGANISM.value not in params assert Key.GENESYMBOLS.value in params for k, valid in params.items(): if isinstance(valid, Iterable): np.testing.assert_array_equal( list(set(valid)), list(set(EnzsubQuery(k).valid)) ) else: assert valid == EnzsubQuery(k).valid
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_docs(self): assert set(Enzsub._docs().keys()) == {e.param for e in EnzsubQuery} assert all(d is None for d in Enzsub._docs().values())
def test_annotations(self): assert set(Enzsub._annotations().keys()) == {e.param for e in EnzsubQuery} assert all( isinstance(a, (_GenericAlias, type)) for a in Enzsub._annotations().values() )
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")
def test_str_repr(self): assert str(Enzsub()) == f"<{Enzsub().__class__.__name__}>" assert repr(Enzsub()) == f"<{Enzsub().__class__.__name__}>"