mdvtools.conversions
Functions
|
Convert a Scanpy AnnData object to MDV (Multi-Dimensional Viewer) format. |
|
|
|
|
|
Compute the end position of the variant determined from 'POS', 'REF' and 'ALT'. |
|
Converts a VCF file to an MDV project. |
|
|
|
|
|
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:
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.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’.