Mercurial > repos > melpetera > tablemerge
comparison tablemerge_script.R @ 0:19e19f40dc7a draft
Test the tool dependencies managing.
| author | melpetera |
|---|---|
| date | Tue, 26 Jul 2016 08:28:03 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:19e19f40dc7a |
|---|---|
| 1 ################################################################################################ | |
| 2 # TABLE MERGE # | |
| 3 # # | |
| 4 # User: Galaxy # | |
| 5 # Starting date: 16-04-2015 # | |
| 6 # V-0.1: First version of merge code # | |
| 7 # V-0.2: Addition of data check and handling of special characters # | |
| 8 # # | |
| 9 # # | |
| 10 # Input files: dataMatrix ; Metadata file # | |
| 11 # Output files: dataMatrix ; Metadata file # | |
| 12 # # | |
| 13 # Dependencies: RcheckLibrary.R ; miniTools.R # | |
| 14 # # | |
| 15 ################################################################################################ | |
| 16 | |
| 17 # Parameters (for dev) | |
| 18 if(FALSE){ | |
| 19 DM.name <- "dataMatrix_CleanIons_CleanEch.txt" | |
| 20 meta.name <- "sampleMetadata_CleanEch.txt" | |
| 21 metype <- "sample" | |
| 22 output <- "Combined_${Metadata_in.name}" | |
| 23 } | |
| 24 | |
| 25 | |
| 26 | |
| 27 tab.merge <- function(DM.name,meta.name,metype,output){ | |
| 28 # This function allows to merge the dataMatrix with one metadata table. | |
| 29 # | |
| 30 # Parameters: | |
| 31 # - DM.name, meta.name: dataMatrix and metadata files' access respectively | |
| 32 # - metype: "sample" or "variable" depending on metadata content | |
| 33 # - output: output file's access | |
| 34 | |
| 35 | |
| 36 # Input -------------------------------------------------------------- | |
| 37 | |
| 38 DM <- read.table(DM.name,header=TRUE,sep="\t",check.names=FALSE) | |
| 39 meta <- read.table(meta.name,header=TRUE,sep="\t",check.names=FALSE) | |
| 40 | |
| 41 # Table match check | |
| 42 table.check <- match2(DM,meta,metype) | |
| 43 check.err(table.check) | |
| 44 | |
| 45 # StockID | |
| 46 meta.id <- stockID(DM,meta,metype) | |
| 47 DM<-meta.id$dataMatrix ; meta<-meta.id$Metadata ; meta.id<-meta.id$id.match | |
| 48 | |
| 49 | |
| 50 # Merging tables ----------------------------------------------------- | |
| 51 | |
| 52 if(metype=="sample"){ | |
| 53 ori.DM <- DM | |
| 54 rownames(DM) <- DM[,1] | |
| 55 DM <- DM[,-1] | |
| 56 DM <- t(DM) | |
| 57 DM <- data.frame(sample=row.names(DM),DM) | |
| 58 rownames(DM) <- NULL | |
| 59 } | |
| 60 | |
| 61 comb.data <- merge(x=meta,y=DM,by.x=1,by.y=1) | |
| 62 | |
| 63 | |
| 64 # Output ------------------------------------------------------------- | |
| 65 | |
| 66 # Getting back original identifiers | |
| 67 if(metype=="sample"){ | |
| 68 id.ori <- reproduceID(ori.DM,comb.data,metype,meta.id) | |
| 69 }else{ | |
| 70 id.ori <- reproduceID(DM,comb.data,metype,meta.id) | |
| 71 } | |
| 72 comb.data <- id.ori$Metadata | |
| 73 | |
| 74 # Writing the table | |
| 75 write.table(comb.data,output,sep="\t",quote=FALSE,row.names=FALSE) | |
| 76 | |
| 77 | |
| 78 } # End of tab.merge | |
| 79 | |
| 80 | |
| 81 # Typical function call | |
| 82 # tab.merge(DM.name,meta.name,metype,output) |
