Skip to content

Commit

Permalink
correct5
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiomarco25 committed Jan 3, 2025
1 parent b166b11 commit 30891e8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 38 deletions.
3 changes: 2 additions & 1 deletion src/troutpy/tl/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ def get_gene_interaction_strength(


# Define the colormap and create color mappings for each cell type
cmap = plt.get_cmap("tab20")

# Plot the interaction strength using a chord diagram
#### work on this function ######
#cmap = plt.get_cmap("tab20")
#colors = [cmap(i) for i in range(interactions.shape[0])]
#chord_diagram(interactions, source_proportions.columns.tolist(), directed=True, fontsize=8, colors=colors)
plt.title(f"exotranscriptomic {gene_symbol} exchange", fontweight="bold")
Expand Down
2 changes: 1 addition & 1 deletion src/troutpy/tl/quantify_xrna.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def quantify_overexpression(
scores_per_gene.loc[:, "logfoldratio_over_noise"] = np.log(scores_per_gene.loc[:, "count"] / threshold)
try:
sdata['xrna_metadata']
except:
except KeyError:
create_xrna_metadata(sdata, points_layer = 'transcripts')

sdata['xrna_metadata'].var=sdata['xrna_metadata'].var.join(scores_per_gene)
Expand Down
7 changes: 4 additions & 3 deletions src/troutpy/tl/source_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import matplotlib.pyplot as plt
import numpy as np
from tqdm import tqdm
import scanpy as sc
import pandas as pd
import os
from sklearn.neighbors import KDTree
Expand All @@ -21,13 +22,13 @@ def create_xrna_metadata(
----------
- sdata : SpatialData
The SpatialData object to modify.
- points_layer : str, optional
The name of the layer in `sdata.points` from which to extract gene names.Default is 'transcripts'.
- gene_key : str, optional
The key in the `points_layer` dataframe that contains the gene names.Default is 'feature_name'.
- copy : bool, optional
- If `True`, returns a copy of the `SpatialData` object with the new table added.
- If `False`, modifies the original `SpatialData` object in place. Default is `False`.
Expand Down
55 changes: 22 additions & 33 deletions src/troutpy/tl/target_cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,35 @@ def calculate_target_cells(
gene_id_key:str='feature_name',
copy: bool = False
) -> Optional[sd.SpatialData]:
"""
Calculate the closest target cell for each transcript in a spatial omics dataset.
"""Calculate the closest target cell for each transcript in a spatial omics dataset.
This function identifies the nearest cell to each transcript based on spatial coordinates and
annotates the transcript data with the ID, cell type, and distance to the closest cell.
This function identifies the nearest cell to each transcript based on spatial coordinates and annotates the transcript data with the ID, cell type, and distance to the closest cell.
Parameters:
----------
sdata : sd.SpatialData
- sdata : sd.SpatialData
SpatialData object containing spatial and transcript data.
layer : str, optional
- layer : str, optional
The layer in `sdata.points` containing transcript data. Default is 'transcripts'.
xcoord : str, optional
- xcoord : str, optional
Column name for the x-coordinate of transcripts. Default is 'x'.
ycoord : str, optional
- ycoord : str, optional
Column name for the y-coordinate of transcripts. Default is 'y'.
xcellcoord : str, optional
- xcellcoord : str, optional
Column name for the x-coordinate of cell centroids. Default is 'x_centroid'.
ycellcoord : str, optional
- ycellcoord : str, optional
Column name for the y-coordinate of cell centroids. Default is 'y_centroid'.
celltype_key : str, optional
- celltype_key : str, optional
Column name in `adata.obs` that contains cell type annotations. Default is 'cell type'.
gene_id_key : str, optional
- gene_id_key : str, optional
Column name in `sdata.points[layer]` that contains gene identity. Default is 'feature_name'.
copy : bool, optional
- copy : bool, optional
If True, returns a copy of the modified SpatialData object. Default is False.
Returns:
-------
Optional[sd.SpatialData]
Modified SpatialData object with updated transcript annotations if `copy=True`.
Otherwise, updates are made in place, and None is returned.
- Optional[sd.SpatialData]
Modified SpatialData object with updated transcript annotations if `copy=True`.Otherwise, updates are made in place, and None is returned.
"""
# Copy AnnData object from the SpatialData table
adata = sdata['table'].copy()
Expand Down Expand Up @@ -108,33 +105,25 @@ def calculate_target_cells(
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.
"""Computes the proportion of features (e.g., transcripts) associated with each cell type in the spatial dataset.
This function calculates a cross-tabulation between features (e.g., extracellular transcripts) and cell types,
and then normalizes the result to provide the proportion of each feature associated with each cell type.
This function calculates a cross-tabulation between features (e.g., extracellular transcripts) and cell types,and then normalizes the result to provide the proportion of each feature associated with each cell type.
Parameters:
----------
sdata : dict-like spatial data object (with 'points' key)
A spatial data object that contains transcript and cell type information. The relevant data is accessed from the
`sdata.points[layer]` where:
- `layer`: Specifies the data layer (e.g., 'extracellular_transcripts') that contains the feature and cell type data.
layer : str, optional
-sdata : dict-like spatial data object (with 'points' key)
A spatial data object that contains transcript and cell type information. The relevant data is accessed from the `sdata.points[layer]`
- layer : str, optional
The key for the layer in `sdata.points` that contains the transcript data (default: 'extracellular_transcripts').
celltype_key : str, optional
- celltype_key : str, optional
The column name representing cell types in the transcript data (default: 'cell type').
feature_key : str, optional
- feature_key : str, optional
The column name representing the feature (e.g., transcript or gene) in the transcript data (default: 'feature_name').
Returns:
-------
pd.DataFrame
A pandas DataFrame where the rows represent features (e.g., transcripts), and the columns represent cell types.
Each entry in the DataFrame is the proportion of that feature associated with the respective cell type.
- pd.DataFrame
A pandas DataFrame where the rows represent features (e.g., transcripts), and the columns represent cell types. Each entry in the DataFrame is the proportion of that feature associated with the respective cell type.
Notes:
-----
Expand Down

0 comments on commit 30891e8

Please sign in to comment.