R/obtainsamples.R

Defines functions obtainsamples

Documented in obtainsamples

#' Draw TIC map
#'
#' Based on the arguments measures samplestodraw_TIC=NA, samplestodraw_altTIC=NA, samplestodraw_LOGTIC=NA,samplestodraw_LOGaltTIC=NA, this function returns the proper columns of the totalsamples
#'
#' @param allsamples all the samples from where to choose the columns asked by the user
#' @param samplestodraw_TIC list of samples whose TIC needs to be drawed. The samples should be referred by their file position on a alphabetical ordered file list. Moreover, it can be drawed the result of adding or substracting a combination of samples; that operation should be indicated with a vector of samples, indicating with a minus the sample that should be substracted. e.g. samplestodraw_TIC=list(1,2,c(1,-3)) draws the TIC of the 1st and second sample, as well as the result of substract the 3rd's TIC sample from the 1st
#' @param samplestodraw_altTIC analogously to the previous argument, list of samples whose "altered" TIC  needs to be drawed. "Altered" TIC is refered to a TIC without specific masses (see precook_measures() function). See the samplestodraw_TIC argument for further details.
#' @param samplestodraw_LOGTIC list of samples whose log(TIC)  needs to be drawed. e.g. samplestodraw_LOGTIC=list(c(1,-3),2) draws two plots, log(TIC(sample3)-log(TIC(sample1) and log(TIC(sample2).
#' @param samplestodraw_LOGaltTIC analogously to the previous argument, list of samples whose TIC  needs to be drawed logarithmically. The only diference is the TIC ploted is the altered one, a TIC without specific masses (see precook_measures() function).
#' @return matrix whose columns have been asked from the allsamples
#' @examples
#'obtainsamples(allsamples=matrix(1:10,nrow=2),samplestodraw_TIC=list(1,2,c(1,-3)))

obtainsamples<-function(allsamples,
                      samplestodraw_TIC=NA, samplestodraw_altTIC=NA,
                      samplestodraw_LOGTIC=NA,samplestodraw_LOGaltTIC=NA)
    {

    draws2rep<-list(samplestodraw_TIC,samplestodraw_altTIC,samplestodraw_LOGTIC,samplestodraw_LOGaltTIC)
    draws2rep_position<-c(2,1,2,1)#by inner convention TIC columns are odd, altTIC are even
    draws2rep_log<-c(F,F,T,T)#which samples should I apply log()

    #the matrix which will keep the results
    matriuresultant<-matrix(,nrow=nrow(allsamples), ncol = 0)

    #we operate for every "samplestodraw_TIC" not NA
    for(i in 1:length(draws2rep)){
        if(!anyNA(draws2rep[[i]])){
            #Agafem les mesures TIC (alterades o no, amb log() o no)
            implied_mesures<- allsamples[,seq(draws2rep_position[i], ncol(allsamples), by=2),drop=F]

            resultat<-operate_columns(operacions=draws2rep[[i]], columnes=implied_mesures,
                                      applylog=draws2rep_log[i])
            matriuresultant<-cbind(matriuresultant,resultat)
        }
    }

return(matriuresultant)

}
jmbadia/GcxGctools documentation built on May 11, 2018, 7:47 p.m.