spacec.archive namespace
Submodules
spacec.archive.tools_archive module
The function tl_cell_types_de performs differential enrichment analysis for various cell subsets between different neighborhoods using linear regression. It takes in several inputs such as cell type frequencies, neighborhood numbers, and patient information. The function first normalizes overall cell type frequencies and then neighborhood-specific cell type frequencies. Next, a linear regression model is fitted to find the coefficients and p-values for the group coefficient. Finally, the function returns a dataframe with the coefficients and p-values for each cell subset. The p-values can be corrected for multiple testing after the function has been executed.
- spacec.archive.tools_archive.tl_Chose_window_size(windows, n_num, n_neighborhoods, sum_cols, n2_name='neigh_ofneigh')[source]
- spacec.archive.tools_archive.tl_Create_neighborhoods(df, n_num, cluster_col, X, Y, regions, sum_cols=None, keep_cols=None, ks=[20])[source]
- spacec.archive.tools_archive.tl_analyze_image(path, output_dir, invert=False, properties_list=['label', 'centroid', 'area', 'perimeter', 'solidity', 'coords', 'axis_minor_length', 'axis_major_length', 'orientation', 'slice'])[source]
Analyze an image by performing connected component analysis on patches and storing their information.
The function applies image processing techniques such as Gaussian smoothing, thresholding, and connected component labeling to identify and analyze patches within the image. It extracts region properties of these patches, calculates their circularity, and stores the coordinates of their contour. The resulting information is saved in a DataFrame along with a visualization plot.
- Parameters:
path (str) – Path to the input image.
output_dir (str) – Directory to save the output plot.
invert (bool, optional) – Flag indicating whether to invert the image (default is False).
properties_list – (list of str): Define properties to be measured (see SciKit Image), by default “label”, “centroid”, “area”, “perimeter”, “solidity”, “coords”, “axis_minor_length”, “axis_major_length”, “orientation”, “slice”
- Returns:
- A tuple containing the DataFrame with region properties, including patch contour coordinates, and
the list of contour coordinates for each patch.
- Return type:
- spacec.archive.tools_archive.tl_apply_mask(image_path, mask_path, output_path)[source]
Apply a mask to an image and save the resulting masked image.
- spacec.archive.tools_archive.tl_cell_types_de(ct_freq, all_freqs, neighborhood_num, nbs, patients, group, cells, cells1)[source]
- spacec.archive.tools_archive.tl_corr_cell_ad(adata, per_categ, grouping_col, rep, sub_column, normed=True, sub_list2=None)[source]
Perform correlation analysis on a pandas DataFrame and plot correlation scatter plots.
- Parameters:
data (pandas DataFrame) – The input DataFrame.
per_categ (str) – The categorical column in the DataFrame to be used.
grouping_col (str) – The grouping column in the DataFrame.
rep (str) – The replicate column in the DataFrame.
sub_column (str) – The subcategory column in the DataFrame.
normed (bool, optional) – If the percentage should be normalized. Default is True.
sub_list2 (list, optional) – A list of subcategories to be considered. Default is None.
- Returns:
cmat (pandas DataFrame) – The correlation matrix DataFrame.
cc (pandas DataFrame) – The DataFrame after pivoting and formatting for correlation function.
- spacec.archive.tools_archive.tl_generate_info_dataframe(df, voronoi_output, mask_output, filter_list=None, info_cols=['tissue', 'donor', 'unique_region', 'region', 'array'])[source]
Generate a filtered DataFrame based on specific columns and values.
- Parameters:
df (pandas.DataFrame) – Input DataFrame.
voronoi_output (str) – Path to the Voronoi output directory.
mask_output (str) – Path to the mask output directory.
info_cols (list) – columns to extract from input df
filter_list (list, optional) – List of values to filter.
- Returns:
Filtered DataFrame.
- Return type:
- spacec.archive.tools_archive.tl_generate_mask(path, output_dir, filename='mask.png', filter_size=5, threshold_value=5)[source]
Generate a mask from a maximum projection of an input image.
- Parameters:
path (str) – Path to the input image.
output_dir (str) – Directory to save the generated mask and quality control plot.
filename (str, optional) – Name of the generated mask file (default is “mask.png”).
filter_size (int, optional) – Size of the filter disk used for image processing (default is 5).
threshold_value (int, optional) – Threshold value for binary conversion (default is 5).
- Returns:
None
- spacec.archive.tools_archive.tl_generate_masks_from_images(image_folder, mask_output, image_type='.tif', filter_size=5, threshold_value=10)[source]
Generate binary masks from CODEX images.
- Parameters:
image_folder (str) – Directory that contains the images that are used to generate the masks
mask_output (str) – Directory to store the generated masks
image_type (str) – File type of image. By default “.tif”
filter_size (num) – Size for filter disk during mask generation
threshold_value (num) – Threshold value for binary mask generation
- Returns:
None
- spacec.archive.tools_archive.tl_generate_voronoi_plots(df, output_path, grouping_col='Community', tissue_col='tissue', region_col='unique_region', x_col='x', y_col='y')[source]
Generate Voronoi plots for unique combinations of tissue and region.
- Parameters:
df (pandas.DataFrame) – Input DataFrame containing the data.
output_path (str) – Output path to save the plots.
grouping_col (str) – Column that contains group label that is used to color the voronoi diagrams
tissue_col (str) – Column that contains tissue labels
region_col (str) – Column that contains region labels
x_col (str) – Column that contains x coordinates
y_col (str) – Column that contains y coordinates
- Returns:
None
- spacec.archive.tools_archive.tl_process_data(df_info, output_dir_csv)[source]
Process data based on the information provided in the DataFrame.
- Parameters:
df_info (pandas.DataFrame) – DataFrame containing the information.
output_dir_csv (str) – Output directory for CSV results.
- Returns:
Concatenated DataFrame of results. list: List of contours.
- Return type:
- spacec.archive.tools_archive.tl_process_files(voronoi_path, mask_path, region)[source]
Process files based on the provided paths and region.
- spacec.archive.tools_archive.tl_spatial_context_stats(n_num, patient_ID_component1, patient_ID_component2, windows, total_per_thres=0.9, comb_per_thres=0.005, tissue_column='Block type', subset_list=['Resection'], plot_order=['Resection', 'Biopsy'], pal_tis={'Biopsy': 'orange', 'Resection': 'blue'}, subset_list_tissue1=['Resection'], subset_list_tissue2=['Biopsy'])[source]