mdvtools.mdvproject =================== .. py:module:: mdvtools.mdvproject Attributes ---------- .. autoapisummary:: mdvtools.mdvproject.DataSourceName mdvtools.mdvproject.ColumnName mdvtools.mdvproject.Cols mdvtools.mdvproject.datatype_mappings mdvtools.mdvproject.numpy_dtypes mdvtools.mdvproject.path Classes ------- .. autoapisummary:: mdvtools.mdvproject.MDVProject Functions --------- .. autoapisummary:: mdvtools.mdvproject.get_json mdvtools.mdvproject.save_json mdvtools.mdvproject.get_subgroup_bytes mdvtools.mdvproject.add_column_to_group mdvtools.mdvproject.get_column_info mdvtools.mdvproject.check_htslib mdvtools.mdvproject.create_bed_gz_file mdvtools.mdvproject.get_random_string Module Contents --------------- .. py:data:: DataSourceName .. py:data:: ColumnName .. py:data:: Cols .. py:data:: datatype_mappings .. py:data:: numpy_dtypes .. py:class:: MDVProject(dir: str, id: Optional[str] = None, delete_existing=False, skip_column_clean=True, backend_db=False) .. py:attribute:: skip_column_clean :value: True .. py:attribute:: dir .. py:attribute:: id .. py:attribute:: h5file .. py:attribute:: datasourcesfile .. py:attribute:: statefile .. py:attribute:: viewsfile .. py:attribute:: imagefolder .. py:attribute:: trackfolder .. py:attribute:: _lock .. py:attribute:: backend_db :value: False .. py:property:: datasources .. py:property:: views :type: dict[str, mdvtools.charts.view.View] .. py:property:: state .. py:method:: set_editable(edit) .. py:method:: lock(type='read') .. py:method:: get_column_metadata(datasource, column) .. py:method:: set_column_metadata(datasource, column, parameter, value) .. py:method:: get_datasource_as_dataframe(datasource: str) -> pandas.DataFrame .. py:method:: check_columns_exist(datasource, columns) .. py:method:: get_datasource_names() -> list[str] Get a list of all datasource names in the project. :returns: A list of datasource names :rtype: list[str] .. py:method:: 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) See `spatialdata.md` for documentation... .. py:method:: get_datasource_metadata(name) .. py:method:: set_datasource_metadata(ds) .. py:method:: add_images_to_datasource(ds: str, image_folder: str, key_column: str, name='Images', image_type='png') 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 .. py:method:: add_or_update_image_datasource(tiff_metadata, datasource_name, file) Add or update an image datasource in datasources.json returns the name of the added view so the user can navigate to it .. py:method:: upload_image_file(file, upload_file_path) Upload the TIFF file to the imagefolder, saving it with the original filename. .. py:method:: delete_uploaded_image(file_path) Delete the uploaded image file at the specified path. .. py:method:: restore_datasource(datasource_backup) Restore the datasource from the backup. .. py:method:: update_datasource_for_tiff(datasource, datasource_name, tiff_metadata, region_name: str) Update an existing datasource with new image metadata. .. py:method:: create_datasource_template(datasource_name: str) -> dict Create a new datasource template with the basic structure. .. py:method:: ensure_regions_fields(regions, position_fields=['x', 'y'], region_field='sample_id', default_color='leiden', scale_unit='µm', scale=1.0) .. py:method:: get_image(path: str) Gets the filename of an image. .. py:method:: _get_h5_handle(read_only=False, attempt=0) -> h5py.File .. py:method:: get_column(datasource: str, column, raw=False) .. py:method:: set_column_with_raw_data(datasource, column, raw_data) 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 .. py:method:: set_column(datasource, column, data) Adds (or replaces an existing column) with the data supplied :param datasource: The name of the datasource. :type datasource: str :param column: 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 :type column: str|dict :param raw_data: Anything that can be converted into a pandas Series :type raw_data: list|array :param The data should be in the correct order: .. py:method:: remove_column(datasource, column) Removes the specified column :param datasource: The name of the data source. :type datasource: str :param column: The id (field) of the column. :type column: str .. py:method:: add_annotations(datasource: str, data: pandas.DataFrame | str, separator='\t', missing_value='ND', columns=[], supplied_columns_only=False) Adds annotations based on an existing column :param datasource: The name of the data source. :type datasource: str :param data: 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. :type data: dataframe|str :param separator: The delimiter if a text file is supplied (tab by default) :type separator: str,optional :param missing_value: The value to put if the index value is missing in the input data. Default is 'ND' :type missing_value: str,optional .. py:method:: set_column_group(datasource, groupname, columns) Adds (or changes) a column group :param datasource: The name of the datasource :type datasource: string :param groupname: The name of the column group :type groupname: string :param columns: The field names of columns in the group. If None, then the column group will be removed :type columns: list .. py:method:: delete_datasource(name, delete_views=True) .. py:method:: add_genome_browser(datasource, parameters=['chr', 'start', 'end'], name=None, extra_params=None, custom_track=None, overwrite=False) :param datasource: The name of the datasource :type datasource: string :param parameters: The names of the columns containing the chromosome, start and end positions. Defaults to ["chr","start","end"] :type parameters: list, optional :param name: The name of the genome browser track. Defaults to the datasource name. :type name: string, optional .. py:method:: get_genome_browser(datasource) .. py:method:: add_refseq_track(datasource, genome) .. py:method:: add_datasource(name: str, dataframe: pandas.DataFrame | str, columns: Optional[list] = None, supplied_columns_only=False, replace_data=False, add_to_view: Optional[str] = 'default', separator='\t') -> list[dict[str, str]] 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. :param name: The name of datasource :type name: string :param dataframe: Either a pandas dataframe or the path of a text file :type dataframe: dataframe|str :param columns: A list of objects containing the column name and datatype. :type columns: list, optional :param supplied_columns_only: If True, only the the subset of columns in the columns argument :type supplied_columns_only: bool, optional :param replace_data: If True, the existing datasource will be overwritten, Default is False, :type replace_data: bool, optional :param add_to_view: The datasource will be added to the specified view. :type add_to_view: string, optional :param separator: If a path to text file is supplied, then this should be the file's delimiter. :type separator: str, optional .. py:method:: create_table_plot(title, params, size, position) Create and configure a TablePlot instance with the given parameters. .. py:method:: convert_plot_to_json(plot) Convert plot data to JSON format. .. py:method:: insert_link(datasource, linkto, linktype, data) 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. .. py:method:: add_rows_as_columns_link(ds_row: str, ds_col: str, column_name: str, name: str) 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. :param ds_row: The name of the datasource into which the link will be added :type ds_row: string :param ds_col: The name of the datasource containing the columns :type ds_col: string :param column_name: 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 :type column_name: string :param name: The name of the link that will appear in the interface to describe the nature of the data being added, e.g. `'Gene Expr'` :type name: string .. py:method:: add_rows_as_columns_subgroup(row_ds: str, col_ds: str, stub: str, data, name: Optional[str] = None, label: Optional[str] = None, sparse=False) Add rows as columns in a subgroup. .. py:method:: get_links(datasource, filter=None) .. py:method:: serve(**kwargs) .. py:method:: delete() .. py:method:: get_configs() .. py:method:: convert_to_static_page(outdir, include_sab_headers=True) .. py:method:: copy_images(outdir) .. py:method:: save_state(state) .. py:method:: add_image_set(datasource, setname, column, folder, type='png') 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 .. py:method:: get_view(view: str) .. py:method:: set_view(name: str, view: Optional[mdvtools.charts.view.View | Any], make_default=False) Sets the view with the given name to the supplied view data. If the view is None, then the view will be deleted. .. py:method:: convert_data_to_binary(outdir=None) .. py:method:: get_byte_data(columns, group) .. py:method:: set_region_data(datasource, data, region_field='sample_id', default_color='annotations', position_fields=['x', 'y'], scale_unit='µm', scale=1.0) .. py:method:: add_region_images(datasource: DataSourceName, data) Adds images to regions in a datasource. :param datasource: The name of the datasource. :type datasource: str :param data: A dictionary containing data about which images should be associated with :type data: dict|str .. py:method:: add_viv_viewer(datasource_name, default_channels) Add a Viv viewer to the specified datasource with default channels. .. py:method:: add_viv_images(datasource, data, link_images=True) .. py:method:: get_interaction_matrix(datasource, group, interaction_metric, square_size=20) :param datasource: The name of the datasource. :type datasource: str :param group: The name of the group. :type group: str :param interaction_metric: The name of the interaction metric. :type interaction_metric: str .. py:method:: get_selection_dialog(datasource, selections) .. py:method:: get_image_plot(datsource, image_set) .. py:method:: get_centroid_plot(datasource, region, background_image='_default', scale=0.5) :param datasource: The name of the datasource. :type datasource: str :param region: The name of the region. :type region: str :param background_image: The name of the background image. Default is '_default' :type background_image: str, optional :param scale: The scale of the image. Default is 0.5 :type scale: float, optional :returns: The chart specification. :rtype: dict .. py:function:: get_json(file) .. py:function:: save_json(file, data) .. py:function:: get_subgroup_bytes(grp, index, sparse=False) .. py:function:: add_column_to_group(col: dict, data: pandas.Series | pandas.DataFrame, group: h5py.Group, length: int, skip_column_clean: bool) 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 .. py:function:: get_column_info(columns, dataframe, supplied_columns_only) .. py:function:: check_htslib() .. py:function:: create_bed_gz_file(infile, outfile) .. py:function:: get_random_string(length=6) .. py:data:: path