:class:`~.AstroSample` ============================================================================================================================================= .. py:class:: astropathdb.db_io.load_sample.AstroSample(*args, sdata, sampleid, **kwargs) :single-line-parameter-list: Bases: :class:`~.astropathdb.db_io.build_astrodb.AstroDB` Helper class loading samples into :class:`~spatialdata.SpatialData`. The class enables loading AstroPath image, cell, and annotation data into a :class:`~spatialdata.SpatialData` to seemlessly adopt the framework. :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` :param sdata: A :class:`~spatialdata.SpatialData` object to load the data into. :param sampleid: A single or list of sampleids to load the data from. .. seealso:: :func:`.load_astrosample` for details on the implementation. :class:`~.astropathdb.db_io.load_sample.AstroSample` *Attributes* --------------------------------------------------------------------------------------------------------------------------------------------- .. autoapisummary:: :signatures: none astropathdb.db_io.load_sample.AstroSample.parsed_init astropathdb.db_io.load_sample.AstroSample.wsi_dbs_metadata astropathdb.db_io.load_sample.AstroSample.public_dbs_metadata :class:`~.astropathdb.db_io.load_sample.AstroSample` *Properties* --------------------------------------------------------------------------------------------------------------------------------------------- .. autoapisummary:: :signatures: none astropathdb.db_io.load_sample.AstroSample.cellmeta astropathdb.db_io.load_sample.AstroSample.metadata astropathdb.db_io.load_sample.AstroSample.schema astropathdb.db_io.load_sample.AstroSample.sql astropathdb.db_io.load_sample.AstroSample.database :class:`~.astropathdb.db_io.load_sample.AstroSample` *Methods* --------------------------------------------------------------------------------------------------------------------------------------------- .. autoapisummary:: :signatures: none astropathdb.db_io.load_sample.AstroSample.from_astrodb astropathdb.db_io.load_sample.AstroSample.samples astropathdb.db_io.load_sample.AstroSample.should_load astropathdb.db_io.load_sample.AstroSample.results_key astropathdb.db_io.load_sample.AstroSample.structured_query astropathdb.db_io.load_sample.AstroSample.load_element astropathdb.db_io.load_sample.AstroSample.load_astrosample astropathdb.db_io.load_sample.AstroSample.load_db_session astropathdb.db_io.load_sample.AstroSample.update_ptype_filter astropathdb.db_io.load_sample.AstroSample.update_exprphenotype_filter astropathdb.db_io.load_sample.AstroSample.update_filter_dict astropathdb.db_io.load_sample.AstroSample.sci_login astropathdb.db_io.load_sample.AstroSample.query astropathdb.db_io.load_sample.AstroSample.print_sql astropathdb.db_io.load_sample.AstroSample.dbstring astropathdb.db_io.load_sample.AstroSample.convert_to_geom astropathdb.db_io.load_sample.AstroSample.gquery astropathdb.db_io.load_sample.AstroSample.select astropathdb.db_io.load_sample.AstroSample.get_table astropathdb.db_io.load_sample.AstroSample.add_sql_filters astropathdb.db_io.load_sample.AstroSample.load_query_init :class:`~.astropathdb.db_io.load_sample.AstroSample` *References* --------------------------------------------------------------------------------------------------------------------------------------------- .. py:currentmodule:: astropathdb.db_io.load_sample.AstroSample *Attribute Reference* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. py:attribute:: parsed_init :type: dict[str, pandas.DataFrame | geopandas.GeoDataFrame | None] .. py:attribute:: wsi_dbs_metadata :type: dict A dictionary with primary keys denoting the available private astropath databases. Each database contains a subsequent mappping for related metadata. :attr:`~.AstroDB.wsi_dbs_metadata` keys: - tissue: The cancer tissue type. - cohort: A unique number denoting a set of patients. - machine: The microscope that was used to image the slides. - method: The method for staining, denoted as 'Manual' or 'Automated'. - panel: A descriptive string denoting the antibody-fluor pairings, each panel is given a unique string. - stainconfig: A number denoting a combination of machine, method, and panel. - xlevel: The numeric cut level from the block that was used for each slide. .. py:attribute:: public_dbs_metadata :type: dict A dictionary with primary keys denoting the available public databases. The databases are named ``_``. The metadata of each one is the metadata of the ``wsiXX`` database it was built from, with the same keys as :attr:`~.AstroDB.wsi_dbs_metadata`. *Property Reference* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. py:property:: cellmeta :type: CellMeta A collection of properties that mirrors data related to cohort cells. Has the following table attributes: - :ref:`batch` - :ref:`boundarytype` - :attr:`~.CellMeta.expression_columns` - :ref:`exprmarkers` - :ref:`exprphenotype` - :ref:`mergeconfig` - :attr:`~.CellMeta.mixing_matrix` - :ref:`phenotype` - ``get_phenotype``: select a phenotype string from a ptype - ``get_ptype``: select the ptype number from a phenotype input - :attr:`~.CellMeta.expression_targets` - :meth:`~.CellMeta.set_ptype_colors`: Set colors for phenotype to mixing matrix. .. py:property:: metadata :type: MetaDat A collection of properties that mirrors data related to cohort metadata. Has the following table attributes: - :ref:`clinical` - :ref:`cohort` - :ref:`constants` - ``extendedclinical`` - :ref:`samples` - ``slides`` The ``extendedclinical`` and ``slides`` tables exist only in the private databases. Reading them on a public database raises ``CasJobsConnectionError``. .. py:property:: schema :type: WsiSchema A collection of properties that mirrors data related to cohort schema. Has the following table attributes: - `wsi_tables` - `wsi_procedures` - `wsi_functions` Has the following methods: - :meth:`~.WsiSchema.get_params` .. 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:: from_astrodb(sdata, astrodb, sampleid) :single-line-parameter-list: :classmethod: Build an instance from a predefined :class:`.AstroDB`. :param sdata: A :class:`~spatialdata.SpatialData` object to load the data into. :param astrodb: A :class:`.AstroDB` object to use as the source of the data. :param sampleid: A single or list of sampleids to load the data from. .. py:method:: samples(element) :single-line-parameter-list: List of sampleids for the element to load. .. py:method:: should_load(element) :single-line-parameter-list: Whether or not to load the element. .. py:method:: results_key(element) :single-line-parameter-list: Results keys for the element. .. py:method:: structured_query(element) :single-line-parameter-list: Returns a structured query for the element. :param element: The element to query. :type element: :py:class:`str` :returns: A StructuredQuery object for the element. .. py:method:: load_element(element) :single-line-parameter-list: Load the element into the :class:`~spatialdata.SpatialData` object. :param element: The element to load. .. py:method:: load_astrosample(*, image, annotations, cells_table, cells_positions, cells_boundaries) :single-line-parameter-list: Load sample data into the :class:`~spatialdata.SpatialData` framework. :param image: Load image data into the object (Defaults to ``True``). :param annotations: A logical value to load annotations or a mapping for what to load. Allowed arguments are columns, instance_id, geometry_id, table_name, and any of the sql filters. Defaults to True. Annotations are loaded from the :ref:`annotations_schema` by default. :param cells_table: A logical value to load cell tables or a mapping for what to load. Allowed arguments are columns, instance_id, coordinate_ids, table_name, and any of the sql filters. (Defaults to ``False``). Cells are loaded from the :ref:`celltag_schema` by default. :param cells_positions: A logical value to load cell centriods into the shapes element or a mapping for what to load. Allowed arguments are columns, instance_id, geometry_id, table_name, and any of the sql filters. (Defaults to ``False``). Cells positions are loaded from the :ref:`celltag_schema` by default. :param cells_boundaries: A logical value to load cell centriods into the shapes element or a mapping for what to load. Allowed arguments are columns, instance_id, geometry_id, table_name, and any of the sql filters. (Defaults to ``False``). Cells boundaries are loaded from the :ref:`cellgeom_schema` by default and only membranes are loaded using ``btype``. .. seealso:: :func:`.load_astrosample` for additional details and implementation. .. py:method:: load_db_session(db = None, *, reload = False, **kwargs) :single-line-parameter-list: Create an ORM mapping of ``db`` and store as a named attribute. The ORM attribute will be named by the ``db`` specified. Only generates the ORM attribute if it did not previously exist. Will default to the active :attr:`~.AstroDB.database` if no ``db`` is provided. :param db: The database to load a new session for (Defaults to the :attr:`~.AstroDB.database` attribute value). :param reload: Reload the ORM, useful if the database changes during analysis. :param \*\*kwargs: Additional keyword arguments to pass to the database connection. .. py:method:: update_ptype_filter(ptype = MappingProxyType({})) :single-line-parameter-list: Updates the ``ptype_filter`` to allow for ``phenotype`` key. :param ptype: A mapping for a filter generated by :func:`~._create_dynamic_filter` which will be applied by :meth:`~.AstroDB.add_sql_filters`. Values to filter can either be supplied to the 'ptype' or 'phenotype' key, do not add both. The code will perform the appropriate 'ptype' lookup if a 'phenotype' is supplied. .. seealso:: :ref:`phenotype_schema`: - A description of the 'ptype' and 'phenotype' keys. :func:`~._create_dynamic_filter`: - For a description of the filters. :meth:`~.AstroDB.add_sql_filters` - For a description of how the filters are added to the :meth:`~.AstroDB.select` statements when using a mappings. .. py:method:: update_exprphenotype_filter(exprphenotype = MappingProxyType({})) :single-line-parameter-list: Updates the ``ptype_filter`` to allow for ``phenotype`` key. :param exprphenotype: A mapping for a filter generated by :func:`~._create_dynamic_filter` which will be applied by :meth:`~.AstroDB.add_sql_filters`. Values to filter can either be supplied to the 'exprphenotype' or 'phenotype' key, do not add both. The code will perform the appropriate 'exprphenotype' bit value lookup if a 'phenotype' is supplied. .. seealso:: :ref:`exprmarkers_schema`: - A description of the 'exprphenotype' and 'phenotype' keys. :func:`~._create_dynamic_filter`: - For a description of the filters. :meth:`~.AstroDB.add_sql_filters` - For a description of how the filters are added to the :meth:`~.AstroDB.select` statements when using a mappings. .. py:method:: update_filter_dict(**filters) :single-line-parameter-list: Group update on some defaults on specific filters. .. seealso:: :meth:`~.AstroDB.update_exprphenotype_filter` and :meth:`~.AstroDB.update_ptype_filter` .. 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. .. py:method:: select(*columns, table_name = None, context = None) :single-line-parameter-list: Custom wrapper for :func:`~sqlalchemy.sql.expression.select`. We do this so that we can use text expressions in Object Relational Mapping (ORM) clauses vs always having to use explicit expressions. If :ref:`sqlalchemy` constructs are passed as the initial arguments, it returns the :ref:`sqlalchemy` :func:`~sqlalchemy.sql.expression.select` as normal. Optionally, you can provide a list of ``columns``, a ``table_name``, and/or a ``context`` as strings and the method will perform an attribute lookup on the instance of the class to find the corresponding ORM contructs. Thus when writing a :meth:`.SQL.select` statement the ORM :func:`~sqlalchemy.sql.expression.select` for the ``sampleid`` and ``cellid`` columns from the :ref:`celltag_schema` can be built with ``obj.select('sampleid', 'cellid', table_name = 'celltag')``. This may become simpler for longer queries than the fully qualified version\: ``obj.select(obj.apmifwsi001_DR2.celltag.sampleid, obj.apmifwsi001_DR2.celltag.cellid)``. .. warning:: If the attribute for the ``context`` does not exist this will return an attribute not found error. :param \*columns: Positional arguments are interpretted list of columns to be selected in the database (e.g. ``'sampleid', 'ptype'``) or a declarative base object for a table (e.g. ``obj.apmifwsi001_DR2.celltag.sampleid, obj.apmifwsi001_DR2.celltag.cellid``). :param table_name: The table name to query as either the mapping object (e.g. ``table_name=obj.apmifwsi001_DR2.celltag``) or as text (e.g. ``table_name='celltag'``). :param context: The database context to query as either the mapping object (e.g. ``context=obj.apmifwsi001_DR2``) or as text (e.g. ``context='apmifwsi001_DR2'``) (defaults to :attr:`~.SciBase.database` attribute of the object). .. seealso:: :func:`sqlalchemy.sql.expression.select`: - For the :ref:`sqlalchemy` ``select`` documentation. :meth:`~.SQL._get_context` and :meth:`~.SQL.get_table`: - Methods used for the lookup. :func:`._create_dynamic_filter`: - The custom filter implementation provided as an extension. :class:`.APFilters`: - A list of the custom filters themselves. .. py:method:: get_table(context = None, table_name = None) :single-line-parameter-list: If a table name is passed this will get that ORM attribute. Will include the context using :meth:`~.SQL._get_context` for a lookup. If the context is not provided we use the :attr:`~.SciBase.database` attribute of the object. :param table_name: The table name to query as either the mapping object (e.g. ``table_name=obj.apmifwsi001_DR2.celltag``) or as text (e.g. ``table_name='celltag'``). If a string is passed the ORM object is looked up in the class. :param context: The database context to query as either the mapping object (e.g. ``context=obj.apmifwsi001_DR2``) or as text (e.g. ``context='apmifwsi001_DR2'``). If a string is passed the ORM object is looked up in the class. (defaults to :attr:`~.SciBase.database` attribute of the object). :returns: Returns the table attribute itself with the context. .. seealso: :meth:`~.SQL.select` and :meth:`~.SQL._get_context`: - Basic implementation of the lookup .. py:method:: add_sql_filters(construct, **filter_mappings) :single-line-parameter-list: :staticmethod: Using mappings add our custom filters to a ``Select`` construct. We extend the :class:`~sqlalchemy.sql.expression.Select` adding keyword arguments as filter mappings, where the argument name is one of the filters in :class:`.APFilters` and the value is a mapping of argument\:value pairs for the filter. For example, to filter on the current ``sampleid`` we can add ``sampleid = self.sampleid``. By default this is already done for us in some methods, to remove the filter we can pass the keyword argument ``sampleid = '*'``, where '*' is a special value we use to specify all values. Optionally, filters .. note:: When default filters are denoted by query and loading methods they typically implement those defaults with this method. :param construct: The sqlalchemy contruct to add the filter to. Must have been derived from :meth:`.SQL.select`. :param \*\*filter_mappings: The argument name is the name of a filter in the :class:`.APFilters` and the value is a mapping of argument\:value pairs. .. seealso:: :meth:`~.SQL.load_query_init` - Additional details on implementation :class:`.APFilters`: - For a list of the available filter mappings :func:`._create_dynamic_filter`: - Additional internal details on the mapping arguments and logic .. py:method:: load_query_init(*columns, table_name = None, top_n = None, where = None, sql = None, **kwargs) :single-line-parameter-list: The basic initialization for load__queries. If ``sql`` is not empty, will return the query. Otherwise it will use our custom :meth:`.SQL.select` to generate a :class:`~sqlalchemy.sql.expression.Select` construct using the positional arguments as ``columns`` and applying the ``table_name``, ``where``, and ``top_n`` arguments when applicable. We always add the `sampleid` to the list of columns to query. We then extend the :class:`~sqlalchemy.sql.expression.Select` adding any other keyword arguments as filter mappings using :meth:`~.SQL.add_sql_filters`. .. note:: When default filters are denoted by query and loading methods they typically implement those defaults with the :meth:`~.SQL.add_sql_filters` method. :param \*columns: Positional arguments are interpretted list of columns to be selected in the database (e.g. ('sampleid', 'ptype')) or a declarative base object for a table (e.g. obj.apmifwsi001_DR2.celltag). The latter would return all columns in the provided table. By default the "sampleid" column is always added. :param table_name: The table name to query as either the mapping object (e.g. ``table_name=obj.apmifwsi001_DR2.celltag``) or as text (e.g. ``table_name='celltag'``). :param where: Provide a custom 'where' clause to filter the table. This is passed to :meth:`~sqlalchemy.sql.expression.Select.where` and should be a :data:`~sqlalchemy.sql.expression.ColumnExpressionArgument`. :param top_n: If applied will only return the top n rows and is applied using :meth:`~sqlalchemy.sql.expression.Select.limit` from ``sqlalchemy``. :param sql: Provide a custom sql query for the element instead of using the default filters options, supersedes and skips all other input arguments. :param \*\*kwargs: Keyword arguments passed to :meth:`~.SQL.add_sql_filters` (Defaults to ``sampleid = {'sampleid':self.sampleid}``). .. seealso:: Implementation examples: - :meth:`~.AstroSample.load_astrosample` :meth:`~.SQL.add_sql_filters`: - For the dictionary implementation of custom filters. :returns: If ``sql`` is provided will return a string, otherwise we return the updated :class:`~sqlalchemy.sql.expression.Select` contruct. *Private Attribute Reference* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. py:attribute:: __sdata :type: spatialdata.SpatialData .. py:attribute:: __elements :type: dict[str, astropathdb.db_io._sample_utils.SamplesToLoad] .. py:attribute:: _sampleids *Private Method Reference* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. py:method:: _parse_element_inputs(**kwargs) :single-line-parameter-list: .. py:method:: _query_init_elements() :single-line-parameter-list: .. py:method:: _parse_init_queries(query_results) :single-line-parameter-list: Parse the queries for the elements requested. :returns: A dictionary with the parsed results for each element. .. py:method:: _load_cells(sample, element) :single-line-parameter-list: .. py:method:: _add_cells_shapes(sample, element_id) :single-line-parameter-list: .. py:method:: _load_cells_boundaries(sample, *_) :single-line-parameter-list: Load the cell boundaries into the shapes element. :param sample: The sample to load the cell boundaries for. .. py:method:: _load_cells_positions(sample, *_) :single-line-parameter-list: Load the cell boundaries into the shapes element. :param sample: The sample to load the cell boundaries for. .. py:method:: _load_cell_points(sample, cells, pos_cols) :single-line-parameter-list: .. py:method:: _astropath_keys() :single-line-parameter-list: Returns a dictionary of keys used in the Astropath database. .. py:method:: _load_cells_table(sample, *_) :single-line-parameter-list: .. py:method:: _load_annotations(sample, geom_key) :single-line-parameter-list: .. py:method:: _load_image(sample, *_) :single-line-parameter-list: