+# Copyright Saez Lab 2020
+if(!'OmnipathR' %in% installed.packages()[,"Package"]){
+ install_github('saezlab/OmnipathR')
+interactions <- as_tibble(
+ import_Omnipath_Interactions(),
+ import_LigrecExtra_Interactions(),
+ import_PathwayExtra_Interactions(),
+ import_KinaseExtra_Interactions()
+g <- interaction_graph(interactions = interactions)
+g <- simplify(g, remove.multiple = FALSE, remove.loops = TRUE)
+intercell <- as_tibble(import_Omnipath_intercell()) %>%
+ filter(!(class_type %in% c('sub', 'above_main')))
+intercell_classes <- intercell %>%
+ unlist(use.names = FALSE) %>%
+ 'growth_factor_binder',
+ 'chemokine_ligands_hgnc',
+ 'endogenous_ligands_hgnc',
+ 'extracellular_peptidase',
+ 'growth_factor_regulator',
+ 'interleukin_receptors_hgnc',
+intercell_proteins <- intercell %>%
+ summarize(uniprot = list(unique(uniprot)))
+intercell_proteins <- as.list(
+ intercell_proteins$uniprot,
+ intercell_proteins$category
+intercell_proteins$transmitter <-intercell %>%
+ filter(category %in% transmitters) %>%
+ unlist(use.names = FALSE) %>%
+intercell_proteins$receiver <-intercell %>%
+ filter(category %in% receivers) %>%
+ unlist(use.names = FALSE) %>%
+for(cls in names(intercell_proteins)){
+ function(x){x %in% intercell_proteins[[cls]]}
+trans_trans <- setNames(
+ V(g)[V(g)$transmitter],
+ vertex_attr(g, 'transmitter', n) &
+ !vertex_attr(g, 'receiver', n)
+ neighbors(g, v, mode= 'out')
+ which(V(g)$transmitter)
+ V(g)[V(g)$transmitter],
+ vertex_attr(g, 'receiver', n)
+ neighbors(g, v, mode= 'out')
+ which(V(g)$transmitter)
+elist <- as_edgelist(g, names = FALSE) %>%
+ `colnames<-`(c('source', 'target')) %>%
+ add_column(eid = 1:ecount(g)) %>%
+ nest(data = c('target', 'eid')) %>%
+ data = map(data, as.list),
+ data = map(data, function(x){with(x, setNames(eid, target))})
+ with(setNames(data, source))
+vpath_to_epath <- function(vpath){
+ vpath[1:(length(vpath) - 1)],
+ vpath[2:length(vpath)],
+ as.integer(get.edge.ids(g, c(vid0, vid1)))
+intercell_vpaths <- list()
+prg <- progress_estimated(length(which(V(g)$transmitter)))
+for(vid_tr in which(V(g)$transmitter)){
+ for(vid_rc in trans_rec[[sprintf('%d', vid_tr)]]){
+ intercell_vpaths[[i]] <- c(vid_tr, vid_rc)
+ for(vid_m in trans_trans[[sprintf('%d', vid_tr)]]){
+ for(vid_rc in trans_rec[[sprintf('%d', vid_m)]]){
+ intercell_vpaths[[i]] <- c(vid_tr, vid_m, vid_rc)
+prg <- progress_estimated(length(intercell_vpaths))
+intercell_epaths <- intercell_vpaths %>%
+paths_vattr <- function(idx, attr){
+ function(p){`if`(idx <= length(p), p[idx], NA)}
+paths_eattr <- function(idx, attr){
+ function(p){`if`(idx <= length(p), p[idx], NA)}
+ node0_uniprot = paths_vattr(1, 'up_ids'),
+ node0_genesymbol = paths_vattr(1, 'name'),
+ paths_vattr(1, 'classes'),
+ function(x){paste(x, collapse = ',')}
+ edge01_directed = paths_eattr(1, 'is_directed'),
+ edge01_stimulation = paths_eattr(1, 'is_stimulation'),
+ edge01_inhibition = paths_eattr(1, 'is_inhibition'),
+ edge01_nsources = paths_eattr(1, 'nsources'),
+ edge01_nrefs = paths_eattr(1, 'nrefs'),
+ node1_uniprot = paths_vattr(2, 'up_ids'),
+ node1_genesymbol = paths_vattr(2, 'name'),
+ paths_vattr(2, 'classes'),
+ function(x){paste(x, collapse = ',')}
+ edge12_directed = paths_eattr(2, 'is_directed'),
+ edge12_stimulation = paths_eattr(2, 'is_stimulation'),
+ edge12_inhibition = paths_eattr(2, 'is_inhibition'),
+ edge12_nsources = paths_eattr(2, 'nsources'),
+ edge12_nrefs = paths_eattr(2, 'nrefs'),
+ node2_uniprot = paths_vattr(3, 'up_ids'),
+ node2_genesymbol = paths_vattr(3, 'name'),
+ paths_vattr(3, 'classes'),
+ function(x){paste(x, collapse = ',')}
+write_tsv(result, 'omnipath_intercell_paths__20200314.tsv')