mdvtools.mdvproject

Attributes

DataSourceName

ColumnName

Cols

datatype_mappings

numpy_dtypes

path

Classes

MDVProject

Functions

get_json(file)

save_json(file, data)

get_subgroup_bytes(grp, index[, sparse])

add_column_to_group(col, data, group, length, ...)

col (dict): The column metadata (may be modified e.g. to add values)

get_column_info(columns, dataframe, supplied_columns_only)

check_htslib()

create_bed_gz_file(infile, outfile)

get_random_string([length])

Module Contents

mdvtools.mdvproject.DataSourceName[source]
mdvtools.mdvproject.ColumnName[source]
mdvtools.mdvproject.Cols[source]
mdvtools.mdvproject.datatype_mappings[source]
mdvtools.mdvproject.numpy_dtypes[source]
class mdvtools.mdvproject.MDVProject(dir: str, id: str | None = None, delete_existing=False, skip_column_clean=True, backend_db=False)[source]
skip_column_clean = True[source]
dir[source]
id[source]
h5file[source]
datasourcesfile[source]
statefile[source]
viewsfile[source]
imagefolder[source]
trackfolder[source]
_lock[source]
backend_db = False[source]
property datasources[source]
property views: dict[str, mdvtools.charts.view.View][source]
property state[source]
set_editable(edit)[source]
lock(type='read')[source]
get_column_metadata(datasource, column)[source]
set_column_metadata(datasource, column, parameter, value)[source]
get_datasource_as_dataframe(datasource: str) pandas.DataFrame[source]
check_columns_exist(datasource, columns)[source]
get_datasource_names() list[str][source]

Get a list of all datasource names in the project.

Returns:

A list of datasource names

Return type:

list[str]

set_interactions(interaction_ds: str, parent_ds: str, pivot_column='sample_id', parent_column='annotation', is_single_region=True, interaction_columns=['Cell Type 1', 'Cell Type 2'], default_parameter='Cross PCF gr20', node_size='cell 1 number', add_view=True)[source]

See spatialdata.md for documentation…

get_datasource_metadata(name)[source]
set_datasource_metadata(ds)[source]
add_images_to_datasource(ds: str, image_folder: str, key_column: str, name='Images', image_type='png')[source]

Adds images to a datasource. These will be copied as static assets with convert_to_static_page(), and served from their original location by serve(). :param ds: The name of the datasource. :type ds: str :param image_folder: The folder containing the images. :type image_folder: str :param key_column: The name of the column in ds containing the image names. :type key_column: str :param name: The name of the image set. Defaults to “Images”. :type name: str, optional :param image_type: The image type. Defaults to “png”. :type image_type: str, optional

add_or_update_image_datasource(tiff_metadata, datasource_name, file)[source]

Add or update an image datasource in datasources.json returns the name of the added view so the user can navigate to it

upload_image_file(file, upload_file_path)[source]

Upload the TIFF file to the imagefolder, saving it with the original filename.

delete_uploaded_image(file_path)[source]

Delete the uploaded image file at the specified path.

restore_datasource(datasource_backup)[source]

Restore the datasource from the backup.

update_datasource_for_tiff(datasource, datasource_name, tiff_metadata, region_name: str)[source]

Update an existing datasource with new image metadata.

create_datasource_template(datasource_name: str) dict[source]

Create a new datasource template with the basic structure.

ensure_regions_fields(regions, position_fields=['x', 'y'], region_field='sample_id', default_color='leiden', scale_unit='µm', scale=1.0)[source]
get_image(path: str)[source]

Gets the filename of an image.

_get_h5_handle(read_only=False, attempt=0) h5py.File[source]
get_column(datasource: str, column, raw=False)[source]
set_column_with_raw_data(datasource, column, raw_data)[source]

Adds or updates a column with raw data :param datasource: The name of the datasource. :type datasource: str :param column: The complete metadata for the column :type column: dict :param raw_data: The raw binary data for the column :type raw_data: list|array

set_column(datasource, column, data)[source]

Adds (or replaces an existing column) with the data supplied

Parameters:
  • datasource (str) – The name of the datasource.

  • column (str|dict) – metadata for the column. Can be a string with the column’s name, although datatype should also be included as the inferred datatype is not always correct

  • raw_data (list|array) – Anything that can be converted into a pandas Series

  • order (The data should be in the correct)

remove_column(datasource, column)[source]

Removes the specified column

Parameters:
  • datasource (str) – The name of the data source.

  • column (str) – The id (field) of the column.

add_annotations(datasource: str, data: pandas.DataFrame | str, separator='\t', missing_value='ND', columns=[], supplied_columns_only=False)[source]

Adds annotations based on an existing column

Parameters:
  • datasource (str) – The name of the data source.

  • data (dataframe|str) – Either a pandas dataframe or a text file. The first column should be the ‘index’ column and match a column in the datasource. The other columns should contain the annotations to add.

  • separator (str,optional) – The delimiter if a text file is supplied (tab by default)

  • missing_value (str,optional) – The value to put if the index value is missing in the input data. Default is ‘ND’

set_column_group(datasource, groupname, columns)[source]

Adds (or changes) a column group

Parameters:
  • datasource (string) – The name of the datasource

  • groupname (string) – The name of the column group

  • columns (list) – The field names of columns in the group. If None, then the column group will be removed

