:class:`~.CellMeta` ============================================================================================================================================ .. py:class:: astropathdb.db_io.build_astrodb.CellMeta(*args, **kwargs) :single-line-parameter-list: Bases: :class:`~.WsiMirrorBase` Mirrors the database tables with cell type metadata information. This allows for easy access to the database tables as class properties. :param database: The database to query by default, given in any letter case (see :func:`~.canonical_database_name`). Defaults to a public database. :type database: :py:class:`str` :param username: The SciServer account. With ``password``, it takes priority over every other source. Alone, it ranks below ``credential_filename``, and a missing password may be completed from this account's keyring. :type username: :py:class:`str` | :py:obj:`None` :param password: The selected account's password, preserved exactly when supplied directly. :type password: :py:class:`str` | :py:obj:`None` :param credential_filename: A local .env, JSON, or two-line text credential file, used unless ``username`` and ``password`` are both given. Relative paths use the current directory; home-directory paths may start with ``~``. :type credential_filename: :py:class:`str` | :py:class:`~pathlib.Path` | :py:obj:`None` :param db_connection: ``True`` to authenticate and open a client, or an existing :class:`~.CasJobsUrllib3Client` to reuse its connection pool. :type db_connection: :py:class:`bool` | :py:class:`~astropathdb.db_io.dbconnect.CasJobsUrllib3Client` :class:`~.astropathdb.db_io.build_astrodb.CellMeta` *Attributes* -------------------------------------------------------------------------------------------------------------------------------------------- .. autoapisummary:: :signatures: none astropathdb.db_io.build_astrodb.CellMeta.mirror_name astropathdb.db_io.build_astrodb.CellMeta.mirrored_tables :class:`~.astropathdb.db_io.build_astrodb.CellMeta` *Properties* -------------------------------------------------------------------------------------------------------------------------------------------- .. autoapisummary:: :signatures: none astropathdb.db_io.build_astrodb.CellMeta.mixing_matrix astropathdb.db_io.build_astrodb.CellMeta.expression_columns astropathdb.db_io.build_astrodb.CellMeta.expression_targets astropathdb.db_io.build_astrodb.CellMeta.sql astropathdb.db_io.build_astrodb.CellMeta.database :class:`~.astropathdb.db_io.build_astrodb.CellMeta` *Methods* -------------------------------------------------------------------------------------------------------------------------------------------- .. autoapisummary:: :signatures: none astropathdb.db_io.build_astrodb.CellMeta.set_ptype_colors astropathdb.db_io.build_astrodb.CellMeta.get_phenotype astropathdb.db_io.build_astrodb.CellMeta.get_ptype astropathdb.db_io.build_astrodb.CellMeta.get_exprphenotype astropathdb.db_io.build_astrodb.CellMeta.sci_login astropathdb.db_io.build_astrodb.CellMeta.query astropathdb.db_io.build_astrodb.CellMeta.print_sql astropathdb.db_io.build_astrodb.CellMeta.dbstring astropathdb.db_io.build_astrodb.CellMeta.convert_to_geom astropathdb.db_io.build_astrodb.CellMeta.gquery :class:`~.astropathdb.db_io.build_astrodb.CellMeta` *References* -------------------------------------------------------------------------------------------------------------------------------------------- .. py:currentmodule:: astropathdb.db_io.build_astrodb.CellMeta *Attribute Reference* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. py:attribute:: mirror_name :value: 'CellMeta' .. py:attribute:: mirrored_tables :value: ('batch', 'boundarytype', 'exprmarkers', 'exprphenotype', 'mergeconfig', 'phenotype') *Property Reference* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. py:property:: mixing_matrix :type: pandas.DataFrame A ``layerx3`` matrix for converting images to rgb. By default the mixing matrix in the ref:`mergeconfig` table will be used. The matrix can be changed by passing either 'default' or a mapping of ``{layer: hex color}`` to the property. If input ``mixing_matrix`` is set to 'default', it will use the mixing matrix for the foundational AstroPath paper published in *Science, 2021* for the number of image layers in the mergeconfig table, and raise a ``ValueError`` if there is none. If a mapping for a matrix is supplied the ``mixing_matrix``, that mapping will be applied to the :ref:`mergeconfig` table stored in the :attr:`~.WsiMirror.cellmeta` property and used for visualization. .. note:: The mixing matrix will default back to the database mixing matrix if the :attr:`~.SciBase.database` is updated. .. py:property:: expression_columns :type: list Get the target expression column names from mergeconfig for celltag. .. py:property:: expression_targets :type: list Get the target expression column names from mergeconfig for celltag. .. py:property:: sql :type: str | sqlalchemy.sql.expression.ClauseElement | collections.abc.Sequence[str | sqlalchemy.sql.expression.ClauseElement] The last query sent to the database. Holds the SQL string, or list of strings, most recently sent by :meth:`~.SciBase.query`. Set it to a SQL string, a SQLAlchemy construct, or a sequence of either, then call :meth:`~.SciBase.query` with no ``sql`` to run it; the attribute then holds the SQL that was sent. .. py:property:: database :type: str The database queried when no ``db`` is given. Always the registered spelling of the name (see :func:`~.canonical_database_name`). Setting it calls :meth:`~.SciBase._database_setter`, which subclasses override. *Method Reference* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. py:method:: set_ptype_colors() :single-line-parameter-list: Set the ptype colors to the mixing matrix colors. .. py:method:: get_phenotype(ptype) :single-line-parameter-list: Select the phenotype string from ptype. :param ptype: A ptype or list of ptypes. .. py:method:: get_ptype(phenotype) :single-line-parameter-list: Select the ptype number from phenotype input. :param phenotype: A phenotype or list of phenotypes .. py:method:: get_exprphenotype(phenotype) :single-line-parameter-list: Select the ptype number from phenotype input. :param phenotype: A phenotype or list of phenotypes .. py:method:: sci_login(username = None, password = None, *, credential_filename = None) :single-line-parameter-list: Authenticate or reuse the process-wide SciServer session. Automatic local discovery selects an environment token, the existing session, a configured file, environment credentials, then ``scicreds/sciserver_creds.txt`` in a source checkout. Supply explicit credentials to reauthenticate after a rejected query; a bare call may reuse the rejected session. Reused tokens are not validated against the server. Compute uses its managed session only. :param username: The SciServer account. With ``password``, it takes priority over every other source. Alone, it ranks below ``credential_filename``, and a missing password may be completed from this account's keyring. :param password: The selected account's password, preserved exactly when supplied directly. :param credential_filename: A local .env, JSON, or two-line text credential file, used unless ``username`` and ``password`` are both given. Relative paths use the current directory; home-directory paths may start with ``~``. :raises AstroPathAuthenticationInputError: Inputs are invalid. :raises AstroPathCredentialsError: No complete credentials or token are available. :raises FileNotFoundError: A selected credential file does not exist. :raises AstroPathAuthenticationError: SciServer authentication failed. :raises CasJobsLoginError: No active token was obtained. .. admonition:: Examples .. code-block:: python db.sci_login(username="account", password=password) .. py:method:: query(sql = None, *, long = False, db = None, output_format = CASJOBSDCONST.DEFAULT_RETURNTYPE, nthreads = CASJOBSDCONST.DEFAULT_THREADS, _force_sciscript = False) :single-line-parameter-list: Query a database with a SQL statement. ``sql`` is a SQL string, a SQLAlchemy construct, or a sequence of either. Constructs are compiled to SQL strings. A sequence is run as separate queries in parallel, and the results are returned in completion order, not input order. Splitting a large query into a sequence, or joining several queries with ';', usually returns data faster. Output formats: - "pandas": A dataframe for a single result set, otherwise a list of the non-empty dataframes. - "pandas_concat": The non-empty result sets concatenated into one dataframe. All result sets must have the same columns. - "json" or "dict": The raw result set dictionaries. - "list": A ``(columns, rows)`` tuple with the rows of every result set. All result sets must have the same columns. - "csv", "readable", "StringIO", "fits", and "BytesIO": Supported only with ``_force_sciscript``; see the ``SciScript-Python`` documentation. :param sql: The query or queries to run. Defaults to :attr:`~.SciBase.sql`. :param long: Submit ``sql`` as a long-running ``CasJobs`` job and wait for it. Use for queries that exceed the synchronous time limit; the query must write its results to a table in 'MyDB', and the job status is returned instead of data. :param db: The database context. Defaults to :attr:`~.SciBase.database`. :param output_format: The output format; see above. :param nthreads: Number of threads used to run a sequence of queries. :param _force_sciscript: Run the query through ``SciScript-Python`` instead of the package's parallel client. :returns: The query results in the ``output_format`` output format. .. admonition:: Examples Query a table, then run two queries in parallel and join their results: .. code-block:: python from astropathdb import AstroDB astrodb = AstroDB(database="apmifwsi001_DR2") samples = astrodb.query("SELECT sampleid, astroid FROM Samples") df = astrodb.query( [ "SELECT sampleid, astroid FROM Samples WHERE sampleid < 10", "SELECT sampleid, astroid FROM Samples WHERE sampleid >= 10", ], output_format="pandas_concat", ) .. py:method:: print_sql(sql = None, *, construct = False, as_string = False) :single-line-parameter-list: Print, or return, a SQL statement as the SQL sent to the database. Defaults to the last SQLAlchemy construct passed to :meth:`~.SciBase.query`, then to :attr:`~.SciBase.sql`. :param sql: A SQL string, a SQLAlchemy construct, or a sequence of SQL strings. :param construct: Keep a SQLAlchemy construct as is instead of compiling it to SQL. :param as_string: Return the statement instead of printing it. :returns: The statement if ``as_string`` is ``True``, otherwise ``None``. .. py:method:: dbstring(sql_str) :single-line-parameter-list: :staticmethod: Wrap a string in single quotes for use as a SQL string literal. :param sql_str: The string to quote. :returns: ``sql_str`` wrapped in single quotes. .. py:method:: convert_to_geom(df, geometry_id) :single-line-parameter-list: :staticmethod: Convert :class:`~pandas.DataFrame` to :class:`~geopandas.GeoDataFrame`. The database returns ``geometry`` values as well-known text (MSSQL ``.STAsText()``) or as hex-encoded well-known binary (``.STAsBinary()``). The ``geometry_id`` column is parsed as WKB when its values start with '0x', otherwise as WKT, and replaced by a 'geometry' column. Rows with empty geometries are removed. :param df: The query result. A list of dataframes is concatenated first. :param geometry_id: The column holding the geometry values. Cannot be 'geometry'. :returns: The query result with a 'geometry' column in place of ``geometry_id``. :raises ValueError: ``geometry_id`` is 'geometry'. .. seealso:: :meth:`~.SciBase.gquery` to query and convert in one call. .. py:method:: gquery(*args, geometry_id = APDBREF.GEOM_WKT_NAME, **kwargs) :single-line-parameter-list: Run :meth:`~.SciBase.query` and convert a geometry column. The ``geometry_id`` column of the result becomes the 'geometry' column of a :class:`~geopandas.GeoDataFrame`; see :meth:`~.SciBase.convert_to_geom`. :param \*args: Positional arguments for :meth:`~.SciBase.query`. :param geometry_id: The column holding the geometry values. If ``None``, the query result is returned unconverted. :param \*\*kwargs: Keyword arguments for :meth:`~.SciBase.query`. :returns: The query result, converted when ``geometry_id`` is given. .. seealso:: :meth:`~.SciBase.query` for query inputs and output formats, and :meth:`~.SciBase.convert_to_geom` for the geometry conversion. *Private Property Reference* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. py:property:: _filtered_mergeconfig :type: pandas.DataFrame