Commit bb19c1c3639bfca2de290ce11096b8cad98d05eb
1 parent
b0ad80bb4c
Exists in
master
UPDATE!!!! Changed from i+1 < to i+1<=
by = "ID_REF" Will make a difference in any analysis that used this code
Showing
1 changed file
with
3 additions
and
3 deletions
 
Show diff stats
RMatchGenes.R
| 1 | #Checking for similar genes in both data sets | 1 | #Checking for similar genes in both data sets | 
| 2 | 2 | ||
| 3 | #Required libraries | 3 | #Required libraries | 
| 4 | library(MASS) | 4 | library(MASS) | 
| 5 | library(readr) | 5 | library(readr) | 
| 6 | library(dplyr) | 6 | library(dplyr) | 
| 7 | 7 | ||
| 8 | Check2Match <- function(){ | 8 | Check2Match <- function(){ | 
| 9 | ANDIS <- select.list(choices = list.files(),multiple = TRUE, title = "Choose the file/files you want to analyze:") | 9 | ANDIS <- select.list(choices = list.files(),multiple = TRUE, title = "Choose the file/files you want to analyze:") | 
| 10 | numrows <- "How many rows of clinical data are their in each data set (separate each number by a comma no spaces)?: " %>% | 10 | numrows <- "How many rows of clinical data are their in each data set (separate each number by a comma no spaces)?: " %>% | 
| 11 | readline(prompt = .) %>% | 11 | readline(prompt = .) %>% | 
| 12 | strsplit(.,split = ",") %>% | 12 | strsplit(.,split = ",") %>% | 
| 13 | .[[1]] %>% | 13 | .[[1]] %>% | 
| 14 | as.integer(.) | 14 | as.integer(.) | 
| 15 | i <- 1 | 15 | i <- 1 | 
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | for(i in 1:length(numrows)){ | 18 | for(i in 1:length(numrows)){ | 
| 19 | if( i == 1){ | 19 | if( i == 1){ | 
| 20 | edfile <- ANDIS[i] | 20 | edfile <- ANDIS[i] | 
| 21 | ed <- edfile %>% | 21 | ed <- edfile %>% | 
| 22 | read_delim(.,delim = "\t") | 22 | read_delim(.,delim = "\t") | 
| 23 | ednocd <- ed[-(1:numrows[1]),] | 23 | ednocd <- ed[-(1:numrows[1]),] | 
| 24 | #Second file brought in | 24 | #Second file brought in | 
| 25 | eddfile <- ANDIS[i + 1] | 25 | eddfile <- ANDIS[i + 1] | 
| 26 | edd <- eddfile %>% | 26 | edd <- eddfile %>% | 
| 27 | read_delim(.,delim = "\t") | 27 | read_delim(.,delim = "\t") | 
| 28 | eddnocd <- edd[-(1:numrows[2]),] | 28 | eddnocd <- edd[-(1:numrows[2]),] | 
| 29 | 29 | ||
| 30 | ##Fully matched both data sets | 30 | ##Fully matched both data sets | 
| 31 | eddy <- inner_join(ednocd,eddnocd) | 31 | eddy <- inner_join(ednocd,eddnocd,by = "ID_REF") | 
| 32 | #Matches | 32 | #Matches | 
| 33 | meds <- eddy[,1] | 33 | meds <- eddy[,1] | 
| 34 | 34 | ||
| 35 | } | 35 | } | 
| 36 | if(i > 1 && ((i + 1) <= length(numrows))){ | 36 | if(i > 1 && ((i + 1) <= length(numrows))){ | 
| 37 | eddfile <- ANDIS[i + 1] | 37 | eddfile <- ANDIS[i + 1] | 
| 38 | edd <- eddfile %>% | 38 | edd <- eddfile %>% | 
| 39 | read_delim(.,delim = "\t") | 39 | read_delim(.,delim = "\t") | 
| 40 | eddnocd <- edd[-(1:numrows[i + 1]),] | 40 | eddnocd <- edd[-(1:numrows[i + 1]),] | 
| 41 | ##Fully matched both data sets | 41 | ##Fully matched both data sets | 
| 42 | eddy <- inner_join(meds,eddnocd) | 42 | eddy <- inner_join(meds,eddnocd,by = "ID_REF") | 
| 43 | meds <- eddy[,1] | 43 | meds <- eddy[,1] | 
| 44 | 44 | ||
| 45 | 45 | ||
| 46 | } | 46 | } | 
| 47 | } | 47 | } | 
| 48 | meds | 48 | meds | 
| 49 | for(j in 1:length(numrows)){ | 49 | for(j in 1:length(numrows)){ | 
| 50 | edfile <- ANDIS[j] | 50 | edfile <- ANDIS[j] | 
| 51 | ed <- edfile %>% | 51 | ed <- edfile %>% | 
| 52 | read_delim(.,delim = "\t") | 52 | read_delim(.,delim = "\t") | 
| 53 | ednocd <- ed[-(1:numrows[j]),] | 53 | ednocd <- ed[-(1:numrows[j]),] | 
| 54 | #use meds to match | 54 | #use meds to match | 
| 55 | eddy <- inner_join(meds,ednocd) | 55 | eddy <- inner_join(meds,ednocd,by = "ID_REF") | 
| 56 | Finedm <- rbind(ed[1:numrows[j],],eddy) | 56 | Finedm <- rbind(ed[1:numrows[j],],eddy) | 
| 57 | nam_fil_ed <- strsplit(edfile,"[\\|/]") %>% | 57 | nam_fil_ed <- strsplit(edfile,"[\\|/]") %>% | 
| 58 | .[[1]] %>% | 58 | .[[1]] %>% | 
| 59 | .[length(.)] %>% | 59 | .[length(.)] %>% | 
| 60 | gsub("\\D","",.) %>% | 60 | gsub("\\D","",.) %>% | 
| 61 | c("GSE",.,"matched.txt") %>% | 61 | c("GSE",.,"matched.txt") %>% | 
| 62 | paste(collapse = "") | 62 | paste(collapse = "") | 
| 63 | write.table(Finedm,file = nam_fil_ed,sep = "\t",row.names = FALSE) | 63 | write.table(Finedm,file = nam_fil_ed,sep = "\t",row.names = FALSE) | 
| 64 | } | 64 | } | 
| 65 | meds | 65 | meds | 
| 66 | } | 66 | } | 
| 67 | 67 | ||
| 68 | Check2Match() | 68 | Check2Match() |