Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update utils.R #52

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ Imports:
dplyr,
cowplot,
reshape2
RoxygenNote: 6.1.1
RoxygenNote: 7.2.3
5 changes: 1 addition & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Generated by roxygen2: do not edit by hand

export()
export(GEP_makeMean)
export(addRandToSampTab)
export(addToST)
Expand All @@ -26,12 +25,12 @@ export(findAvgLabel)
export(findBestPairs)
export(findClassyGenes)
export(findVarGenes)
export(get_cate)
export(getGenesFromGO)
export(getSpecGenes)
export(getTopGenes)
export(getTopGenesList)
export(getUniqueGenes)
export(get_cate)
export(gnrAll)
export(gnrBP)
export(harmonize)
Expand Down Expand Up @@ -109,7 +108,5 @@ export(utils_strip_fname)
export(utils_stripwhite)
export(weighted_down)
import(parallel)
import(umap)
import(viridis)
importFrom(RColorBrewer,brewer.pal)
importFrom(randomForest,randomForest)
68 changes: 34 additions & 34 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ctRename<-function(sampTab, annCol, oldName, newName){
xnot<-which(colnames(sampTab)!=annCol)
ans<-sampTab[,xnot]
cbind(ans, newAnn=newann)
}
}

#' @title
#' Split Sample Table
Expand All @@ -41,13 +41,13 @@ ctRename<-function(sampTab, annCol, oldName, newName){
#'
#' @export
splitCommon<-function(sampTab, ncells = 50, dLevel="cell_ontology_class", cells_reserved = 3){

cts<-unique(as.vector(sampTab[,dLevel]))

if(sum(is.na(cts)) > 0){
stop("There are NAs in your training labels, please remove them first!")
}

trainingids<-vector()
for(ct in cts){
cat(ct,": ")
Expand Down Expand Up @@ -102,7 +102,7 @@ loadLoomExpCluster<-function# load a loom object containing expression + cluste
expMat<- t(lfile[["matrix"]][1:length(cellNames),])
rownames(expMat)<-geneNames
colnames(expMat)<-cellNames

cluster_old <- lfile[['col_attrs']][[xname]][]

sampTab <- data.frame(cell_name=cellNames, cluster=cluster_old)
Expand All @@ -117,7 +117,7 @@ loadLoomExpCluster<-function# load a loom object containing expression + cluste
#' @export
getGenesFromGO<-function# return the entrez gene ids of a given a GOID, for now assumes mouse
(GOID, # GO id to find genes for
annList
annList
){
sort(as.vector(unlist(annList[['egSymbols']][annList[['goegs']][[GOID]]])));
}
Expand Down Expand Up @@ -149,15 +149,15 @@ GEP_makeMean<-function
groupings,
type='mean'
){


ans<-data.frame();
grps<-unique(groupings);
if(type=='mean'){
for(grp in grps){
gi<-which(groupings==grp);
if(length(gi)==1){

if(nrow(ans)==0){
ans<-data.frame(exp[,gi]);
}else{
Expand Down Expand Up @@ -187,7 +187,7 @@ GEP_makeMean<-function
}
}
}

colnames(ans)<-grps;
ans;
### data.frame of mean or median-ed data based on given groupings
Expand Down Expand Up @@ -215,8 +215,8 @@ library(GO.db)
#'
#' 1-PCC distance
#' @param x numeric matrix
#'
#' @return distance matrix
#'
#' @return distance matrix
#'
#' @examples
#' xdist<-utils_myDist(t(expDat))
Expand Down Expand Up @@ -254,7 +254,7 @@ utils_loadObject<-function
#'
#' @export
utils_stripwhite<-function
###
###
(string
#### string
){
Expand All @@ -268,7 +268,7 @@ utils_stripwhite<-function
#'
#' @export
utils_myDate<-function
###
###
()
{
format(Sys.time(), "%b_%d_%Y");
Expand Down Expand Up @@ -299,11 +299,11 @@ zscore<-function
### compute zscore
(x,
### numeric vector
meanVal,
### mean of distribution to compute zscore of x against
meanVal,
### mean of distribution to compute zscore of x against
sdVal
### standard deviation of distribution to compute zscore of x agains
){
){
(x-meanVal)/sdVal;
### zscore
}
Expand Down Expand Up @@ -363,7 +363,7 @@ cn_correctZmat<-function
downSampleW<-function
(vector,
total=1e5,
dThresh=0){
dThresh=0){

totalSignal<-sum(vector)
wAve<-vector/totalSignal
Expand Down Expand Up @@ -403,7 +403,7 @@ weighted_down<-function
tmpAns <- expDat - t(props * rrids)
tmpAns[which(tmpAns<dThresh)] <- 0
}

tmpAns
}

Expand Down Expand Up @@ -461,15 +461,15 @@ trans_binarize<-function
#' @return list
#' @export
extractSeurat <- function(seurat_object, exp_slot_name = "counts"){

#extract metadata
sampTab = [email protected]

#extract expression matrix
expDat = as.matrix(GetAssayData(seurat_object, slot = exp_slot_name))
expDat = as.matrix(GetAssayData(seurat_object, slot = exp_slot_name))

return(list(sampTab = sampTab, expDat = expDat))

}

#' extract sampTab and expDat sce object into regular S3 objects
Expand All @@ -479,24 +479,24 @@ extractSeurat <- function(seurat_object, exp_slot_name = "counts"){
#' @export
extractSCE <- function(sce_object, exp_slot_name = "counts"){
#extract metadata
sampTab = as.data.frame(colData(sce_object, internal = TRUE))
sampTab = as.data.frame(colData(sce_object))
sampTab$sample_name = rownames(sampTab)

#extract expression matrix
if(exp_type == "counts"){
if(exp_slot_name == "counts"){
expDat = counts(sce_object)
}
if(exp_type == "normcounts"){

if(exp_slot_name == "normcounts"){
expDat = normcounts(sce_object)
}
if(exp_type == "logcounts"){

if(exp_slot_name == "logcounts"){
expDat = logcounts(sce_object)
}

return(list(sampTab = sampTab, expDat = expDat))

}

#' @export
Expand Down Expand Up @@ -590,7 +590,7 @@ load10x<-function

# sample_name == prefix + inc
# sample_id == prefix + inc + barcode

# barcode == barcode
# colnames of expDat == sample_name
# rownames(sampTab) = sample_name
Expand Down Expand Up @@ -657,7 +657,7 @@ mergeLoad10x<-function
##stp<-nCells
cat(pNames[1],"\n")
cat("named:",ncol(expList[[pNames[1]]][['expDat']]),"\n")
cat("numbered:",ncol(expList[[1]]),"\n")
cat("numbered:",ncol(expList[[1]]),"\n")
stp<-ncol(expList[[pNames[1]]][['expDat']])
# for(pName in pNames){
for(i in seq(length(pNames))){
Expand Down
12 changes: 10 additions & 2 deletions man/cn_barplot_grnSing_base.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions man/cn_clPerf.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions man/cn_classAssess.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions man/cn_computeAUCPR.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions man/cn_eval.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions man/compareGenePairs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions man/csRenameOrth.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions man/findClassyGenes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/hm_enr.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading