R basic

In this post, I will document all basic for R and R programming.

Scenario 1, useful R introduction manuals and websites

	
  • CRAN
  • Thomas Girke -- USC
  • Scenario 2, differentiating matrix and dataframe

    A matrix is a two-dimensional data structure. All the elements of a matrix must be of the same type (numeric, logical, character, complex).
    A data frame combines features of matrices and lists. In fact we can think of a data frame as a rectangular list, that is, a list in which all items have the length length. The items of the list serve as the columns of the data frame, so every item within a particular column has to be of the samne type. However, different columns can be of different types. 
    Matrix -- Dataframe
    

    Scenario 3, how to combine two matrix by rownames

    It seems easy and legitimate question, but not everyone knows it. I found one pretty decent solution

    
    cbind.fill <- function(x, y){
      xrn <- rownames(x)
      yrn <- rownames(y)
      rn <- union(xrn, yrn)
      xcn <- colnames(x)
      ycn <- colnames(y)
      if(is.null(xrn) | is.null(yrn) | is.null(xcn) | is.null(ycn)) 
        stop("NULL rownames or colnames")
      z <- matrix(NA, nrow=length(rn), ncol=length(xcn)+length(ycn))
      rownames(z) <- rn
      colnames(z) <- c(xcn, ycn)
      idx <- match(rn, xrn)
      z[!is.na(idx), 1:length(xcn)] <- x[na.omit(idx),]
      idy <- match(rn, yrn)
      z[!is.na(idy), length(xcn)+(1:length(ycn))] <- y[na.omit(idy),]
      return(z)
    }
    
    

    Scenario 4, I want to have a thorough note on apply function in R

    There was a simple question on R apply function. Although it seems quite straightforward, it causes lots of confusion for people. Therefore, I decide to write a thorough document for this.


    Scenario 5, Invoking R from the command line

    Here gives a good example to invoke R from the linux command line.

    Scenario 6, Use R to perform clustering and then produce a heatmap

    Good example-by-mannheimia
    Example of savvi by Earl Glynn
    

    Installing MikTex on windows 7 64bit machine

    All the help docs deserve the credits:

    First post I encountered
    Detail installation instructions
    

    Working on the site visit report reminds me about the MikTex tools I had a year ago. And, I am learning it through this process. First of all, there are urls that help me and I would like to acknowledge their effort.

    HowToTex is very helpful, but I could not install/use the packages.
    This one looks pretty professional.
    Math course at Kansas State University is primarily for creating magic math formula.
    I started with this dummy skeleton, at least is a working example for dummy.
    A self-study manual.
    Another LaTex online book here.
    

    Using mongoDB for LINCS1000

    L1000CDS use MongoDB schema to store all the information.

    Installation

    1. Install MongoDB. Please select release 2.4.14 for download. The 
    MongoDB files on this page are not compatible with newer versions 
    of MongoDB
    
    2. Download the LINCS_L1000_CD.tar.gz file and unzip.
    
    3. Place all the LINCS_L1000_CD.x files in the unzipped folder 
    into the MongoDB database folder.
    
    4. Start mongod.
    
    5. Open a mongo shell and switch to LINCS_L1000_CD db. The LINCScloud 
    collection in the db stores all the processed LINCS L1000 data 
    download from LINCS cloud. The GSE70138 collection contains all 
    the processed LINCS L1000 data downlaoded from GEO. 
    The two collections do not overlap.
    
    6. Optionally it is suggested to download and install Robomongo 
    which provides a nice GUI to browse the data.
    
    6. Refer to the MongoDB documentation for query specifications 
    and drivers for different languages.
    

    Import and export between MongoDB and .json files

    mongoimport
    mongoexport
    will help to dump json file in and out from a mongodb
    import-export
    

    For Jacqui, temporarily stored here

    epigquickstart_508

    I have mongodb installed on my Windows10 desktop and Linux CentOS7. To installed L1000CDS on my linux and windows desktop:

    Download two files from the download page
    On linux: copy two files to /tmp/mongo/

    cpcd-gse70138.metadata.json

    and

    cpcd-gse70138.bson

    mongorestore -d databasename /tmp/mongo/ mongorestore -d databasename -c collectionname /path/to/both_json_and_bson_files In my case, I tested both ways and they all worked:

    mongorestore -d LINCS_L1000_CD -c cpc2014 /path/to/cpcd-gse70138.bson

    mongorestore -d LINCS_L1000_CD /home/li11/LINCS-L1000/

    Although both ways work, however, the second method (without collection name)

    produced a collection called “cpcd-gse70138”. This makes query very cumbersome as

    I have to deal withlittle dash. Therefore, it is with more control to do

    mongorestore -d LINCS_L1000_CD -c cpc2014 /home/li11/LINCS-L1000/cpcd-gse70138.bson