Skip to main content

BioTuring SpatialX Connector

Project description

BioTuring SpatialX Connector

Import

import os
import spatialx_connector
from spatialx_connector import SpatialXConnector
import warnings
warnings.filterwarnings("ignore")

Domain and Token

DOMAIN = "INPUT DOMAIN HERE"
TOKEN = "INPUT TOKEN HERE"

Explore Account

connector = SpatialXConnector(domain=DOMAIN, token=TOKEN)
spatialx_connector.format_print(connector.info)
spatialx_connector.format_print(connector.groups)
spatialx_connector.format_print(connector.s3)
spatialx_connector.format_print(connector.folders)
studies = connector.list_study(
    group=spatialx_connector.DefaultGroup.PERSONAL_WORKSPACE.value,
    species=spatialx_connector.Species.HUMAN,
)
spatialx_connector.format_print(studies)
study_details = connector.get_study_detail(studies[0]["study_id"])
spatialx_connector.format_print(study_details)
samples = connector.list_sample(studies[0]["study_id"])
spatialx_connector.format_print(samples)
sample_details = connector.get_sample_detail(samples[0]["sample_id"])
spatialx_connector.format_print(sample_details)

Uploading

uploading_results = connector.upload_file("/s3/colab/content/xenium/experiment.xenium")
spatialx_connector.format_print(uploading_results)
uploading_results = connector.upload_big_file("/s3/colab/content/xenium/morphology_mip.ome.tif", debug_mode=True)
spatialx_connector.format_print(uploading_results)
uploading_results = connector.upload_folder("/s3/colab/content/xenium", debug_mode=True)
spatialx_connector.format_print(uploading_results)

Submission

visium_submission_information = connector.parse_data_information(
    "Visium_V2_Human_Colon_Cancer_P2",
    spatialx_connector.Technologies.VISIUM,
    os.path.join(
        connector.s3["bioturingpublic"],
        "SpatialX_datasets/Human_Colon_Cancer_P2/Visium_V2_Human_Colon_Cancer_P2"
    )
)
spatialx_connector.format_print(visium_submission_information)
xenium_submission_information = connector.parse_data_information(
    "Xenium_V1_Human_Colon_Cancer_P2_CRC_Add_on_FFPE",
    spatialx_connector.Technologies.XENIUM,
    os.path.join(
        connector.s3["bioturingpublic"],
        "SpatialX_datasets/Human_Colon_Cancer_P2/Xenium_V1_Human_Colon_Cancer_P2_CRC_Add_on_FFPE"
    )
)
spatialx_connector.format_print(xenium_submission_information)
submission_results = connector.submit(
    spatialx_connector.DefaultGroup.PERSONAL_WORKSPACE.value,
    spatialx_connector.Species.HUMAN,
    "10xgenomics",
    "Human_Colon_Cancer_P2",
    visium_submission_information
)
spatialx_connector.format_print(submission_results)
xenium_submission_results = connector.add_sample_data(
    submission_results["study_id"],
    submission_results["sample_id"],
    xenium_submission_information,
)
submission_results["sample_data"].extend(xenium_submission_results["sample_data"])
spatialx_connector.format_print(submission_results)

Analysis

data_id = submission_results["sample_data"][-1]["data_id"]
data_id
Embeddings
response = connector.analysis.embeddings.pca(data_id=data_id, title="Connector - PCA")
spatialx_connector.format_print(response)
response = connector.analysis.embeddings.scvi(data_id=data_id, title="Connector - scVI", n_top_genes=2000)
spatialx_connector.format_print(response)
embeddings = connector.analysis.list_embedding(data_id)
spatialx_connector.format_print(embeddings)
response = connector.analysis.embeddings.umap(data_id=data_id, embedding_key=embeddings[0], title="Connector - UMAP")
spatialx_connector.format_print(response)
response = connector.analysis.embeddings.tsne(data_id=data_id, embedding_key=embeddings[0], title="Connector - tSNE")
spatialx_connector.format_print(response)
Clustering
response = connector.analysis.clustering.louvain(
    data_id=data_id,
    embedding_key=embeddings[0],
    resolution=0.1,
    title="Connector - Louvain",
)
spatialx_connector.format_print(response)
response = connector.analysis.clustering.kmeans(
    data_id=data_id,
    embedding_key=embeddings[0],
    n_clusters=5,
    title="Connector - k-means",
)
spatialx_connector.format_print(response)
Prediction
embeddings = connector.analysis.list_embedding(data_id)
spatialx_connector.format_print(embeddings)
metadata = connector.analysis.list_metadata(data_id)
spatialx_connector.format_print(metadata)
response = connector.analysis.prediction.metadata_reference(
    data_id=data_id,
    cluster_key=metadata[0],
    species=spatialx_connector.Species.HUMAN,
    title="Connector - Metadata Reference",
)
spatialx_connector.format_print(response)
Differential Expression
response = connector.analysis.de.differential_expression_genes(
    data_id_1=data_id,
    data_id_2=data_id,
    group_1_indices=[i for i in range(10000)],
    group_2_indices=[i for i in range(10000, 20000)],
    title="Connector - DE genes",
)
spatialx_connector.format_print(response)
Spatial Analysis
response = connector.analysis.spatial_analysis.region_segmentation(
    data_id=data_id,
    radius=50,
    mpp=0.2125,
    resolution=0.5,
    species=spatialx_connector.Species.HUMAN,
    title="Connector - Region Segmentation",
)
spatialx_connector.format_print(response)

Convert data from Lens

!pip install bioturing_connector
LENS_SC_HOST: str = "LENS_SC_HOST"
LENS_SC_TOKEN: str = "LENS_SC_TOKEN"
lens_sc_studies = connector.list_lens_sc_studies(
    host=LENS_SC_HOST, token=LENS_SC_TOKEN,
    group=spatialx_connector.DefaultGroup.PERSONAL_WORKSPACE,
    species=spatialx_connector.Species.HUMAN,
)
spatialx_connector.format_print(lens_sc_studies)
# Convert a study
connector.convert_data_from_lens(lens_sc_studies[0])
LENS_BULK_HOST: str = "LENS_BULK_HOST"
LENS_BULK_TOKEN: str = "LENS_BULK_TOKEN"
lens_bulk_studies = connector.list_lens_bulk_studies(
    host=LENS_BULK_HOST, token=LENS_BULK_TOKEN,
    group=spatialx_connector.DefaultGroup.PERSONAL_WORKSPACE,
    species=spatialx_connector.Species.HUMAN,
)
spatialx_connector.format_print(lens_bulk_studies)
# Convert multiple studies
connector.convert_data_from_lens(lens_bulk_studies)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spatialx_connector-0.1.3.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

spatialx_connector-0.1.3-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file spatialx_connector-0.1.3.tar.gz.

File metadata

  • Download URL: spatialx_connector-0.1.3.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for spatialx_connector-0.1.3.tar.gz
Algorithm Hash digest
SHA256 8ce36df2862f9de4a03e84482e2e78beffecccd2b1485ea55170667b434c62cf
MD5 17a1137e815623243cc55148cef5c662
BLAKE2b-256 fce0cbebbf60d5a6ce13ab0ec204f893435b9ec31c171f041ef44be665f7ccaf

See more details on using hashes here.

File details

Details for the file spatialx_connector-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for spatialx_connector-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 415d0ce11e0ad807a192dd78a31444db80a261cc7e92d02365d56e7d39d43022
MD5 e688fc8d43a4e42be8e1fd48fb3b7285
BLAKE2b-256 b1d07a6d494bb8a4d35118e490767435a535dfb7e52a001d1f56beb360201e7f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page