Skip to content

Commit

Permalink
Merge pull request #815 from drieslab/suite_dev
Browse files Browse the repository at this point in the history
v3.3.2
  • Loading branch information
jiajic authored Nov 29, 2023
2 parents cde56f8 + 6ec699e commit 17a4e54
Show file tree
Hide file tree
Showing 48 changed files with 4,033 additions and 361 deletions.
Binary file added .RData
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ merfish_preoptic/
.vscode/*
.Rprofile
inst/python/.ipynb_checkpoints/
docs
3 changes: 3 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ Suggests:
smfishHmrf,
SPARK,
SpatialExperiment,
spdep,
SummarizedExperiment,
tiff,
trendsceek,
Expand Down Expand Up @@ -143,6 +144,7 @@ Collate:
'interactivity.R'
'interoperability.R'
'poly_influence.R'
'python_bento.R'
'python_environment.R'
'python_hmrf.R'
'python_scrublet.R'
Expand All @@ -154,6 +156,7 @@ Collate:
'spatial_interaction_visuals.R'
'spatial_structures.R'
'spatial_visuals.R'
'spdep.R'
'utilities.R'
'utils-pipe.R'
'variable_genes.R'
Expand Down
16 changes: 13 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export(calculateOverlapParallel)
export(calculateOverlapPolygonImages)
export(calculateOverlapRaster)
export(calculateOverlapSerial)
export(calculateSpatCellMetadataProportions)
export(callSpdep)
export(cellProximityBarplot)
export(cellProximityEnrichment)
export(cellProximityEnrichmentEachSpot)
Expand Down Expand Up @@ -85,6 +87,7 @@ export(comparePolygonExpression)
export(convertEnsemblToGeneSymbol)
export(convertGiottoLargeImageToMG)
export(createArchRProj)
export(createBentoAdata)
export(createCellMetaObj)
export(createCrossSection)
export(createDimObj)
Expand Down Expand Up @@ -141,13 +144,15 @@ export(dimPlot2D)
export(dimPlot3D)
export(distGiottoImage)
export(doCellSegmentation)
export(doClusterProjection)
export(doFeatureSetEnrichment)
export(doGiottoClustree)
export(doHMRF)
export(doHMRF_V2)
export(doHclust)
export(doKmeans)
export(doLeidenCluster)
export(doLeidenClusterIgraph)
export(doLeidenSubCluster)
export(doLouvainCluster)
export(doLouvainSubCluster)
Expand Down Expand Up @@ -229,7 +234,8 @@ export(giottoMasterToSuite)
export(giottoPoints)
export(giottoPolygon)
export(giottoToAnnData)
export(giottoToSeurat)
export(giottoToSeuratV4)
export(giottoToSeuratV5)
export(giottoToSpatialExperiment)
export(heatmSpatialCorFeats)
export(heatmSpatialCorGenes)
Expand Down Expand Up @@ -332,11 +338,14 @@ export(runIntegratedUMAP)
export(runPAGEEnrich)
export(runPAGEEnrich_OLD)
export(runPCA)
export(runPCAprojection)
export(runPCAprojectionBatch)
export(runPatternSimulation)
export(runRankEnrich)
export(runSpatialDeconv)
export(runSpatialEnrich)
export(runUMAP)
export(runUMAPprojection)
export(runWNN)
export(runtSNE)
export(saveGiotto)
Expand Down Expand Up @@ -364,8 +373,8 @@ export(set_spatialGrid)
export(set_spatialNetwork)
export(set_spatial_enrichment)
export(set_spatial_locations)
export(seuratToGiotto)
export(seuratToGiotto_OLD)
export(seuratToGiottoV4)
export(seuratToGiottoV5)
export(showCellProportionSwitchedPie)
export(showCellProportionSwitchedSanKey)
export(showClusterDendrogram)
Expand Down Expand Up @@ -437,6 +446,7 @@ export(spatialAutoCorGlobal)
export(spatialAutoCorLocal)
export(spatialDE)
export(spatialExperimentToGiotto)
export(spdepAutoCorr)
export(specificCellCellcommunicationScores)
export(stitchFieldCoordinates)
export(stitchGiottoLargeImage)
Expand Down
27 changes: 22 additions & 5 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@

# Giotto Suite 3.3.2 (Release TBD)

## Breaking Changes

## Added
- Added `checkPythonPackage()` within `python_environment.R` to check for a python package within a provided environment, and install that package there if it is not found. Supports github url installation. Supports package version specification, but not version minima, maxima, or ranges (i.e., "pysodb==1.0.0" is supported, "pysodb>=1.0.0" is not)
- Added `py_install_prompt()` within `python_environment.R` to prompt a user to install a python package within a provided environment
- Added `install_github_link_pip()` within `python_environment.R` to use pip to install a python package from a github link within a provided environment after prompting the user.
- Added `install_py_pkg_reticulate()` within `python_environment.R` to install a specified python package within a provided environment via `reticulate::py_install()` after prompting the user.
- New file `python_bento.R`
- Added `createBentoAdata()` within `python_bento.R` to create a bento-flavor anndata object from a Giotto Object

## Changes
- Improved performance of gefToGiotto()
- Added `env_name` as an argument to `anndataToGiotto()` and `giottoToAnnData()` for compatability with `checkPythonPackage()`
- Deprecated internal function `check_py_for_scanpy()` in favor of new function `checkPythonPackage()`


# Giotto Suite 3.3.1 (2023-08-02)

Expand Down Expand Up @@ -28,10 +45,10 @@
## Changes
- Fix bug in `combine_matrices()`
- Fix bug in `createGiottoObject()` that will not allow object creation without supplied expression information
- Updated `polyStamp()` to replace an apply function with a crossjoin for better performance.
- Updated `spatInSituPlotPoints()` with `plot_last` parameter. Default output now plots polygons above points for better visibility.
- Updated `polyStamp()` to replace an apply function with a crossjoin for better performance
- Updated `spatInSituPlotPoints()` with `plot_last` parameter. Default output now plots polygons above points for better visibility
- Add check for spatLocsObj for spatlocs in polyStamp()
- Removed various print() and cat() statements throughout.
- Removed various print() and cat() statements throughout
- Changed default verbose argument to FALSE for createGiottoObject
- Changed default verbose argument to FALSE for joinGiottoObjects
- Changed default verbose argument to FALSE for createGiottoObjectSubcellular
Expand Down Expand Up @@ -154,7 +171,7 @@
- Fix `loadGiotto()` loss of over-allocation for data.tables-based objects after loading from disk


# Giotto Suite 3.1.0 (2202-12-01)
# Giotto Suite 3.1.0 (2022-12-01)


## Added
Expand Down Expand Up @@ -209,7 +226,7 @@



# Giotto Suite 2.1.0 (2202-11-09)
# Giotto Suite 2.1.0 (2022-11-09)

## Breaking Changes
- Update of python version to **3.10.2** [details](https://giottosuite.readthedocs.io/en/latest/additionalinformation.html#giotto-suite-2-1-0-2202-11-09)
Expand Down
140 changes: 140 additions & 0 deletions R/auxiliary_giotto.R
Original file line number Diff line number Diff line change
Expand Up @@ -4774,6 +4774,146 @@ calculateMetaTableCells = function(gobject,



#' @title calculateSpatCellMetadataProportions
#' @name calculateSpatCellMetadataProportions
#' @description calculates a proportion table for a cell metadata column (e.g. cluster labels)
#' for all the spatial neighbors of a source cell. In other words it calculates the
#' niche composition for a given annotation for each cell.
#' @param gobject giotto object
#' @param spat_unit spatial unit
#' @param feat_type feature type
#' @param spat_network spatial network
#' @param metadata_column metadata column to use
#' @param name descriptve name for the calculated proportions
#' @param metadata_cols annotation columns found in \code{pDataDT(gobject)}
#' @param return_gobject return giotto object
#' @return giotto object (default) or enrichment object if return_gobject = FALSE
#' @export
calculateSpatCellMetadataProportions = function(gobject,
spat_unit = NULL,
feat_type = NULL,
spat_network = NULL,
metadata_column = NULL,
name = 'proportion',
return_gobject = TRUE){


if(is.null(spat_network)) stop('spat_network = NULL, you need to provide an existing spatial network')
if(is.null(metadata_column)) stop('metadata_column = NULL, you need to provide an existing cell metadata column')

# Set feat_type and spat_unit
spat_unit = set_default_spat_unit(gobject = gobject,
spat_unit = spat_unit)
feat_type = set_default_feat_type(gobject = gobject,
spat_unit = spat_unit,
feat_type = feat_type)

# get spatial network to use
sp_network = get_spatialNetwork(gobject = gobject,
spat_unit = spat_unit,
name = spat_network,
output = 'networkDT')

# convert spatial network to a full spatial network
sp_network = convert_to_full_spatial_network(reduced_spatial_network_DT = sp_network)

# get cell metadata
cell_meta = get_cell_metadata(gobject = gobject,
spat_unit = spat_unit,
feat_type = feat_type,
output = 'data.table')

# merge spatial network and cell metadata
network_annot = data.table::merge.data.table(network, cell_meta[,c('cell_ID', metadata_column), with = FALSE], by.x = 'source', by.y = 'cell_ID')
setnames(network_annot, old = metadata_column, 'source_clus')
network_annot = data.table::merge.data.table(network_annot, cell_meta[,c('cell_ID', metadata_column), with = FALSE], by.x = 'target', by.y = 'cell_ID')
setnames(network_annot, old = metadata_column, 'target_clus')

# create self information: source cell is its own neighbor
source_annot_info = unique(network_annot[,.(source, source_clus)])
setnames(source_annot_info, 'source_clus', 'label')
source_annot_info[, target := source]
source_annot_info = source_annot_info[,.(source, target, label)]

# network information: source cells and other neighbors
target_annot_info = unique(network_annot[,.(source, target, target_clus)])
setnames(target_annot_info, 'target_clus', 'label')

# combine: provides most detailed information about neighbors
final_annot_info = rbindlist(list(source_annot_info, target_annot_info))



# calculate proportions of neighbors
tableres = final_annot_info[, names(table(label)), by = 'source']
setnames(tableres, 'V1', 'tablelabels')
propensities = final_annot_info[, prop.table(table(label)), by = 'source']
setnames(propensities, 'V1', 'proptable')


# data.table variables
label = NULL
propensities[, label := tableres$tablelabels]
propensities[, proptable := as.numeric(proptable)]
proportions_mat = dcast.data.table(propensities, formula = 'source~label', fill = 0, value.var = 'proptable')
data.table::setnames(x = proportions_mat, old = 'source', new = 'cell_ID')

# convert to matrix
# proportions_matrix = dt_to_matrix(proportions_mat)
# proportions_matrix[1:4, 1:10]

# create spatial enrichment object
enrObj = create_spat_enr_obj(name = name,
method = 'rank',
enrichDT = proportions_mat,
spat_unit = spat_unit,
feat_type = feat_type,
provenance = NULL,
misc = NULL)


## return object or results ##
if(return_gobject == TRUE) {

spenr_names = list_spatial_enrichments_names(gobject = gobject,
spat_unit = spat_unit,
feat_type = feat_type)


if(name %in% spenr_names) {
cat('\n ', name, ' has already been used, will be overwritten \n')
}

## update parameters used ##
parameters_list = gobject@parameters
number_of_rounds = length(parameters_list)
update_name = paste0(number_of_rounds,'_spatial_enrichment')


## update parameters used ##
gobject = update_giotto_params(gobject, description = '_enrichment')

### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###
gobject = set_spatial_enrichment(gobject = gobject,
spatenrichment = enrObj)
### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ###

return(gobject)

} else {

return(enrObj)

}



}





#' @title combineMetadata
#' @name combineMetadata
#' @description This function combines the cell metadata with spatial locations and
Expand Down
Loading

0 comments on commit 17a4e54

Please sign in to comment.