mdvtools.conversions

Functions

convert_scanpy_to_mdv(→ mdvtools.mdvproject.MDVProject)

Convert a Scanpy AnnData object to MDV (Multi-Dimensional Viewer) format.

convert_mudata_to_mdv(→ mdvtools.mdvproject.MDVProject)

convert_vcf_to_df(→ pandas.DataFrame)

compute_vcf_end(→ pandas.DataFrame)

Compute the end position of the variant determined from 'POS', 'REF' and 'ALT'.

convert_vcf_to_mdv(→ mdvtools.mdvproject.MDVProject)

Converts a VCF file to an MDV project.

create_regulamentary_project(folder, output, name[, ...])

_create_dt_heatmap(folder, project, mdv, marks)

_add_dims(table, dims, max_dims)

Module Contents

mdvtools.conversions.convert_scanpy_to_mdv(folder: str, scanpy_object: scanpy.AnnData, max_dims: int = 3, delete_existing: bool = False, label: str = '') mdvtools.mdvproject.MDVProject[source]

Convert a Scanpy AnnData object to MDV (Multi-Dimensional Viewer) format.

This function transforms single-cell RNA sequencing data from AnnData format into the MDV project structure, handling both cells and genes as separate datasources with their associated dimensionality reductions and metadata.

Parameters:
  • folder (str) – Path to the target MDV project folder

  • scanpy_object (AnnData) – The AnnData object containing the single-cell data

  • max_dims (int, optional) – Maximum number of dimensions to include from dimensionality reductions. Defaults to 3.

  • delete_existing (bool, optional) – Whether to delete existing project data. If False, merges with existing data. Defaults to False.

  • label (str, optional) – Prefix to add to datasource names and metadata columns when merging with existing data. Defaults to “”.

Returns:

The configured MDV project object with the converted data

Return type:

MDVProject

Notes

Data Structure Creation: - Creates two main datasources: ‘{label}cells’ and ‘{label}genes’ - Preserves all cell metadata from scanpy_object.obs - Preserves all gene metadata from scanpy_object.var - Transfers dimension reductions from obsm/varm matrices - Links cells and genes through expression data - Adds gene expression scores as a subgroup

View Handling: - If delete_existing=True:

  • Creates new default view with empty initial charts

  • Sets project as editable

  • If delete_existing=False:
    • Preserves existing views

    • Updates views with new datasources

    • Maintains panel widths and other view settings

    • Adds new datasources to each view’s initialCharts

Dimension Reduction: - Processes dimensionality reductions up to max_dims - Supports standard formats (e.g., PCA, UMAP, t-SNE) - Column names in the format: {reduction_name}_{dimension_number}

Raises:
  • ValueError – If the provided AnnData object is invalid or missing required components

  • IOError – If there are issues with file operations in the target folder

  • Exception – For other unexpected errors during conversion

mdvtools.conversions.convert_mudata_to_mdv(folder: str, mudata_object: mudata.MuData, max_dims=3) mdvtools.mdvproject.MDVProject[source]
mdvtools.conversions.convert_vcf_to_df(vcf_filename: str) pandas.DataFrame[source]
mdvtools.conversions.compute_vcf_end(df: pandas.DataFrame) pandas.DataFrame[source]

Compute the end position of the variant determined from ‘POS’, ‘REF’ and ‘ALT’.

This is added as a column ‘END’ in the given DataFrame.

mdvtools.conversions.convert_vcf_to_mdv(folder: str, vcf_filename: str) mdvtools.mdvproject.MDVProject[source]

Converts a VCF file to an MDV project. The VCF file must be tab-delimited, with the header lines starting with “##” and column names in the line starting with “#CHROM”.

An ‘END’ column is derived, which is the end position of the variant determined from ‘POS’, ‘REF’ and ‘ALT’.

mdvtools.conversions.create_regulamentary_project(folder, output: str, name: str, bigwig_folder='', bed_folder='', openchrome='DNase', openchrome_color='#eb9234', marks=['H3K4me1', 'H3K4me3', 'H3K27ac', 'CTCF'], mark_colors=['#349beb', '#3aeb34', '#c4c41f', '#ab321a'], genome='hg38')[source]
mdvtools.conversions._create_dt_heatmap(folder, project, mdv, marks)[source]
mdvtools.conversions._add_dims(table, dims, max_dims)[source]