Skip to main content

BioTuring SpatialX Connector

Project description

BioTuring SpatialX Connector

Installation

!pip install -U spatialx_connector

Import

import warnings
warnings.filterwarnings("ignore")
import os

import spatialx_connector
from spatialx_connector import SpatialXConnector
from spatialx_connector import Technologies
from spatialx_connector import DefaultGroup
from spatialx_connector import Species
from spatialx_connector import ConnectorKeys
from spatialx_connector import SubmissionElementKeys
from spatialx_connector import ExtendSegmentationSubmission
from spatialx_connector import ExtendExpressionSubmission

Domain and Token

DOMAIN = ""
TOKEN = ""

Explore Account

User's Information

connector = SpatialXConnector(domain=DOMAIN, token=TOKEN)
spatialx_connector.format_print(connector.info)

Groups

spatialx_connector.format_print(connector.groups)
{
    Personal workspace: 0eebe305688d82fe6c5ce361a43c64da
    All members: GLOBAL_GROUP
    BioTuring Public Studies: bioturing_public_studies
}
Storage

AWS buckets

spatialx_connector.format_print(connector.s3)
{
    bioturingpublic: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic
}

Personal/Shared folders

spatialx_connector.format_print(connector.folders)
{
    shared: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/shared_folder/shared
    Converted: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/converted
    Submitted: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/study
    Upload: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/upload
}

Browsing storage

connector.listdir(connector.s3["bioturingpublic"])
[
    'python3.9.13_linux.zip',
    'genes_annotation.human.json',
    'genes_annotation.mouse.json',
    'genes_annotation.primate.json',
    'ontology.mouse.sql',
    'ontology.human.sql',
    'SpatialX_datasets',
    'anotation',
    'binary',
    'examples',
    'mount'
]
connector.listdir(os.path.join(connector.s3["bioturingpublic"], "SpatialX_datasets"))
[
    'AnnData',
    'COSMX_VER1',
    'COSMX_VER2',
    'GeoMx',
    'Human_Colon_Cancer_P2',
    'MERSCOPE_VER1',
    'MERSCOPE_VER2',
    'Slide-Seq',
    'SpatialData'
]
connector.listdir(os.path.join(connector.s3["bioturingpublic"], "SpatialX_datasets/COSMX_VER1"))
['Lung6', 'Lung9_Rep1', 'Lung9_Rep2']
Browsing Studies Information

Listing studies

studies = connector.list_study(
    group=DefaultGroup.PERSONAL_WORKSPACE.value,
    species=Species.HUMAN.value,
)
spatialx_connector.format_print(studies)

Get more details of the first study

study_details = connector.get_study_detail(study_id=studies[0][ConnectorKeys.STUDY_ID.value])
spatialx_connector.format_print(study_details)

Listing samples of the first study

samples = connector.list_sample(study_id=studies[0][ConnectorKeys.STUDY_ID.value])
spatialx_connector.format_print(samples)

Get more details of the first sample of the study

sample_details = connector.get_sample_detail(sample_id=samples[0][ConnectorKeys.SAMPLE_ID.value])
spatialx_connector.format_print(sample_details)

Uploading

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

Submission

Parsing information for submission from data path and technology :

  • data_name: Name of the dataset
  • technology: Technology of the dataset
  • data_path: path to the dataset
