Skip to content

Commit

Permalink
fix network bug
Browse files Browse the repository at this point in the history
  • Loading branch information
RubD committed Mar 13, 2020
1 parent 9bb8f37 commit 1b288b7
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions R/spatial_interaction.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,23 @@ annotateSpatialNetwork = function(gobject,
}
spatial_network = gobject@spatial_network[[spatial_network_name]]


if(create_full_network == TRUE) {

spatial_network = Giotto:::convert_to_full_spatial_network(spatial_network)
setnames(spatial_network,
old = c('source', 'target', 'source_begin', 'source_end', 'target_begin', 'target_end'),
new = c('from', 'to', 'sdimx_begin', 'sdimy_begin', 'sdimx_end', 'sdimy_end'))

# convert to names for a reduced network
source_coordinates = grep('source_', colnames(spatial_network), value = T)
new_source_coordinates = gsub(x = source_coordinates, pattern = 'source_', replacement = 'sdim')
new_source_coordinates = paste0(new_source_coordinates,'_begin')

target_coordinates = grep('target_', colnames(spatial_network), value = T)
new_target_coordinates = gsub(x = target_coordinates, pattern = 'target_', replacement = 'sdim')
new_target_coordinates = paste0(new_target_coordinates,'_end')

data.table::setnames(spatial_network,
old = c('source', 'target', source_coordinates, target_coordinates),
new = c('from', 'to', new_source_coordinates, new_target_coordinates))
}


Expand All @@ -42,7 +54,6 @@ annotateSpatialNetwork = function(gobject,
cluster_type_vector = cell_metadata[[cluster_column]]
names(cluster_type_vector) = cell_metadata[['cell_ID']]


spatial_network_annot = data.table::copy(spatial_network)
spatial_network_annot[, to_cell_type := cluster_type_vector[to]]
spatial_network_annot[, from_cell_type := cluster_type_vector[from]]
Expand All @@ -56,8 +67,6 @@ annotateSpatialNetwork = function(gobject,
column1 = 'from_cell_type', column2 = 'to_cell_type',
myname = 'unified_int')

#spatial_network_annot[, unified_int := paste(sort(c(from_cell_type, to_cell_type)), collapse = '--'), by = 1:nrow(spatial_network_annot)]

return(spatial_network_annot)

}
Expand Down

0 comments on commit 1b288b7

Please sign in to comment.