mdvtools.mdvproject
Attributes
Classes
Functions
|
|
|
|
|
|
|
col (dict): The column metadata (may be modified e.g. to add values) |
|
|
|
|
|
Module Contents
- class mdvtools.mdvproject.MDVProject(dir: str, id: str | None = None, delete_existing=False, skip_column_clean=True, backend_db=False)[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…
- 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.
- 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]
- 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
- 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.
- 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.
- insert_link(datasource, linkto, linktype, data)[source]
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.
- add_rows_as_columns_link(ds_row: str, ds_col: str, column_name: str, name: str)[source]
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.
- 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
- 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.
- 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.
- 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_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.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