Visium_V2_Human_Colon_Cancer_P2_submission_information = connector.parse_data_information(
    data_name="Visium_V2_Human_Colon_Cancer_P2",
    technology=Technologies.VISIUM.value,
    data_path=os.path.join(
        connector.s3["bioturingpublic"],
        "SpatialX_datasets/Human_Colon_Cancer_P2/Visium_V2_Human_Colon_Cancer_P2"
    )
)
spatialx_connector.format_print(Visium_V2_Human_Colon_Cancer_P2_submission_information)
[
    {
        name: Visium_V2_Human_Colon_Cancer_P2
        submission_type: SUBMIT_SPATIAL_BULK
        technology: VISIUM
        files: [
            {
                key: images
                value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/Human_Colon_Cancer_P2/Visium_V2_Human_Colon_Cancer_P2/Visium_V2_Human_Colon_Cancer_P2_tissue_image.btf
            }
            {
                key: matrix
                value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/Human_Colon_Cancer_P2/Visium_V2_Human_Colon_Cancer_P2/Visium_V2_Human_Colon_Cancer_P2_raw_feature_bc_matrix.h5
            }
            {
                key: tissue_positions
                value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/Human_Colon_Cancer_P2/Visium_V2_Human_Colon_Cancer_P2/spatial/tissue_positions.csv
            }
            {
                key: scalefactors
                value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/Human_Colon_Cancer_P2/Visium_V2_Human_Colon_Cancer_P2/spatial/scalefactors_json.json
            }
        ]
        folders: []
        args: []
        kwargs: []
        identities: []
    }
]
Xenium_V1_Human_Colon_Cancer_P2_submission_information = connector.parse_data_information(
    data_name="Xenium_V1_Human_Colon_Cancer_P2_CRC_Add_on_FFPE",
    technology=Technologies.XENIUM.value,
    data_path=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_V1_Human_Colon_Cancer_P2_submission_information)
[
    {
        name: Xenium_V1_Human_Colon_Cancer_P2_CRC_Add_on_FFPE
        submission_type: SUBMIT_SPATIAL_TRANSCRIPTOMICS
        technology: XENIUM
        files: [
            {
                key: experiment
                value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/Human_Colon_Cancer_P2/Xenium_V1_Human_Colon_Cancer_P2_CRC_Add_on_FFPE/experiment.xenium
            }
            {
                key: images
                value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/Human_Colon_Cancer_P2/Xenium_V1_Human_Colon_Cancer_P2_CRC_Add_on_FFPE/morphology.ome.tif
            }
            {
                key: alignment
                value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/Human_Colon_Cancer_P2/Xenium_V1_Human_Colon_Cancer_P2_CRC_Add_on_FFPE/Xenium_V1_Human_Colon_Cancer_P2_CRC_Add_on_FFPE_he_imagealignment.csv
            }
            {
                key: segmentation
                value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/Human_Colon_Cancer_P2/Xenium_V1_Human_Colon_Cancer_P2_CRC_Add_on_FFPE/cell_boundaries.csv.gz
            }
            {
                key: transcripts
                value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/Human_Colon_Cancer_P2/Xenium_V1_Human_Colon_Cancer_P2_CRC_Add_on_FFPE/transcripts.csv.gz
            }
        ]
        folders: []
        args: []
        kwargs: []
        identities: []
    }
]

Submiting new study with one sample and some data to flatform:

  • group: User's group
  • species: Species of the dataset
  • tilte: Title of new study
  • sample_name: Name of new sample
  • sample_data: Information of the data, it should be result or combine of results of connector.parse_data_information
submission_results = connector.submit(
    group=DefaultGroup.PERSONAL_WORKSPACE.value,
    species=Species.HUMAN.value,
    title="Human Colon Cancer - 10xgenomics",
    sample_name="Human_Colon_Cancer_P2",
    sample_data=Xenium_V1_Human_Colon_Cancer_P2_submission_information + Visium_V2_Human_Colon_Cancer_P2_submission_information,
)
spatialx_connector.format_print(submission_results)
{
    study_id: ST-01JMGMH3AT8HH8S23QV8ZC2G9T
    sample_id: SP-01JMGMH408Q5QDH2YPNXRR2WS6
    sample_data: [
        {
            data_id: DA-01JMGMH409ZPBZPQGHBCF4RXF6
            submit_id: SB-01JMGMH408Q5QDH2YPNWG5ZH46
            submit_name: Xenium_V1_Human_Colon_Cancer_P2_CRC_Add_on_FFPE
        }
        {
            data_id: DA-01JMGMH43QEYAC44YPGTQY80XY
            submit_id: SB-01JMGMH43QEYAC44YPGWMFTJ54
            submit_name: Visium_V2_Human_Colon_Cancer_P2
        }
    ]
    submit_id: SB-01JMGMH408Q5QDH2YPNWG5ZH46
    job_id: 2
    err_message:
}

Adding new sample to submitted study:

  • study_id: ID of the submitted study
  • name: Name of new sample
  • sample_data: Information of the data, it should be result or combine of results of connector.parse_data_information
