Commit b0ad80bb4c1950d4f23a1495e811b76dc8362e4d
1 parent
7acfa60c60
Exists in
master
UPDATE!!!! Changed from i+1 < to i+1<=
Will affect previous results
Showing
1 changed file
with
1 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) |
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) |
43 | meds <- eddy[,1] | 43 | meds <- eddy[,1] |
44 | 44 | ||
45 | 45 | ||
46 | } | 46 | } |
47 | i <- i + 1 | ||
48 | } | 47 | } |
49 | meds | 48 | meds |
50 | for(j in 1:length(numrows)){ | 49 | for(j in 1:length(numrows)){ |
51 | edfile <- ANDIS[j] | 50 | edfile <- ANDIS[j] |
52 | ed <- edfile %>% | 51 | ed <- edfile %>% |
53 | read_delim(.,delim = "\t") | 52 | read_delim(.,delim = "\t") |
54 | ednocd <- ed[-(1:numrows[j]),] | 53 | ednocd <- ed[-(1:numrows[j]),] |
55 | #use meds to match | 54 | #use meds to match |
56 | eddy <- inner_join(meds,ednocd) | 55 | eddy <- inner_join(meds,ednocd) |
57 | Finedm <- rbind(ed[1:numrows[j],],eddy) | 56 | Finedm <- rbind(ed[1:numrows[j],],eddy) |
58 | nam_fil_ed <- strsplit(edfile,"[\\|/]") %>% | 57 | nam_fil_ed <- strsplit(edfile,"[\\|/]") %>% |
59 | .[[1]] %>% | 58 | .[[1]] %>% |
60 | .[length(.)] %>% | 59 | .[length(.)] %>% |
61 | gsub("\\D","",.) %>% | 60 | gsub("\\D","",.) %>% |
62 | c("GSE",.,"matched.txt") %>% | 61 | c("GSE",.,"matched.txt") %>% |
63 | paste(collapse = "") | 62 | paste(collapse = "") |
64 | 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) |
65 | j <- j + 1 | ||
66 | } | 64 | } |
67 | meds | 65 | meds |
68 | } | 66 | } |
69 | 67 | ||
70 | Check2Match() | 68 | Check2Match() |