Commit 7acfa60c605a052988391cb81ca9c4a3e982a80b
1 parent
52de10530c
Exists in
master
Update reordered questions asked
Showing
1 changed file
with
2 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 | ANDIS <- select.list(choices = list.files(),multiple = TRUE, title = "Choose the file/files you want to analyze:") | ||
9 | 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)?: " %>% |
10 | readline(prompt = .) %>% | 11 | readline(prompt = .) %>% |
11 | strsplit(.,split = ",") %>% | 12 | strsplit(.,split = ",") %>% |
12 | .[[1]] %>% | 13 | .[[1]] %>% |
13 | as.integer(.) | 14 | as.integer(.) |
14 | i <- 1 | 15 | i <- 1 |
15 | ANDIS <- select.list(choices = list.files(),multiple = TRUE, title = "Choose the file/files you want to analyze:") | 16 | |
16 | 17 | ||
17 | for(i in 1:length(numrows)){ | 18 | for(i in 1:length(numrows)){ |
18 | if( i == 1){ | 19 | if( i == 1){ |
19 | edfile <- ANDIS[i] | 20 | edfile <- ANDIS[i] |
20 | ed <- edfile %>% | 21 | ed <- edfile %>% |
21 | read_delim(.,delim = "\t") | 22 | read_delim(.,delim = "\t") |
22 | ednocd <- ed[-(1:numrows[1]),] | 23 | ednocd <- ed[-(1:numrows[1]),] |
23 | #Second file brought in | 24 | #Second file brought in |
24 | eddfile <- ANDIS[i + 1] | 25 | eddfile <- ANDIS[i + 1] |
25 | edd <- eddfile %>% | 26 | edd <- eddfile %>% |
26 | read_delim(.,delim = "\t") | 27 | read_delim(.,delim = "\t") |
27 | eddnocd <- edd[-(1:numrows[2]),] | 28 | eddnocd <- edd[-(1:numrows[2]),] |
28 | 29 | ||
29 | ##Fully matched both data sets | 30 | ##Fully matched both data sets |
30 | eddy <- inner_join(ednocd,eddnocd) | 31 | eddy <- inner_join(ednocd,eddnocd) |
31 | #Matches | 32 | #Matches |
32 | meds <- eddy[,1] | 33 | meds <- eddy[,1] |
33 | 34 | ||
34 | } | 35 | } |
35 | if(i > 1 && i + 1 < length(numrows)){ | 36 | if(i > 1 && i + 1 < length(numrows)){ |
36 | eddfile <- ANDIS[i + 1] | 37 | eddfile <- ANDIS[i + 1] |
37 | edd <- eddfile %>% | 38 | edd <- eddfile %>% |
38 | read_delim(.,delim = "\t") | 39 | read_delim(.,delim = "\t") |
39 | eddnocd <- edd[-(1:numrows[i + 1]),] | 40 | eddnocd <- edd[-(1:numrows[i + 1]),] |
40 | ##Fully matched both data sets | 41 | ##Fully matched both data sets |
41 | eddy <- inner_join(meds,eddnocd) | 42 | eddy <- inner_join(meds,eddnocd) |
42 | meds <- eddy[,1] | 43 | meds <- eddy[,1] |
43 | 44 | ||
44 | 45 | ||
45 | } | 46 | } |
46 | i <- i + 1 | 47 | i <- i + 1 |
47 | } | 48 | } |
48 | meds | 49 | meds |
49 | for(j in 1:length(numrows)){ | 50 | for(j in 1:length(numrows)){ |
50 | edfile <- ANDIS[j] | 51 | edfile <- ANDIS[j] |
51 | ed <- edfile %>% | 52 | ed <- edfile %>% |
52 | read_delim(.,delim = "\t") | 53 | read_delim(.,delim = "\t") |
53 | ednocd <- ed[-(1:numrows[j]),] | 54 | ednocd <- ed[-(1:numrows[j]),] |
54 | #use meds to match | 55 | #use meds to match |
55 | eddy <- inner_join(meds,ednocd) | 56 | eddy <- inner_join(meds,ednocd) |
56 | Finedm <- rbind(ed[1:numrows[j],],eddy) | 57 | Finedm <- rbind(ed[1:numrows[j],],eddy) |
57 | nam_fil_ed <- strsplit(edfile,"[\\|/]") %>% | 58 | nam_fil_ed <- strsplit(edfile,"[\\|/]") %>% |
58 | .[[1]] %>% | 59 | .[[1]] %>% |
59 | .[length(.)] %>% | 60 | .[length(.)] %>% |
60 | gsub("\\D","",.) %>% | 61 | gsub("\\D","",.) %>% |
61 | c("GSE",.,"matched.txt") %>% | 62 | c("GSE",.,"matched.txt") %>% |
62 | paste(collapse = "") | 63 | paste(collapse = "") |
63 | write.table(Finedm,file = nam_fil_ed,sep = "\t",row.names = FALSE) | 64 | write.table(Finedm,file = nam_fil_ed,sep = "\t",row.names = FALSE) |
64 | j <- j + 1 | 65 | j <- j + 1 |
65 | } | 66 | } |
66 | meds | 67 | meds |
67 | } | 68 | } |
68 | 69 | ||
69 | Check2Match() | 70 | Check2Match() |