Skip to content

Commit

Permalink
errors_correction2
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiomarco25 committed Dec 19, 2024
1 parent 57f05ea commit 08d8e9d
Show file tree
Hide file tree
Showing 12 changed files with 36 additions and 110 deletions.
6 changes: 2 additions & 4 deletions notebooks/spatialdata_tutorials/4_explore_comunication.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,13 @@
" - sdata: AnnData object\n",
" A spatial data object containing the 'table' and 'xrna_metadata' components.\n",
" - proportion_threshold: float, optional (default=0.2)\n",
" The threshold for filtering significant gene proportions. Genes with proportions \n",
" above this value are considered significant.\n",
" The threshold for filtering significant gene proportions. Genes with proportions above this value are considered significant.\n",
" - cell_type_key: str, optional (default='cell type')\n",
" The key in `adata.obs` that contains the cell type annotations.\n",
"\n",
" Returns:\n",
" - number_interactions_df: pandas.DataFrame\n",
" A DataFrame where rows represent source cell types, columns represent target cell \n",
" types, and values indicate the number of significant genes shared between them.\n",
" A DataFrame where rows represent source cell types, columns represent target cell types, and values indicate the number of significant genes shared between them.\n",
" \"\"\"\n",
" adata=sdata['table']\n",
" source_proportions=pd.DataFrame(sdata['xrna_metadata'].varm['source'],index=sdata['xrna_metadata'].var.index,columns=adata.obs[cell_type_key].unique().dropna())\n",
Expand Down
75 changes: 0 additions & 75 deletions src/troutpy/merge_all_data.py

This file was deleted.

