spateo.io ========= .. py:module:: spateo.io Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/spateo/io/bbs/index /autoapi/spateo/io/bgi/index /autoapi/spateo/io/image/index /autoapi/spateo/io/image_utils/index /autoapi/spateo/io/merfish/index /autoapi/spateo/io/nanostring/index /autoapi/spateo/io/seqfish/index /autoapi/spateo/io/seqscope/index /autoapi/spateo/io/slideseq/index /autoapi/spateo/io/starmap/index /autoapi/spateo/io/tenx/index /autoapi/spateo/io/utils/index Functions --------- .. autoapisummary:: spateo.io.alpha_shape spateo.io.get_concave_hull spateo.io.read_bgi spateo.io.read_bgi_agg spateo.io.read_image spateo.io.read_nanostring spateo.io.read_slideseq spateo.io.read_10x spateo.io.read_10x_as_anndata Package Contents ---------------- .. py:function:: alpha_shape(x: numpy.ndarray, y: numpy.ndarray, alpha: float = 1, buffer: float = 1, vectorize: bool = True) -> Tuple[Union[shapely.geometry.MultiPolygon, shapely.geometry.Polygon], List] Compute the alpha shape (concave hull) of a set of points. Code adapted from: https://gist.github.com/dwyerk/10561690 :param x: x-coordinates of the DNA nanoballs or buckets, etc. :param y: y-coordinates of the DNA nanoballs or buckets, etc. :param alpha: alpha value to influence the gooeyness of the border. Smaller numbers don't fall inward as much as larger numbers. Too large, and you lose everything! :param buffer: the buffer used to smooth and clean up the shapley identified concave hull polygon. :param vectorize: Whether to vectorize the alpha-shape calculation instead of looping through. :returns: The computed concave hull. edge_points: The coordinates of the edge of the resultant concave hull. :rtype: alpha_hull .. py:function:: get_concave_hull(path: str, binsize: int = 20, min_agg_umi: Optional[int] = None, alpha: float = 1.0, buffer: Optional[float] = None) -> Tuple[shapely.geometry.Polygon, List] Return the convex hull of all nanoballs that have non-zero UMI (or at least > min_agg_umi UMI). :param path: Path to read file. :param binsize: The number of spatial bins to aggregate RNAs captured by DNBs in those bins. By default it is 20, which is close to the size of a single cell. If stereo-seq chip used is bigger than 1 x 1 mm, you may need to increase the binsize. :param min_agg_umi: the minimal aggregated UMI number for the bucket. :param alpha: alpha value to influence the gooeyness of the border. Smaller numbers don't fall inward as much as larger numbers. Too large, and you lose everything! :param buffer: the buffer used to smooth and clean up the shapley identified concave hull polygon. :returns: The computed concave hull. edge_points: The coordinates of the edge of the resultant concave hull. :rtype: alpha_hull .. py:function:: read_bgi(path: str, binsize: Optional[int] = None, segmentation_adata: Optional[anndata.AnnData] = None, labels_layer: Optional[str] = None, labels: Optional[Union[numpy.ndarray, str]] = None, seg_binsize: int = 1, label_column: Optional[str] = None, add_props: bool = True, version: typing_extensions.Literal[stereo] = 'stereo') -> anndata.AnnData Read BGI read file as AnnData. :param path: Path to read file. :param binsize: Size of pixel bins. Should only be provided when labels (i.e. the `segmentation_adata` and `labels` arguments) are not used. :param segmentation_adata: AnnData containing segmentation results. :param labels_layer: Layer name in `segmentation_adata` containing labels. :param labels: Numpy array or path to numpy array saved with `np.save` that contains labels. :param seg_binsize: the bin size used in cell segmentation, used in conjunction with `labels` and will be overwritten when `labels_layer` and `segmentation_adata` are not None. :param label_column: Column that contains already-segmented cell labels. If this column is present, this takes prescedence. :param add_props: Whether or not to compute label properties, such as area, bounding box, centroid, etc. :param version: BGI technology version. Currently only used to set the scale and scale units of each unit coordinate. This may change in the future. :returns: Bins x genes or labels x genes AnnData. .. py:function:: read_bgi_agg(path: str, stain_path: Optional[str] = None, binsize: int = 1, gene_agg: Optional[Dict[str, Union[List[str], Callable[[str], bool]]]] = None, prealigned: bool = False, label_column: Optional[str] = None, version: typing_extensions.Literal[stereo] = 'stereo') -> anndata.AnnData Read BGI read file to calculate total number of UMIs observed per coordinate. :param path: Path to read file. :param stain_path: Path to nuclei staining image. Must have the same coordinate system as the read file. :param binsize: Size of pixel bins. :param gene_agg: Dictionary of layer keys to gene names to aggregate. For example, `{'mito': ['list', 'of', 'mitochondrial', 'genes']}` will yield an AnnData with a layer named "mito" with the aggregate total UMIs of the provided gene list. :param prealigned: Whether the stain image is already aligned with the minimum x and y RNA coordinates. :param label_column: Column that contains already-segmented cell labels. :param version: BGI technology version. Currently only used to set the scale and scale units of each unit coordinate. This may change in the future. :returns: An AnnData object containing the UMIs per coordinate and the nucleus staining image, if provided. The total UMIs are stored as a sparse matrix in `.X`, and spliced and unspliced counts (if present) are stored in `.layers['spliced']` and `.layers['unspliced']` respectively. The nuclei image is stored as a Numpy array in `.layers['nuclei']`. .. py:function:: read_image(adata: anndata.AnnData, filename: str, scale_factor: float, slice: Optional[str] = None, img_layer: Optional[str] = None) -> anndata.AnnData Load an image into the AnnData object. :param adata: AnnData object :param filename: The path of the image :param scale_factor: The scale factor of the image. Define: pixels/DNBs :param slice: Name of the slice. Will be used when displaying multiple slices. :param img_layer: Name of the image layer. :returns: * :attr:`~anndata.AnnData.uns`\ `['spatial'][slice]['images'][img_layer]` -- The stored image * :attr:`~anndata.AnnData.uns`\ `['spatial'][slice]['scalefactors'][img_layer]` -- The scale factor for the spots .. py:function:: read_nanostring(path: str, meta_path: Optional[str] = None, binsize: Optional[int] = None, label_columns: Optional[Union[str, List[str]]] = None, add_props: bool = True, version: typing_extensions.Literal[cosmx] = 'cosmx') -> anndata.AnnData Read NanoString CosMx data as AnnData. :param path: Path to transcript detection CSV file. :param meta_path: Path to cell metadata CSV file. :param scale: Physical length per coordinate. For visualization only. :param scale_unit: Scale unit. :param binsize: Size of pixel bins :param label_columns: Columns that contain already-segmented cell labels. Each unique combination is considered a unique cell. :param add_props: Whether or not to compute label properties, such as area, bounding box, centroid, etc. :param version: NanoString technology version. Currently only used to set the scale and scale units of each unit coordinate. This may change in the future. :returns: Bins x genes or labels x genes AnnData. .. py:function:: read_slideseq(path: str, beads_path: str, binsize: Optional[int] = None, version: typing_extensions.Literal[slide2] = 'slide2') -> anndata.AnnData Read Slide-seq data as AnnData. :param path: Path to Slide-seq digital expression matrix CSV. :param beads_path: Path to CSV file containing bead locations. :param binsize: Size of pixel bins. :param version: Slideseq technology version. Currently only used to set the scale and scale units of each unit coordinate. This may change in the future. .. py:function:: read_10x(matrix_dir: str, positions_path: str, version: typing_extensions.Literal[visium] = 'visium') -> anndata.AnnData Read 10x Visium data as AnnData. :param matrix_dir: Directory containing matrix files (barcodes.tsv.gz, features.tsv.gz, matrix.mtx.gz) :param positions_path: Path to CSV containing spatial coordinates :param version: 10x technology version. Currently only used to set the scale and scale units of each unit coordinate. This may change in the future. .. py:function:: read_10x_as_anndata(matrix_dir: str) -> anndata.AnnData Read 10x Visium matrix directory as AnnData. :param matrix_dir: Path to directory containing matrix files. :returns: AnnData of barcodes x genes.