Commit 4d40f2746596baecff36ec15a7d5b389b0aca34c
1 parent
02c140cb2b
Exists in
master
Update first question
Showing
1 changed file
with
1 additions
and
1 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 | numrows <- "How many rows of clinical data are their in each data set (seperate each number by a comma no spaces)?: " %>% | 9 | numrows <- "How many rows of clinical data are their in each data set (separate each number by a comma no spaces)?: " %>% |
| 10 | readline(prompt = .) %>% | 10 | readline(prompt = .) %>% |
| 11 | strsplit(.,split = ",") %>% | 11 | strsplit(.,split = ",") %>% |
| 12 | .[[1]] %>% | 12 | .[[1]] %>% |
| 13 | as.integer(.) | 13 | as.integer(.) |
| 14 | i <- 1 | 14 | i <- 1 |
| 15 | ANDIS <- select.list(choices = list.files(),multiple = TRUE, title = "Choose the file/files you want to analyze:") | 15 | ANDIS <- select.list(choices = list.files(),multiple = TRUE, title = "Choose the file/files you want to analyze:") |
| 16 | 16 | ||
| 17 | for(i in 1:length(numrows)){ | 17 | for(i in 1:length(numrows)){ |
| 18 | if( i == 1){ | 18 | if( i == 1){ |
| 19 | edfile <- ANDIS[i] | 19 | edfile <- ANDIS[i] |
| 20 | ed <- edfile %>% | 20 | ed <- edfile %>% |
| 21 | read_delim(.,delim = "\t") | 21 | read_delim(.,delim = "\t") |
| 22 | ednocd <- ed[-(1:numrows[1]),] | 22 | ednocd <- ed[-(1:numrows[1]),] |
| 23 | #Second file brought in | 23 | #Second file brought in |
| 24 | eddfile <- ANDIS[i + 1] | 24 | eddfile <- ANDIS[i + 1] |
| 25 | edd <- eddfile %>% | 25 | edd <- eddfile %>% |
| 26 | read_delim(.,delim = "\t") | 26 | read_delim(.,delim = "\t") |
| 27 | eddnocd <- edd[-(1:numrows[2]),] | 27 | eddnocd <- edd[-(1:numrows[2]),] |
| 28 | 28 | ||
| 29 | ##Fully matched both data sets | 29 | ##Fully matched both data sets |
| 30 | eddy <- inner_join(ednocd,eddnocd) | 30 | eddy <- inner_join(ednocd,eddnocd) |
| 31 | #Matches | 31 | #Matches |
| 32 | meds <- eddy[,1] | 32 | meds <- eddy[,1] |
| 33 | 33 | ||
| 34 | } | 34 | } |
| 35 | if(i > 1 && i + 1 < length(numrows)){ | 35 | if(i > 1 && i + 1 < length(numrows)){ |
| 36 | eddfile <- ANDIS[i + 1] | 36 | eddfile <- ANDIS[i + 1] |
| 37 | edd <- eddfile %>% | 37 | edd <- eddfile %>% |
| 38 | read_delim(.,delim = "\t") | 38 | read_delim(.,delim = "\t") |
| 39 | eddnocd <- edd[-(1:numrows[i + 1]),] | 39 | eddnocd <- edd[-(1:numrows[i + 1]),] |
| 40 | ##Fully matched both data sets | 40 | ##Fully matched both data sets |
| 41 | eddy <- inner_join(meds,eddnocd) | 41 | eddy <- inner_join(meds,eddnocd) |
| 42 | meds <- eddy[,1] | 42 | meds <- eddy[,1] |
| 43 | 43 | ||
| 44 | 44 | ||
| 45 | } | 45 | } |
| 46 | i <- i + 1 | 46 | i <- i + 1 |
| 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) |
| 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 | j <- j + 1 | 64 | j <- j + 1 |
| 65 | } | 65 | } |
| 66 | meds | 66 | meds |
| 67 | } | 67 | } |
| 68 | 68 | ||
| 69 | Check2Match() | 69 | Check2Match() |