adding_sample_results = connector.add_sample(
    study_id=submission_results[ConnectorKeys.STUDY_ID.value],
    sample_name="Human_Colon_Cancer_P2 - New Sample",
    sample_data=Visium_V2_Human_Colon_Cancer_P2_submission_information,
)
spatialx_connector.format_print(adding_sample_results)
{
    study_id: ST-01JMGMH3AT8HH8S23QV8ZC2G9T
    sample_id: SP-01JMGMH7K19M32CWQ1RH5TBDKM
    sample_data: [
        {
            data_id: DA-01JMGMH7K19M32CWQ1RMY7ZF8A
            submit_id: SB-01JMGMH7K19M32CWQ1RDWJ1KDW
            submit_name: Visium_V2_Human_Colon_Cancer_P2
        }
    ]
    submit_id: SB-01JMGMH7K19M32CWQ1RDWJ1KDW
    job_id: 3
    err_message:
}

Adding new sample data to existed sample:

  • study_id: ID of the submitted study
  • sample_id: ID of the existed sample
  • sample_data: Information of the data, it should be result or combine of results of connector.parse_data_information
adding_sample_data_results = connector.add_sample_data(
    study_id=adding_sample_results[ConnectorKeys.STUDY_ID.value],
    sample_id=adding_sample_results[ConnectorKeys.SAMPLE_ID.value],
    sample_data=Xenium_V1_Human_Colon_Cancer_P2_submission_information,
)
spatialx_connector.format_print(adding_sample_data_results)
{
    study_id: ST-01JMGMH3AT8HH8S23QV8ZC2G9T
    sample_id: SP-01JMGMH7K19M32CWQ1RH5TBDKM
    sample_data: [
        {
            data_id: DA-01JMGMHCZRFGANB8H36BSEBS3V
            submit_id: SB-01JMGMHCZRFGANB8H369FA1ZP7
            submit_name: Xenium_V1_Human_Colon_Cancer_P2_CRC_Add_on_FFPE
        }
    ]
    submit_id: SB-01JMGMHCZRFGANB8H369FA1ZP7
    job_id: 4
    err_message:
}

Parsing submission information for multiple samples:

  • technology: Technology of samples, only support one common technology
  • data_path: Path to directory of multiple datasets, with each sub-folder is a dataset
  • sample_name_mapping: Mapping of sub-folder to sample name
  • data_name_mapping: Mapping of sub-folder to data name