4 changes: 2 additions & 2 deletions src/troutpy/pl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .plotting import sorted_heatmap,coupled_scatter,heatmap,plot_crosstab,pie_of_positive,genes_over_noise
from .plotting import moranI_histogram,proportion_above_threshold,nmf_factors_exrna_cells_W
from .plotting import apply_exrnaH_to_cellular_to_create_cellularW,W
from .plotting import *
from .plotting import nmf_gene_contributions,apply_exrnaH_to_cellular_to_create_cellularW,paired_nmf_factors
from .plotting import W,spatial_interactions,interactions_with_arrows
12 changes: 4 additions & 8 deletions src/troutpy/pl/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@ def plot_crosstab(data, xvar: str = '', yvar: str = '', normalize=True, axis=1,

def pie_of_positive(data, groupby: str = '', figures_path: str = '', save: bool = True):
"""
Generates a pie chart showing the proportion of positive and negative values
for a specified categorical variable in the data.
Generates a pie chart showing the proportion of positive and negative values for a specified categorical variable in the data.
Parameters
----------
Expand All @@ -284,8 +283,7 @@ def pie_of_positive(data, groupby: str = '', figures_path: str = '', save: bool
Returns
-------
None
The function generates and either saves or displays a pie chart,
depending on the value of the `save` parameter.
The function generates and either saves or displays a pie chart, depending on the value of the `save` parameter.
"""

plt.figure()
Expand All @@ -300,8 +298,7 @@ def pie_of_positive(data, groupby: str = '', figures_path: str = '', save: bool
plt.savefig(os.path.join(figures_path, plot_filename))

def genes_over_noise(sdata, scores_by_genes,layer='extracellular_transcripts', output_path:str='',save=True,format:str='pdf'):
"""
This function plots log fold change per gene over noise using a boxplot.
"""This function plots log fold change per gene over noise using a boxplot.
Parameters:
- data_quantified: DataFrame containing the extracellular transcript data, including feature names and codeword categories.
Expand Down Expand Up @@ -333,8 +330,7 @@ def genes_over_noise(sdata, scores_by_genes,layer='extracellular_transcripts', o
plt.show()

def moranI_histogram(svg_df, save=True, figures_path: str = '', bins: int = 200, format: str = 'pdf'):
"""
Plots the distribution of Moran's I scores from a DataFrame.
"""Plots the distribution of Moran's I scores from a DataFrame.
Parameters:
-----------
Expand Down
4 changes: 2 additions & 2 deletions src/troutpy/pp/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .compute import *
from .format import *
from .compute import compute_extracellular_counts,define_extracellular,compute_crosstab
from .format import format_adata
22 changes: 17 additions & 5 deletions src/troutpy/pp/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,22 @@ def define_extracellular(

return sdata if copy else None

#
def compute_crosstab(data, xvar: str = '', yvar: str = ''):
"""Compute a crosstabulation (contingency table) of two categorical variables from the given DataFrame.
Parameters:
-----------
data : pandas.DataFrame
The input DataFrame containing the data to be analyzed.
xvar : str, optional
The name of the column to use as the rows of the crosstab. Default is an empty string.
yvar : str, optional
The name of the column to use as the columns of the crosstab. Default is an empty string.
def compute_crosstab(data,xvar:str='',yvar:str=''):
"""Compute crosstabs for each given variable"""
crosstab_data= pd.crosstab(data[xvar], data[yvar])
return crosstab_data
Returns:
--------
pandas.DataFrame
A DataFrame representing the crosstab of the specified variables, with counts of occurrences for each combination of categories.
"""
crosstab_data = pd.crosstab(data[xvar], data[yvar])
return crosstab_data
3 changes: 1 addition & 2 deletions src/troutpy/pp/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@

def format_adata(input_path, outpath_dummy, xlimits, ylimits):
"""
Processes and formats AnnData and transcripts by loading data, merging cell information,
applying spatial filters, and saving the processed data to a dummy output directory.
Processes and formats AnnData and transcripts by loading data, merging cell information,applying spatial filters, and saving the processed data to a dummy output directory.
Args:
input_path (str): Path to the input directory containing:
Expand Down
14 changes: 7 additions & 7 deletions src/troutpy/tl/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .source_cell import *
from .target_cell import *
from .estimate_density import *
from .quantify_xrna import *
from .interactions import *
from .NMF import *
from .segmentation_free import *
from .source_cell import create_xrna_metadata,compute_source_cells,distance_to_source_cell,compute_distant_cells_prop,get_proportion_expressed_per_cell_type
from .target_cell import calculate_target_cells,define_target_by_celltype
from .estimate_density import colocalization_proportion
from .quantify_xrna import spatial_variability,create_xrna_metadata,quantify_overexpression,extracellular_enrichment,spatial_colocalization
from .interactions import get_number_of_communication_genes,get_gene_interaction_strength
from .NMF import apply_nmf_to_adata,nmf,apply_exrna_factors_to_cells
from .segmentation_free import segmentation_free_clustering
1 change: 1 addition & 0 deletions src/troutpy/tl/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def get_number_of_communication_genes(
target_proportion_threshold: float = 0.2
) -> pd.DataFrame:
"""Compute the number of exchanged genes between any two cell types
Args:
source_proportions (pd.DataFrame): A data frame (Gene name x Cell Type) with
proportion of cells per cell type expressing corresponding gene
Expand Down
1 change: 0 additions & 1 deletion src/troutpy/tl/quantify_xrna.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ def extracellular_enrichment(sdata, gene_id_column: str = 'feature_name', copy:

return sdata if copy else None


def spatial_colocalization(
sdata,
coords_keys=['x', 'y'],
Expand Down
1 change: 0 additions & 1 deletion src/troutpy/tl/segmentation_free.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pandas as pd



def segmentation_free_clustering(
sdata,
params: dict = {},
Expand Down
3 changes: 0 additions & 3 deletions src/troutpy/tl/target_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ def calculate_target_cells(
# Return a copy of the modified SpatialData object if requested
return sdata.copy() if copy else None




def define_target_by_celltype(sdata, layer='transcripts', closest_celltype_key='closest_target_cell_type', feature_key='feature_name'):
"""
Computes the proportion of features (e.g., transcripts) associated with each cell type in the spatial dataset.
Expand Down

0 comments on commit 08d8e9d

Please sign in to comment.