delete_datasource(name, delete_views=True)[source]
add_genome_browser(datasource, parameters=['chr', 'start', 'end'], name=None, extra_params=None, custom_track=None, overwrite=False)[source]
Parameters:
  • datasource (string) – The name of the datasource

  • parameters (list, optional) – The names of the columns containing the chromosome, start and end positions. Defaults to [“chr”,”start”,”end”]

  • name (string, optional) – The name of the genome browser track. Defaults to the datasource name.

get_genome_browser(datasource)[source]
add_refseq_track(datasource, genome)[source]
add_datasource(name: str, dataframe: pandas.DataFrame | str, columns: list | None = None, supplied_columns_only=False, replace_data=False, add_to_view: str | None = 'default', separator='\t') list[dict[str, str]][source]

Adds a pandas dataframe to the project. Each column’s datatype, will be deduced by the data it contains, but this is not always accurate. Hence, you can supply a list of column metadata, which will override the names/types deduced from the dataframe.

Parameters:
  • name (string) – The name of datasource

  • dataframe (dataframe|str) – Either a pandas dataframe or the path of a text file

  • columns (list, optional) – A list of objects containing the column name and datatype.

  • supplied_columns_only (bool, optional) – If True, only the the subset of columns in the columns argument

  • replace_data (bool, optional) – If True, the existing datasource will be overwritten, Default is False,

  • add_to_view (string, optional) – The datasource will be added to the specified view.

  • separator (str, optional) – If a path to text file is supplied, then this should be the file’s delimiter.

create_table_plot(title, params, size, position)[source]

Create and configure a TablePlot instance with the given parameters.

convert_plot_to_json(plot)[source]

Convert plot data to JSON format.

Adds a link between two datasources. datasource is the name of the datasource to which the link will be added. linkto is the name of the datasource to which the link will point. linktype is the type of link to add. The data argument is a dictionary containing the data for the link, the format of which depends on the linktype.

Adds a link between two datasources, such that columns may be added to the ds_row datasource based on the values in the ds_col datasource dynamically at runtime. The values in the column_name column of the ds_col datasource will be used as the names for the columns added to the ds_row datasource.

Parameters:
  • ds_row (string) – The name of the datasource into which the link will be added

  • ds_col (string) – The name of the datasource containing the columns

  • column_name (string) – The name of a column in the ds_col datasource, the row-value of which will be used as the column name for columns dynamically added to the ds_row datasource

  • name (string) – The name of the link that will appear in the interface to describe the nature of the data being added, e.g. ‘Gene Expr’

add_rows_as_columns_subgroup(row_ds: str, col_ds: str, stub: str, data, name: str | None = None, label: str | None = None, sparse=False)[source]

Add rows as columns in a subgroup.

serve(**kwargs)[source]
delete()[source]
get_configs()[source]
convert_to_static_page(outdir, include_sab_headers=True)[source]
copy_images(outdir)[source]
save_state(state)[source]
add_image_set(datasource, setname, column, folder, type='png')[source]

Adds a set of images to a datasource. The images should be in a folder, with the same name as the column :param datasource: The name of the datasource. :type datasource: str :param column: The name of the column. :type column: str :param folder: The path to the folder containing the images. :type folder: str

get_view(view: str)[source]
set_view(name: str, view: mdvtools.charts.view.View | Any | None, make_default=False)[source]

Sets the view with the given name to the supplied view data. If the view is None, then the view will be deleted.

convert_data_to_binary(outdir=None)[source]
get_byte_data(columns, group)[source]
set_region_data(datasource, data, region_field='sample_id', default_color='annotations', position_fields=['x', 'y'], scale_unit='µm', scale=1.0)[source]
add_region_images(datasource: DataSourceName, data)[source]

Adds images to regions in a datasource.

Parameters:
  • datasource (str) – The name of the datasource.

  • data (dict|str) – A dictionary containing data about which images should be associated with

add_viv_viewer(datasource_name, default_channels)[source]

Add a Viv viewer to the specified datasource with default channels.

add_viv_images(datasource, data, link_images=True)[source]
get_interaction_matrix(datasource, group, interaction_metric, square_size=20)[source]
Parameters:
  • datasource (str) – The name of the datasource.

  • group (str) – The name of the group.

  • interaction_metric (str) – The name of the interaction metric.

get_selection_dialog(datasource, selections)[source]
get_image_plot(datsource, image_set)[source]
get_centroid_plot(datasource, region, background_image='_default', scale=0.5)[source]
Parameters:
  • datasource (str) – The name of the datasource.

  • region (str) – The name of the region.

  • background_image (str, optional) – The name of the background image. Default is ‘_default’

  • scale (float, optional) – The scale of the image. Default is 0.5

Returns:

The chart specification.

Return type:

dict

mdvtools.mdvproject.get_json(file)[source]
mdvtools.mdvproject.save_json(file, data)[source]
mdvtools.mdvproject.get_subgroup_bytes(grp, index, sparse=False)[source]
mdvtools.mdvproject.add_column_to_group(col: dict, data: pandas.Series | pandas.DataFrame, group: h5py.Group, length: int, skip_column_clean: bool)[source]

col (dict): The column metadata (may be modified e.g. to add values) data (pandas.Series): The data to add group (h5py.Group): The group to add the data to length (int): The length of the data

mdvtools.mdvproject.get_column_info(columns, dataframe, supplied_columns_only)[source]
mdvtools.mdvproject.check_htslib()[source]
mdvtools.mdvproject.create_bed_gz_file(infile, outfile)[source]
mdvtools.mdvproject.get_random_string(length=6)[source]
mdvtools.mdvproject.path[source]