multiple_cosmx_samples_submission_information = connector.parse_multiple_samples_information(
    technology=Technologies.COSMX_VER1.value,
    data_path=os.path.join(connector.s3["bioturingpublic"], "SpatialX_datasets/COSMX_VER1"),
    sample_name_mapping={
        "Lung6": "Human Lung Cancer - Sample 6",
        "Lung9_Rep1": "Human Lung Cancer - Sample 9 Rep 1",
        "Lung9_Rep2": "Human Lung Cancer - Sample 9 Rep 2",
    },
    data_name_mapping={
        "Lung6": "Sample 6",
        "Lung9_Rep1": "Sample 9 Rep 1",
        "Lung9_Rep2": "Sample 9 Rep 2",
    },
)
spatialx_connector.format_print(multiple_cosmx_samples_submission_information)
[
    {
        sample_name: Human Lung Cancer - Sample 6
        data: [
            {
                name: Sample 6
                submission_type: SUBMIT_SPATIAL_TRANSCRIPTOMICS
                technology: COSMX_VER1
                files: [
                    {
                        key: fov_positions
                        value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/COSMX_VER1/Lung6/Lung6-Flat_files_and_images/Lung6_fov_positions_file.csv
                    }
                    {
                        key: transcripts
                        value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/COSMX_VER1/Lung6/Lung6-Flat_files_and_images/Lung6_tx_file.csv
                    }
                ]
                folders: [
                    {
                        key: images
                        value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/COSMX_VER1/Lung6/Lung6-RawMorphologyImages
                    }
                    {
                        key: segmentation
                        value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/COSMX_VER1/Lung6/Lung6-Flat_files_and_images/CellLabels
                    }
                ]
                args: [
                    {
                        key: mpp
                        value: 0.18
                    }
                ]
                kwargs: []
                identities: []
            }
        ]
    }
    {
        sample_name: Human Lung Cancer - Sample 9 Rep 1
        data: [
            {
                name: Sample 9 Rep 1
                submission_type: SUBMIT_SPATIAL_TRANSCRIPTOMICS
                technology: COSMX_VER1
                files: [
                    {
                        key: fov_positions
                        value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/COSMX_VER1/Lung9_Rep1/Lung9_Rep1-Flat_files_and_images/Lung9_Rep1_fov_positions_file.csv
                    }
                    {
                        key: transcripts
                        value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/COSMX_VER1/Lung9_Rep1/Lung9_Rep1-Flat_files_and_images/Lung9_Rep1_tx_file.csv
                    }
                ]
                folders: [
                    {
                        key: images
                        value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/COSMX_VER1/Lung9_Rep1/Lung9_Rep1-RawMorphologyImages
                    }
                    {
                        key: segmentation
                        value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/COSMX_VER1/Lung9_Rep1/Lung9_Rep1-Flat_files_and_images/CellLabels
                    }
                ]
                args: [
                    {
                        key: mpp
                        value: 0.18
                    }
                ]
                kwargs: []
                identities: []
            }
        ]
    }
    {
        sample_name: Human Lung Cancer - Sample 9 Rep 2
        data: [
            {
                name: Sample 9 Rep 2
                submission_type: SUBMIT_SPATIAL_TRANSCRIPTOMICS
                technology: COSMX_VER1
                files: [
                    {
                        key: fov_positions
                        value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/COSMX_VER1/Lung9_Rep2/Lung9_Rep2-Flat_files_and_images/Lung9_Rep2_fov_positions_file.csv
                    }
                    {
                        key: transcripts
                        value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/COSMX_VER1/Lung9_Rep2/Lung9_Rep2-Flat_files_and_images/Lung9_Rep2_tx_file.csv
                    }
                ]
                folders: [
                    {
                        key: images
                        value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/COSMX_VER1/Lung9_Rep2/Lung9_Rep2-RawMorphologyImages
                    }
                    {
                        key: segmentation
                        value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/COSMX_VER1/Lung9_Rep2/Lung9_Rep2-Flat_files_and_images/CellLabels
                    }
                ]
                args: [
                    {
                        key: mpp
                        value: 0.18
                    }
                ]
                kwargs: []
                identities: []
            }
        ]
    }
]
multiple_samples_submission_results = connector.submit_multiple_samples(
    group=DefaultGroup.PERSONAL_WORKSPACE.value,
    species=Species.HUMAN.value,
    title="Multiple Human Lung Cancer - CosMX Ver1",
    sample_data=multiple_cosmx_samples_submission_information,
)
spatialx_connector.format_print(multiple_samples_submission_results)
[
    {
        study_id: ST-01JMGMHYDGZ6G1VM6QNNYR4492
        sample_id: SP-01JMGMHZ2QWSXH2DHE3C8X6TCZ
        sample_data: [
            {
                data_id: DA-01JMGMHZ2QWSXH2DHE3FBFSD00
                submit_id: SB-01JMGMHZ2QWSXH2DHE38VKV8NS
                submit_name: Sample 6
            }
        ]
        submit_id: SB-01JMGMHZ2QWSXH2DHE38VKV8NS
        job_id: 5
        err_message:
    }
    {
        study_id: ST-01JMGMHYDGZ6G1VM6QNNYR4492
        sample_id: SP-01JMGMHZRSPPD8PH8CS157RWZX
        sample_data: [
            {
                data_id: DA-01JMGMHZRTJQXH6Z32WGYT9MDK
                submit_id: SB-01JMGMHZRSPPD8PH8CRZ0X1C30
                submit_name: Sample 9 Rep 1
            }
        ]
        submit_id: SB-01JMGMHZRSPPD8PH8CRZ0X1C30
        job_id: 6
        err_message:
    }
    {
        study_id: ST-01JMGMHYDGZ6G1VM6QNNYR4492
        sample_id: SP-01JMGMJ0ET0PYY4PRZMKQ9XXDT
        sample_data: [
            {
                data_id: DA-01JMGMJ0ET0PYY4PRZMN6R7SKW
                submit_id: SB-01JMGMJ0ET0PYY4PRZMJ5JF5H7
                submit_name: Sample 9 Rep 2
            }
        ]
        submit_id: SB-01JMGMJ0ET0PYY4PRZMJ5JF5H7
        job_id: 7
        err_message:
    }
]

