Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .Rbuildignore

This file was deleted.

3 changes: 0 additions & 3 deletions .gitignore

This file was deleted.

8 changes: 7 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ Authors@R: person("Sahil", "Shah", email = "[email protected]", role
Description: What the package does (one paragraph).
Depends:
R (>= 3.2.1)
Imports:
graphics,
igraph,
KEGGgraph,
limma,
pcaPP
License: What license is it under?
LazyData: true
RoxygenNote: 5.0.0
RoxygenNote: 6.0.1
14 changes: 14 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,2 +1,16 @@
# Generated by roxygen2: do not edit by hand

export(calcAllPairsDistances)
export(calcCorMatrix)
export(calcGeneTStats)
export(geneNIDG)
export(plotRadiusVS)
importFrom(graphics,abline)
importFrom(graphics,mtext)
importFrom(graphics,par)
importFrom(graphics,plot)
importFrom(igraph,V)
importFrom(igraph,shortest.paths)
importFrom(limma,lmFit)
importFrom(limma,treat)
importFrom(pcaPP,cor.fk)
71 changes: 36 additions & 35 deletions R/Observed.DecayDE.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,42 @@
#' differential expression of other genes j in the neighborhood is inversely
#' related to the distance d(i,j) of gene j from gene i
#'
#' @param distance.matrix A matrix of the distances on the global network
#' @param gene.id The name of the gene to which GeneSurrounder is applied
#' @param genes.assayedETnetwork The names of the genes that are assayed and on the network
#' @param distance_matrix A matrix of the distances on the global network
#' @param gene_id The name of the gene to which GeneSurrounder is applied
#' @param genes_assayedETnetwork The names of the genes that are assayed and on the network
#' @param diameter The diameter of the global network
#' @param geneStats.observed A vector of the observed differential expression
#' @param geneStats_observed A vector of the observed differential expression
#' @importFrom pcaPP cor.fk
#'

Observed.DecayDE <- function(distance.matrix,
gene.id,
genes.assayedETnetwork,
diameter,
geneStats.observed){



distances <- distance.matrix[gene.id,
genes.assayedETnetwork]


observed.tau_b <- vapply(1:diameter,function(RADIUS){


# Excludes gene j with distances > 0
igenes.distances <- distances[distances <= RADIUS
& distances > 0]
igenes.names <- names(igenes.distances)


return(

cor.fk(abs(geneStats.observed[igenes.names]), igenes.distances)

)

},
numeric(1))

Observed.DecayDE <- function(distance_matrix, gene_id, genes_assayedETnetwork,
diameter, geneStats_observed) {
if (class(genes_assayedETnetwork) %in% c("character", "factor")) {
if (!all(genes_assayedETnetwork %in% colnames(distance_matrix))) {
bad_genes <- genes_assayedETnetwork[!(genes_assayedETnetwork %in% colnames(distance_matrix))]
bad_genes_msg <- paste(bad_genes, collapse = ", ")
bad_genes_num <- length(bad_genes)
stop(paste("There are ", bad_genes_num, " genes that are not in 'distance_matrix'.",
"Here is a list of those genes not included:", bad_genes_msg, sep = "\n"))
}
} else if (class(genes_assayedETnetwork) %in% c("numeric", "integer")) {
genes_assayedETnetwork <- as.integer(genes_assayedETnetwork)
if (any(genes_assayedETnetwork <= 0 | genes_assayedETnwork > ncol(distance_matrix))) {
stop("At least one of the supplied column numbers was less than zero or greater than ",
"the total number of columns in 'distance_matrix'.")
}
}

if (gene_id %in% rownames(distance_matrix)) {
stop("The supplied 'gene_id', '", gene_id, "', is not found in 'distance_matrix'.")
}

distances <- distance_matrix[gene_id, genes_assayedETnetwork]

observed_tau_b <- vapply(1:diameter, function(RADIUS) {
# Excludes gene j with distances > 0
igenes_distances <- distances[distances <= RADIUS & distances > 0]
igenes_names <- names(igenes_distances)
tau_b <- abs(geneStats_observed[igenes_names])
pcaPP::cor.fk(tau_b, igenes_distances)
}, numeric(1))
}
44 changes: 11 additions & 33 deletions R/Observed.SI.R
Original file line number Diff line number Diff line change
@@ -1,42 +1,20 @@



#' Sphere of Influence Step
#'
#' Sphere of Influence assesses if a
#' candidate gene i meets the first criterion by testing if gene i
#' is more strongly correlated with its network neighbors than with a
#' random set of genes
#'
#' @param gene.id The name of the gene to which GeneSurrounder is applied
#' @param distance.matrix A matrix of the distances on the global network
#' @param cor.matrix A matrix of correlations between the expression of the genes
#' @param gene_id The name of the gene to which GeneSurrounder is applied
#' @param distance_matrix A matrix of the distances on the global network
#' @param cor_matrix A matrix of correlations between the expression of the genes
#' @param diameter The diameter of the global network
#' @param genes.assayedETnetwork The names of the genes that are assayed and on the network
#' @param genes_assayedETnetwork The names of the genes that are assayed and on the network
#'



Observed.SI <- function(gene.id,
distance.matrix,
cor.matrix,
diameter,
genes.assayedETnetwork){




# Vector of cor between j and all other genes on network (excluding j)
cor.with.j <- cor.matrix[gene.id,
setdiff(genes.assayedETnetwork,gene.id)]

distances.to.j <- distance.matrix[gene.id,
setdiff(genes.assayedETnetwork,gene.id)]


observed.cor <- SumAbsCor(cor.with.j,
diameter,
distances.to.j)


}
Observed.SI <- function(gene_id, distance_matrix, cor_matrix,
diameter, genes_assayedETnetwork){
# Vector of cor between j and all other genes on network (excluding j)
cor_with_j <- cor_matrix[gene_id, setdiff(genes_assayedETnetwork, gene_id)]
distances_to_j <- distance_matrix[gene_id, setdiff(genes_assayedETnetwork, gene_id)]
observed_cor <- SumAbsCor(cor_with_j, diameter, distances_to_j)
}
123 changes: 44 additions & 79 deletions R/Resample.DecayDE.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,94 +5,59 @@
# author: Sahil Shah <[email protected]>
# ==========================================================================



#' Decay of Differential Expression step
#'
#' Decay of Differential Expression tests whether the magnitude of
#' differential expression of other genes j in the neighborhood is inversely
#' related to the distance d(i,j) of gene j from gene i
#'
#' @param distance.matrix A matrix of the distances on the global network
#' @param gene.id The name of the gene to which GeneSurrounder is applied
#' @param genes.assayedETnetwork The names of the genes that are assayed and on the network
#' @param distance_matrix A matrix of the distances on the global network
#' @param gene_id The name of the gene to which GeneSurrounder is applied
#' @param genes_assayedETnetwork The names of the genes that are assayed and on the network
#' @param diameter The diameter of the global network
#' @param perm.geneStats.matrix A matrix of the resampled differential expression
#' @param perm_geneStats_matrix A matrix of the resampled differential expression
#' @param sizes The number of genes assayed and on the network in each neighborhood
#' @importFrom pcaPP cor.fk
#'


Resample.DecayDE <- function(distance.matrix,
gene.id,
genes.assayedETnetwork,
diameter,
perm.geneStats.matrix,
sizes){


distances <- distance.matrix[gene.id,
genes.assayedETnetwork]





num.genes <- length(genes.assayedETnetwork) - 1
geneid.d <- which(sizes == num.genes)[1]


# null.tau b matrix of 1000 row 34 columns b/c stacks columns
null.tau_b <- vapply(1:geneid.d,function(RADIUS){


# Excludes gene j with distances > 0
igenes.distances <- distances[distances <= RADIUS
& distances > 0]
igenes.names <- names(igenes.distances)





null <- vapply(1:nrow(perm.geneStats.matrix),function(resample.index){

return ( cor.fk( abs(perm.geneStats.matrix[resample.index,igenes.names]) ,
igenes.distances)

)

},
numeric(1))

# X <- cbind(igenes.distances,
# t( abs(geneStats$resampled[,igenes.names]) )
# )

# Y <- cor.fk(X)


},
numeric(1000)) # numeric is length of one of the columns vapply stacks

# 2:genid.d means number of rows in null.tau_b is not geneid.d

null.tau_b <- cbind(null.tau_b,
matrix(
rep(null.tau_b[, geneid.d],diameter - geneid.d),
nrow = 1000)

)



# cf. ?vapply
# If FUN.VALUE is not an array, the result is a matrix with
# length(FUN.VALUE) rows and length(X) columns,

# return matrix distance by resample number a la Resample.SI
return(t(null.tau_b))


Resample.DecayDE <- function(distance_matrix, gene_id, genes_assayedETnetwork,
diameter, perm_geneStats_matrix, sizes) {

numResamples <- nrow(perm_geneStats_matrix)
distances <- distance_matrix[gene_id, genes_assayedETnetwork]

num_genes <- length(genes_assayedETnetwork) - 1
geneid_d <- which(sizes == num_genes)[1]

# null_tau b matrix of numResamples (default 1000) rows and
# length(distance_matrix) columns b/c stacks columns
null_tau_b <- vapply(1:geneid_d, function(RADIUS) {
# Excludes gene j with distances > 0
igenes_distances <- distances[distances <= RADIUS & distances > 0]
igenes_names <- names(igenes_distances)

null <- vapply(1:numResamples, function(resample_index) {
tau_b <- abs(perm_geneStats_matrix[resample_index, igenes_names])
pcaPP::cor.fk(tau_b, igenes_distances)
}, numeric(1))

# X <- cbind(igenes_distances,
# t( abs(geneStats$resampled[,igenes_names]) )
# )

# Y <- cor.fk(X)
}, numeric(numResamples)) # numeric is length of one of the columns vapply stacks

# 2:genid_d means number of rows in null_tau_b is not geneid_d
null_tau_b <- cbind(null_tau_b, matrix(
rep(null_tau_b[, geneid_d], diameter - geneid_d),
nrow = numResamples)
)

# cf. ?vapply
# If FUN.VALUE is not an array, the result is a matrix with
# length(FUN.VALUE) rows and length(X) columns,
# return matrix distance by resample number a la Resample.SI
return(t(null_tau_b))
}


Expand Down
Loading