Defines functions fisher

#'Fisher's Exact Test (Single Cell Type & pSI Threshold)

fisher<-function(pSI, candidate.genes, thresh, cell, total){
  #creating index of genes and column binding it onto the existing pSI data frame
  #compensating for cell/sample column number because of the column bind just performed
  cell <- cell+1
  #this identifies, for a given cell type (column) from the pSI table, the genes which have pSI values less than a certain threshold
  hits <- pSI[which(pSI[,cell]<thresh),1]
  #as long as there is one hit, calculate number of overlapping genes below 
  if(!is.na(hits[1])){ # 7_26_13 
    #hits is the list of row number for an gene with pSI<thresh. It runs through all these hits...
    for (i in 1:length(hits)){   
      #and asks if they are listed as a hit on your gene list, and makes a list of the overlap called outy.
      if (candidate.genes[candidate.genes[,1]==k, 2]  >0){
        if (exists("outy")){
          outy<-rbind(outy, candidate.genes[  candidate.genes[,1]==k, ]  )
        } else {                 
          outy     <- candidate.genes[  candidate.genes[,1]==k, ]
      #number overlapping is equal to this list
  } else {
  #number of human candidate genes not overlapping
  b<-sum(candidate.genes[,2]>0) - a    
  #number of cell type spec genes not overlapping
  c<-length(hits) -a  
  #number of other genes.
  d<-total -a -b -c
  #format expected by fisher.test function.
  #this is the p-value, which is all you get otherwise. 
  fisher.test(counts, alternative="greater")[1]

Try the pSI package in your browser

Any scripts or data that you put into this service are public.

pSI documentation built on May 1, 2019, 10:28 p.m.