Getting data_id to add extend elements add run analysis

DATA_ID = submission_results[ConnectorKeys.SAMPLE_DATA.value][0][ConnectorKeys.DATA_ID.value]

Getting more details information of the data

sample_data_info = connector.get_sample_data_detail(DATA_ID)
spatialx_connector.format_print(sample_data_info)
{
    data_id: DA-01JMGMH409ZPBZPQGHBCF4RXF6
    sample_id: SP-01JMGMH408Q5QDH2YPNXRR2WS6
    study_id: ST-01JMGMH3AT8HH8S23QV8ZC2G9T
    submit_id: SB-01JMGMH408Q5QDH2YPNWG5ZH46
    email_id: nhatnm@bioturing.com
    title: Xenium_V1_Human_Colon_Cancer_P2_CRC_Add_on_FFPE
    species_version:
    submission_type: SUBMIT_SPATIAL_TRANSCRIPTOMICS
    technology: XENIUM
    files:
    files_map: [
        {
            key: experiment
            value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/Human_Colon_Cancer_P2/Xenium_V1_Human_Colon_Cancer_P2_CRC_Add_on_FFPE/experiment.xenium
        }
        {
            key: images
            value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/Human_Colon_Cancer_P2/Xenium_V1_Human_Colon_Cancer_P2_CRC_Add_on_FFPE/morphology.ome.tif
        }
        {
            key: alignment
            value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/Human_Colon_Cancer_P2/Xenium_V1_Human_Colon_Cancer_P2_CRC_Add_on_FFPE/Xenium_V1_Human_Colon_Cancer_P2_CRC_Add_on_FFPE_he_imagealignment.csv
        }
        {
            key: segmentation
            value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/Human_Colon_Cancer_P2/Xenium_V1_Human_Colon_Cancer_P2_CRC_Add_on_FFPE/cell_boundaries.csv.gz
        }
        {
            key: transcripts
            value: /data/user_data/spatialx/data/4e3de55d66ef57b14c9119c90fd7f4e1/public_cloud/bioturingpublic/SpatialX_datasets/Human_Colon_Cancer_P2/Xenium_V1_Human_Colon_Cancer_P2_CRC_Add_on_FFPE/transcripts.csv.gz
        }
    ]
    folders:
    folders_map: []
    args:
    args_map: []
    identities:
    identities_map: []
    enable_status: 2
    by_bioturing_status: 0
    percent: 1
    setting:
    map_setting: {}
    submit_result: None
    map_submit_result: None
    extend_items:
    map_extend_items: []
    created_at: 1740020158
    updated_at: 1740020159
    job_id: 1
    analysis_id:
    sub_log_path:
}

Adding new segmentation to the data

add_segmentation_result = connector.add_sample_data_element(
    title="Proteomics Segmentation",
    study_id=sample_data_info[ConnectorKeys.STUDY_ID.value],
    sample_id=sample_data_info[ConnectorKeys.SAMPLE_ID.value],
    data_id=sample_data_info[ConnectorKeys.DATA_ID.value],
    adding_types=[ExtendSegmentationSubmission.PARQUET.value],
    paths={
        SubmissionElementKeys.SEGMENTATION.value: os.path.join(
            connector.s3["bioturingpublic"],
            "mount/examples/spatialx/human_pancreas_codex/human_pancreas_segmentation.parquet",
        )
    }
)
spatialx_connector.format_print(add_segmentation_result)
{
    study_id: ST-01JMGMH3AT8HH8S23QV8ZC2G9T
    sample_id: SP-01JMGMH408Q5QDH2YPNXRR2WS6
    sample_data: None
    submit_id: SB-01JMGMJG55Z7QT8V4S8V40M8Q5
    job_id: 8
    err_message:
}

Getting existed elements in the data

sample_data_elements = connector.get_sample_data_elements(DATA_ID)
spatialx_connector.format_print(sample_data_elements)

Adding new expression matrix to the data

add_expression_result = connector.add_sample_data_element(
    title="Proteomics Expression",
    study_id=sample_data_info[ConnectorKeys.STUDY_ID.value],
    sample_id=sample_data_info[ConnectorKeys.SAMPLE_ID.value],
    data_id=sample_data_info[ConnectorKeys.DATA_ID.value],
    adding_types=[ExtendExpressionSubmission.IMPORT_ANNDATA.value],
    paths={
        SubmissionElementKeys.EXPRESSION.value: os.path.join(
            connector.s3["bioturingpublic"],
            "mount/examples/spatialx/human_pancreas_codex/human_pancreas_protein.h5ad",
        ),
    },
    args={
        SubmissionElementKeys.SPATIAL_ID.value: sample_data_elements[SubmissionElementKeys.CELL_CENTERS.value][0],
    }
)
spatialx_connector.format_print(add_expression_result)

Analysis

data_id = submission_results[ConnectorKeys.SAMPLE_DATA.value][-1][ConnectorKeys.DATA_ID.value]
data_id

Embeddings

response = connector.analysis.embeddings.pca(data_id=data_id, title="Connector - PCA")
spatialx_connector.format_print(response)
{
    study_id: ST-01JCGFMAK3GBMXBEAE2FYE02DV
    sample_id: SP-01JCGFMB7GEV299VR986Z193DW
    data_id: DA-01JCGFMQ5GHYYEYRQKT0W061RF
    analysis_id: AN-01JCGGHV7N620FCZMXWHB03Z1W
    job_id: 3
}
response = connector.analysis.embeddings.scvi(data_id=data_id, title="Connector - scVI", n_top_genes=2000)
spatialx_connector.format_print(response)
{
    study_id: ST-01JCGFMAK3GBMXBEAE2FYE02DV
    sample_id: SP-01JCGFMB7GEV299VR986Z193DW
    data_id: DA-01JCGFMQ5GHYYEYRQKT0W061RF
    analysis_id: AN-01JCGGKWNF53MJBN8363YJHWEE
    job_id: 4
}
embeddings = connector.analysis.list_embedding(data_id)
spatialx_connector.format_print(embeddings)
    [
        Connector - PCA
        Spatial Cell centers
    ]
response = connector.analysis.embeddings.umap(data_id=data_id, embedding_key=embeddings[0], title="Connector - UMAP")
spatialx_connector.format_print(response)
{
    study_id: ST-01JCGFMAK3GBMXBEAE2FYE02DV
    sample_id: SP-01JCGFMB7GEV299VR986Z193DW
    data_id: DA-01JCGFMQ5GHYYEYRQKT0W061RF
    analysis_id: AN-01JCGGPV0M7TEWAG5F8T3GDYY1
    job_id: 5
}
response = connector.analysis.embeddings.tsne(data_id=data_id, embedding_key=embeddings[0], title="Connector - tSNE")
spatialx_connector.format_print(response)
{
    study_id: ST-01JCGFMAK3GBMXBEAE2FYE02DV
    sample_id: SP-01JCGFMB7GEV299VR986Z193DW
    data_id: DA-01JCGFMQ5GHYYEYRQKT0W061RF
    analysis_id: AN-01JCGGQH9ZJE3A8P4JPZRS2JPG
    job_id: 6
}

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)
{
    study_id: ST-01JCGFMAK3GBMXBEAE2FYE02DV
    sample_id: SP-01JCGFMB7GEV299VR986Z193DW
    data_id: DA-01JCGFMQ5GHYYEYRQKT0W061RF
    analysis_id: AN-01JCGGSSRGEP7KAKC47ZVBEDPK
    job_id: 7
}
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)
{
    study_id: ST-01JCGFMAK3GBMXBEAE2FYE02DV
    sample_id: SP-01JCGFMB7GEV299VR986Z193DW
    data_id: DA-01JCGFMQ5GHYYEYRQKT0W061RF
    analysis_id: AN-01JCGGY0VS4JR5VAKY5NXANJM1
    job_id: 9
}

Prediction

embeddings = connector.analysis.list_embedding(data_id)
spatialx_connector.format_print(embeddings)
[
    Connector - PCA
    Connector - UMAP
    Connector - scVI
    Connector - tSNE
    Spatial Cell centers
    UMAP - n_neighbors=15
    scVI - 20 latents - 486 top genes
    t-SNE - perplexity=30
]
metadata = connector.analysis.list_metadata(data_id)
spatialx_connector.format_print(metadata)
[
    Connector - Louvain
    Connector - Louvain (1)
    Connector - k-means
    Louvain clustering - resolution=0.1
    Louvain clustering - resolution=0.5
    Louvain clustering - resolution=1
    MetaReference prediction
    MetaReference prediction (1)
    Number of genes
    Number of mRNA transcripts
]
response = connector.analysis.prediction.metadata_reference(
    data_id=data_id,
    cluster_key=metadata[0],
    species=Species.HUMAN.value,
    title="Connector - Metadata Reference",
)
spatialx_connector.format_print(response)
{
    study_id: ST-01JCGFMAK3GBMXBEAE2FYE02DV
    sample_id: SP-01JCGFMB7GEV299VR986Z193DW
    data_id: DA-01JCGFMQ5GHYYEYRQKT0W061RF
    analysis_id: AN-01JCGM66JYNBRM5E890NTXHFDJ
    job_id: 14
}

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)
{
    study_id: ST-01JCGFMAK3GBMXBEAE2FYE02DV
    sample_id: SP-01JCGFMB7GEV299VR986Z193DW
    data_id: DA-01JCGFMQ5GHYYEYRQKT0W061RF
    analysis_id: AN-01JCGJZ1WP9EXMFRYHTVJAQE51
    job_id: 10
}

Spatial Analysis

response = connector.analysis.spatial_analysis.region_segmentation(
    data_id=data_id,
    radius=50,
    mpp=0.2125,
    resolution=0.5,
    species=Species.HUMAN.value,
    title="Connector - Region Segmentation",
)
spatialx_connector.format_print(response)
{
    study_id: ST-01JCGFMAK3GBMXBEAE2FYE02DV
    sample_id: SP-01JCGFMB7GEV299VR986Z193DW
    data_id: DA-01JCGFMQ5GHYYEYRQKT0W061RF
    analysis_id: AN-01JCGK68MJXRWVD450CAHS42JV
    job_id: 11
}

Convert data from Lens

!pip install bioturing_connector
Requirement already satisfied: bioturing_connector in /home/nhatnguyen/BioTuring/spatialx/pyapps/lib/python3.12/site-packages (1.13.0)
Requirement already satisfied: numpy in /home/nhatnguyen/BioTuring/spatialx/pyapps/lib/python3.12/site-packages (from bioturing_connector) (1.26.4)
Requirement already satisfied: pandas in /home/nhatnguyen/BioTuring/spatialx/pyapps/lib/python3.12/site-packages (from bioturing_connector) (2.2.2)
Requirement already satisfied: requests in /home/nhatnguyen/BioTuring/spatialx/pyapps/lib/python3.12/site-packages (from bioturing_connector) (2.32.3)
Requirement already satisfied: requests_toolbelt>=1.0.0 in /home/nhatnguyen/BioTuring/spatialx/pyapps/lib/python3.12/site-packages (from bioturing_connector) (1.0.0)
Requirement already satisfied: scipy in /home/nhatnguyen/BioTuring/spatialx/pyapps/lib/python3.12/site-packages (from bioturing_connector) (1.12.0)
Requirement already satisfied: tqdm in /home/nhatnguyen/BioTuring/spatialx/pyapps/lib/python3.12/site-packages (from bioturing_connector) (4.66.4)
Requirement already satisfied: charset-normalizer<4,>=2 in /home/nhatnguyen/BioTuring/spatialx/pyapps/lib/python3.12/site-packages (from requests->bioturing_connector) (3.3.2)
Requirement already satisfied: idna<4,>=2.5 in /home/nhatnguyen/BioTuring/spatialx/pyapps/lib/python3.12/site-packages (from requests->bioturing_connector) (3.10)
Requirement already satisfied: urllib3<3,>=1.21.1 in /home/nhatnguyen/BioTuring/spatialx/pyapps/lib/python3.12/site-packages (from requests->bioturing_connector) (1.26.20)
Requirement already satisfied: certifi>=2017.4.17 in /home/nhatnguyen/BioTuring/spatialx/pyapps/lib/python3.12/site-packages (from requests->bioturing_connector) (2024.8.30)
Requirement already satisfied: python-dateutil>=2.8.2 in /home/nhatnguyen/BioTuring/spatialx/pyapps/lib/python3.12/site-packages (from pandas->bioturing_connector) (2.9.0.post0)
Requirement already satisfied: pytz>=2020.1 in /home/nhatnguyen/BioTuring/spatialx/pyapps/lib/python3.12/site-packages (from pandas->bioturing_connector) (2024.2)
Requirement already satisfied: tzdata>=2022.7 in /home/nhatnguyen/BioTuring/spatialx/pyapps/lib/python3.12/site-packages (from pandas->bioturing_connector) (2024.2)
Requirement already satisfied: six>=1.5 in /home/nhatnguyen/BioTuring/spatialx/pyapps/lib/python3.12/site-packages (from python-dateutil>=2.8.2->pandas->bioturing_connector) (1.16.0)
LENS_SC_HOST: str = ""
LENS_SC_TOKEN: str = ""
lens_sc_studies = connector.list_lens_sc_studies(
    host=LENS_SC_HOST, token=LENS_SC_TOKEN,
    group=DefaultGroup.PERSONAL_WORKSPACE,
    species=Species.HUMAN.value,
)
spatialx_connector.format_print(lens_sc_studies)
Connecting to host at https://dev.bioturing.com/lens_sc/api/v1/test_connection
Connection successful
[
    {
        id: 96f6e21e9ac74f74bfe656a2a59ba058
        accession_id: XENIUM
        title: breast
        abstract: TBD
        authors: TBD
        reference: TBD
        species: human
        group_id: 662bd88b50da063e1870a4efc01fe185
    }
    {
        id: 49998dd7de8340c19a0acdd177b71fb4
        accession_id: XENIUM
        title: TBD
        abstract: TBD
        authors: TBD
        reference: TBD
        species: human
        group_id: 662bd88b50da063e1870a4efc01fe185
    }
]
# Convert a study
connector.convert_data_from_lens(lens_sc_studies[0])
LENS_BULK_HOST: str = ""
LENS_BULK_TOKEN: str = ""
lens_bulk_studies = connector.list_lens_bulk_studies(
    host=LENS_BULK_HOST, token=LENS_BULK_TOKEN,
    group=DefaultGroup.PERSONAL_WORKSPACE,
    species=Species.HUMAN.value,
)
spatialx_connector.format_print(lens_bulk_studies)
Connecting to host at https://dev.bioturing.com/lens_bulk/api/v1/test_connection
Connection successful
[
    {
        id: f92a884e42bf43749011d71593e727ba
        accession_id: VISIUM
        title: TBD
        abstract: TBD
        authors: TBD
        reference: TBD
        species: human
        group_id: 662bd88b50da063e1870a4efc01fe185
    }
    {
        id: 8b3e1737007c47fc81667f54ea998740
        accession_id: CURIO
        title: TBD
        abstract: TBD
        authors: TBD
        reference: TBD
        species: human
        group_id: 662bd88b50da063e1870a4efc01fe185
    }
]
# 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.7.tar.gz (29.0 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: spatialx_connector-0.1.7.tar.gz
  • Upload date:
  • Size: 29.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.14

File hashes

Hashes for spatialx_connector-0.1.7.tar.gz
Algorithm Hash digest
SHA256 5d70bb5ffcf76a10310f55133170687596f4e176eaa3c038a165b0c69f9a06c7
MD5 fc4a90b2c65b7a47a62f149a19a1ac65
BLAKE2b-256 c2c2e94150aaf9753547f51ce99f9811a15b3ea65aa424762f26c76aee36a541

See more details on using hashes here.

Supported by

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