-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseqformat.R
1458 lines (1406 loc) · 62.6 KB
/
seqformat.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# seqFormatR v2.3 Development copy. Restructure for TXlevel data and non-human experiments.
#contact acastanza@ucsd.edu with issues
cat("We're going to interactively process your RNA-seq data to output GSEA Compatible files.\n")
cat("Lets get started\n")
cat("Loading dplyr library for data formatting\n")
library("dplyr")
cat("Loaded dplyr for data structuring\n")
cat("\n")
if (exists("altnorm") == FALSE) {
altnorm <- FALSE
}
## before running script set altnorm <- "userlog" or "usevst" or "useall" to
## output additional alternate normalized GCTs using deseq2's rlog or vst functions
iscounts <- FALSE
txlevel <- FALSE
FAIL <- FALSE
isnormalized <- FALSE
TYPE <- NULL
txtype <- "FALSE"
is_directory <- FALSE
getgeofiles <- FALSE
seondaryfactor <- FALSE
NORM <- FALSE
USEDRSEMTXLEVEL <- FALSE
altspecies <- FALSE
mapspecies <- FALSE
# Get Input Files and Prompt User for Necessary Information Set Working Directory
changewd <- askYesNo("Would you like to set a working directory for this session?")
if(changewd == TRUE){
path <- readline(prompt = ("Drop a directory into R window to use as the output folder or enter directory path: "))
setwd(path)
cat("Done\n")
cat("\n")}
getgeofiles <- askYesNo("Attempt to get data directly from GEO \"supplementary files\"? ")
if (getgeofiles == TRUE) {
readline(prompt = ("This step requires the Bioconductor package \"GEOquery\". Make sure it is installed, then press enter to continue..."))
library("GEOquery")
library("tools")
geoid <- readline(prompt = ("Enter the GEOID for the datafiles (eg: GSE107638): "))
geooutfiles <- getGEOSuppFiles(geoid, makeDirectory = TRUE, baseDir = getwd(),
fetch_files = TRUE, filter_regex = NULL)
cat("Getting experiment information from Series Matrix...\n")
gsefile <- getGEO(geoid)
phenotypedata <- as.data.frame(pData(phenoData(gsefile[[1]]))[, c("geo_accession",
"title")], stringsAsFactors = FALSE)
rownames(phenotypedata) <- 1:nrow(phenotypedata)
geostructure <- pData(phenoData(gsefile[[1]]))
cat("\n")
print(phenotypedata)
cat("\n")
cat("Files acquired from GEO:\n")
geoimporttable <- as.data.frame(rownames(geooutfiles), stringsAsFactors = FALSE)
print(rownames(geooutfiles))
# print('All')
cat("\n")
if (nrow(geoimporttable) > 1) {
useall <- askYesNo("Use all downloaded files? (\"No\" allows you to select a specific file)")
if (useall == TRUE) {
genematrix <- paste0(getwd(), "/", geoid)
}
if (useall == FALSE) {
geoselected <- readline(prompt = ("Select which GEO file to use for downstream processing: "))
geoselectednumber <- match(geoselected, cbind(rownames(geoimporttable),
geoimporttable)[, 1])
if (is.na(geoselectednumber) == TRUE) {
geoselectednumber <- match(geoselected, cbind(rownames(geoimporttable),
geoimporttable)[, 2])
}
outfile <- rownames(geooutfiles)[geoselectednumber]
if (file_ext(rownames(geooutfiles)[geoselectednumber]) == "tar") {
untar(rownames(geooutfiles)[geoselectednumber], exdir = paste0(dirname(rownames(geooutfiles)[geoselectednumber]),
"/", basename(tools::file_path_sans_ext(rownames(geooutfiles)[geoselectednumber]))))
outfile <- paste0(dirname(rownames(geooutfiles)[geoselectednumber]),
"/", basename(tools::file_path_sans_ext(rownames(geooutfiles)[geoselectednumber])))
}
genematrix <- outfile
}
} else if (nrow(geoimporttable) == 1) {
if (file_ext(rownames(geooutfiles)[1]) == "tar") {
untar(rownames(geooutfiles)[1], exdir = paste0(dirname(rownames(geooutfiles)[1]),
"/", basename(tools::file_path_sans_ext(rownames(geooutfiles)[1]))))
outfile <- paste0(dirname(rownames(geooutfiles)[1]), "/", basename(tools::file_path_sans_ext(rownames(geooutfiles)[1])))
} else {
outfile <- paste0(geoimporttable[1])
}
genematrix <- outfile
}
cat("\n")
cat("Experiment Imported.\n")
cat("\n")
findcounts <- apply(geostructure, 2, function(x) {
grepl("counts|Counts", x)
})
if (any(findcounts) == TRUE) {
message("Series Matrix implies that this data consists of COUNTS:\n")
print(unique(geostructure[findcounts]))
iscounts <- askYesNo("Do you agree that this is gene COUNTS data? ")
cat("\n")
if (iscounts == TRUE) {
countsdetected <- TRUE
istx <- FALSE
TYPE <- "COUNTS"
}
} else if (any(findcounts) == FALSE) {
cat("We couldn't automatically set the datatype\n")
cat("We'll prompt you to manually select datatype next.\n")
}
findtxquant <- apply(geostructure, 2, function(x) {
grepl("almon|ailfish|allisto", x)
})
if (any(findtxquant) == TRUE) {
cat("\n")
message("Series Matrix implies that this data might be transcript level quantifications:\n")
print(unique(geostructure[findtxquant]))
cat("\n")
message("Validate the presence of transcript level quantifications in data files, then continue.\n")
cat("\n")
}
findnormal <- apply(geostructure, 2, function(x) {
grepl("normalized|Normalized|NORMALIZED|normalised|Normalised|NORMALISED",
x)
})
if (any(findnormal) == TRUE) {
message("Series Matrix implies that this data might be ALREADY NORMALIZED:\n")
print(unique(geostructure[findnormal]))
isnormalized <- askYesNo("Is this data already normalized? ")
if (isnormalized == TRUE) {
NORM <- TRUE
DESEQ2DONE <- FALSE
}
} else if (any(findnormal) == FALSE) {
message("Series Matrix implies that this data might require normalization.\n")
isnormalized <- askYesNo("Is this data already normalized? ")
if (isnormalized == FALSE) {
NORM <- FALSE
DESEQ2DONE <- FALSE
}
}
}
if (iscounts == FALSE) {
istx <- askYesNo("Is your dataset transcript level abundance measurements from Salmon/Kallisto/Sailfish? ")
if (istx == FALSE) {
isrsem <- askYesNo("Is your dataset raw abundance measurements from RSEM? ")
if (isrsem == TRUE) {
if (getgeofiles == TRUE)
{
dir <- dirname(genematrix)
} #GEO
txtype <- "RSEM"
txlevel <- TRUE
TYPE <- txtype
NORM <- FALSE
readline(prompt = ("This step requires the Bioconductor package \"tximport\". Make sure it is installed, then press enter to continue..."))
library("tximport")
}
}
}
if (txtype == "RSEM") {
TYPE <- txtype
if (getgeofiles == FALSE) {
dir <- readline(prompt = ("Drop a directory containing RSEM output into R Window or Enter Directory Path: "))
}
rsemcontents <- as.data.frame(paste0(tools::file_path_sans_ext(tools::file_path_sans_ext(list.files(dir,
recursive = TRUE, full.names = FALSE, pattern = ".results.gz")))), stringsAsFactors = FALSE)
rsemgenes <- as.data.frame(paste0(tools::file_path_sans_ext(tools::file_path_sans_ext(list.files(dir,
recursive = TRUE, full.names = FALSE, pattern = ".genes.results.gz")))),
stringsAsFactors = FALSE)
rsemtxs <- as.data.frame(paste0(tools::file_path_sans_ext(tools::file_path_sans_ext(list.files(dir,
recursive = TRUE, full.names = FALSE, pattern = ".isoforms.results.gz")))),
stringsAsFactors = FALSE)
rsemgenetest <- rsemgenes[, 1] %in% rsemcontents[, 1]
rsemtxtest <- rsemtxs[, 1] %in% rsemcontents[, 1]
if (all(rsemgenetest == TRUE) == TRUE) {
cat("Gene level RSEM quantifications are available. Using these directly.\n ")
USEDRSEMTXLEVEL <- FALSE
files <- list.files(dir, recursive = TRUE, full.names = TRUE, pattern = ".genes.results.gz")
names(files) <- paste0(tools::file_path_sans_ext(tools::file_path_sans_ext(list.files(dir,
recursive = TRUE, full.names = FALSE, pattern = ".genes.results.gz"))))
txi.rsem <- tximport(files, type = "rsem", txIn = FALSE, txOut = FALSE)
txi.rsemcounts <- as.data.frame(txi.rsem$counts)
} else if (all(rsemtxtest == TRUE) == TRUE) {
cat("Gene level RSEM quantifications are NOT available.\n ")
cat("Using RSEM isoform abundances. This is a little messy.\n ")
USEDRSEMTXLEVEL <- TRUE
files <- list.files(dir, recursive = TRUE, full.names = TRUE, pattern = ".isoforms.results.gz")
names(files) <- paste0(tools::file_path_sans_ext(tools::file_path_sans_ext(list.files(dir,
recursive = TRUE, full.names = FALSE, pattern = ".isoforms.results.gz"))))
txi.rsem <- tximport(files, type = "rsem", txIn = TRUE, txOut = TRUE)
txi.rsemcounts <- as.data.frame(txi.rsem$counts)
}
print("Done") #fixes a small bug in tximport rsem output
cat("\n")
cat("Identifiers:\n")
print(head(txi.rsemcounts[, 1], 3))
txi.rsemcounts <- tibble::rownames_to_column(txi.rsemcounts, "GENEID")
cat("\n")
if (all(rsemgenetest == TRUE) == TRUE) {
genehasversions <- askYesNo("Do your GENE IDs have decimal versions? (eg. ENSG00000158321.16)? ")
} else if (USEDRSEMTXLEVEL == TRUE) {
colnames(txi.rsemcounts)[1] <- "TXNAME"
genehasversions <- askYesNo("Do your TRANSCRIPT IDs have decimal versions? (eg. ENST00000342771.9)? ")
}
cat("\n")
if (genehasversions == TRUE) {
txi.rsemcounts[, 1] <- gsub("\\..*", "", txi.rsemcounts[, 1])
genehasversions <- FALSE
}
txi.rsemcounts <- distinct(txi.rsemcounts)
txi.rsemcounts <- txi.rsemcounts %>% group_by(GENEID) %>% summarise_all(sum) %>%
data.frame()
tximportcounts <- txi.rsemcounts
}
if (istx == TRUE | USEDRSEMTXLEVEL == TRUE) {
TYPE <- "TXABUNDANCE"
txlevel <- TRUE
readline(prompt = ("This step requires the Bioconductor package \"tximport\". Make sure it is installed, then press enter to continue..."))
library("tximport")
NORM <- FALSE
iscounts <- FALSE
cat("\n")
cat("To process transcript alignments we need either an existing \"tx2gene\" file, a Gencode GTF/GFF3, or we can pull from ENSEMBL.\n")
tx2geneexists <- askYesNo("Do you have an existing tx2gene annotation file you wish to provide? ")
if (tx2geneexists == TRUE) {
tx2genepath <- readline(prompt = ("Drop Your tx2gene file into R Window or Enter full path to file: "))
cat("\n")
library("tools")
tx2genetype <- file_ext(gsub(".gz$", "", tx2genepath))
if (tx2genetype == "csv") {
tx2gene <- read.table(tx2genepath, sep = ",", header = T)
cat("Identifiers:\n")
print(as.data.frame(head(tx2gene[, 1:2], 3)))
txhasversions <- askYesNo("Do your TRANSCRIPT IDs have decimal versions? (eg. ENST00000342771.9)? ")
if (txhasversions == TRUE) {
tx2gene[, 1] <- gsub("\\..*", "", tx2gene[, 1])
txhasversions <- FALSE
}
genehasversions <- askYesNo("Do your GENE IDs have decimal versions? (eg. ENSG00000158321.16)? ")
if (genehasversions == TRUE) {
tx2gene[, 2] <- gsub("\\..*", "", tx2gene[, 2])
genehasversions <- FALSE
}
}
if (tx2genetype == "txt" | tx2genetype == "tsv" | tx2genetype == "tabular") {
tx2gene <- read.table(tx2genepath, sep = "\t", header = T)
print(head(tx2gene))
txhasversions <- askYesNo("Do your TRANSCRIPT IDs have decimal versions? (eg. ENST00000342771.9)? ")
if (txhasversions == TRUE) {
tx2gene[, 1] <- gsub("\\..*", "", tx2gene[, 1])
txhasversions <- FALSE
}
genehasversions <- askYesNo("Do your GENE IDs have decimal versions? (eg. ENSG00000158321.16)? ")
if (genehasversions == TRUE) {
tx2gene[, 2] <- gsub("\\..*", "", tx2gene[, 2])
genehasversions <- FALSE
}
}
tx2gene <- distinct(tx2gene)
print(head(tx2gene))
cat("This should be formatted as a two column file with TX IDs on the left and Gene IDs on the right and no version decimals.\n")
tx2genebuild <- FALSE
} else if (tx2geneexists == FALSE) {
cat("Ok... \n")
tx2genebuild <- TRUE
cat("\n")
cat("We can attempt to construct the tx2gene file automatically. \n")
cat("Building from a GTF/GFF3, which requires the GenomicFeatures Package from Bioconductor.\n")
cat("Building from ENSEMBL, which requires the biomaRt Package from Bioconductor.\n")
cat("\n")
tx2genesource <- menu(c("Use GTF/GFF3 file","Use ENSEMBL"))
if (tx2genesource == 1) {
if (tx2genebuild == TRUE) {
library("GenomicFeatures")
txgft <- readline(prompt = ("Drop Your GTF/GFF3 file into R Window or Enter full path to file: "))
TxDb <- makeTxDbFromGFF(file = txgft)
k <- keys(TxDb, keytype = "TXNAME")
tx2gene <- select(TxDb, k, "GENEID", "TXNAME")
print(head(tx2gene, 3))
txhasversions <- askYesNo("Do your TRANSCRIPT IDs have decimal versions? (eg. ENST00000342771.9)? ")
if (txhasversions == TRUE) {
tx2gene[, 1] <- gsub("\\..*", "", tx2gene[, 1])
}
genehasversions <- askYesNo("Do your GENE IDs have decimal versions? (eg. ENSG00000158321.16)? ")
if (genehasversions == TRUE) {
tx2gene[, 2] <- gsub("\\..*", "", tx2gene[, 2])
genehasversions <- FALSE
}
tx2geneexists <- TRUE
cat("The Tx2Gene file should be formatted as a two column file with TX IDs on the left and Gene IDs on the right.\n")
tx2gene <- distinct(tx2gene)
}
if (tx2geneexists == FALSE) {
cat("We can't continue with transcript level data without transcript to gene mappings...\n")
FAIL <- TRUE
if (FAIL == TRUE) {
stop("Necessary files are not available so processing was terminated.")
}
}
}
if (tx2genesource == 2) {
readline(prompt = ("This step requires the Bioconductor package \"biomaRt\". Make sure it is installed, then press enter to continue..."))
library("biomaRt")
cat("Default: ENSEMBL Version 97 - Human\n")
altversion <- askYesNo("Do you want to override this default? ")
if (altversion == TRUE) {
ensemblversion <- readline(prompt = ("Enter the ENSEMBL version (eg. 96) you want to use (number only): "))
#species <- "hsapiens_gene_ensembl"
altspecies <- askYesNo("The default species is HUMAN you want to override this default? ")
if (altspecies == TRUE){
datasets <- as.data.frame(listDatasets(useEnsembl(biomart="ensembl",version=ensemblversion)), header =T)
speciesnumber <- menu(datasets[,2], title="Select the species of the dataset you wish to process:")
species <- datasets[speciesnumber,1]
} else if (altspecies == FALSE){species <- "hsapiens_gene_ensembl"}
} else if (altversion == FALSE) {
ensemblversion <- "97"
species <- "hsapiens_gene_ensembl"
cat("Using ENSEMBL97 annotations matching MSigDB7...\n")
}
ensmart <- useEnsembl(biomart = "ensembl", dataset = species,
version = paste0(ensemblversion))
cat("Building ENSEMBL Transcript -> Gene Symbol Mappings...\n")
rawtx2gene <- getBM(attributes = c("ensembl_transcript_id", "ensembl_gene_id"),
mart = ensmart)
colnames(rawtx2gene) <- c("TXNAME", "GENEID")
tx2gene <- distinct(rawtx2gene)
}
}
cat("\n")
message("How were your transcripts quantified? tximport supports the following methods:\n")
# cat("[1] Salmon\n")
# cat("[2] Sailfish\n")
# cat("[3] Kallisto\n")
# # cat('[5] Stringtie\n') cat('[6] Generic Transcript Level Quantification
# # Table\n')
# cat("\n")
# txtype <- readline(prompt = ("Select your platform by entering the corresponding >>NUMBER<< (without brackets): "))
if (USEDRSEMTXLEVEL != TRUE){
txtype <- select.list(c("Salmon", "Sailfish", "Kallisto", "Unknown"))
cat("\n")
if (getgeofiles == TRUE)
{
if (nrow(geoimporttable) > 1) {
dir <- genematrix
} else {
dir <- dirname(genematrix)
}
} #GEO
if (txtype == "Salmon") {
if (getgeofiles == FALSE) {
dir <- readline(prompt = ("Drop a directory containing Salmon output into R Window or Enter Directory Path: "))
}
files <- list.files(dir, recursive = TRUE, full.names = TRUE, pattern = ".sf|.sf.gz")
names(files) <- paste0(tools::file_path_sans_ext(tools::file_path_sans_ext(list.files(dir,
recursive = TRUE, full.names = FALSE, pattern = ".sf|.sf.gz"))))
if (length(files) > 0) {
txi.salmon <- tximport(files, type = "salmon", tx2gene = tx2gene, ignoreTxVersion = TRUE,
ignoreAfterBar = TRUE)
tximportcounts <- as.data.frame(txi.salmon$counts)
tximportcounts <- tibble::rownames_to_column(tximportcounts, "GENEID")
expids <- "GENEID"
} else if (length(files) == 0) {
txtype <- "Unknown"
}
} else if (txtype == "Sailfish") {
if (getgeofiles == FALSE) {
dir <- readline(prompt = ("Drop a directory containing Sailfish output into R Window or Enter Directory Path: "))
}
files <- list.files(dir, recursive = TRUE, full.names = TRUE, pattern = "quant.sf|quant.sf.gz")
names(files) <- paste0(tools::file_path_sans_ext(tools::file_path_sans_ext(list.files(dir,
recursive = TRUE, full.names = FALSE, pattern = "quant.sf|quant.sf.gz"))))
if (length(files) > 0) {
txi.sailfish <- tximport(files, type = "sailfish", tx2gene = tx2gene,
ignoreTxVersion = TRUE, ignoreAfterBar = TRUE)
tximportcounts <- as.data.frame(txi.sailfish$counts)
tximportcounts <- tibble::rownames_to_column(tximportcounts, "GENEID")
expids <- "GENEID"
} else if (length(files) == 0) {
txtype <- "Unknown"
}
} else if (txtype == "Kallisto") {
cat("Import Kallisto abundances from \"abundance.h5\" (requires rhdf5 library), or \"abundance.tsv*\".\n")
kallistotype <- readline(prompt = ("Select kallisto datatype by entering \"h5\" or \"tsv\" (without quotes): "))
if (kallistotype == "h5") {
readline(prompt = ("This step requires the Bioconductor package \"rhdf5\". Make sure it is installed, then press enter to continue..."))
library("rhdf5")
if (getgeofiles == FALSE) {
dir <- readline(prompt = ("Drop a directory containing Kallisto output into R Window or Enter Directory Path: "))
}
files <- list.files(dir, recursive = TRUE, full.names = TRUE, pattern = "abundance.h5|abundance.h5.gz")
if (length(files) > 0) {
names(files) <- paste0(tools::file_path_sans_ext(tools::file_path_sans_ext(list.files(dir,
recursive = TRUE, full.names = FALSE, pattern = "abundance.h5|abundance.h5.gz"))))
txi.kallisto.h5 <- tximport(files, type = "kallisto", tx2gene = tx2gene,
ignoreTxVersion = TRUE, ignoreAfterBar = TRUE)
tximportcounts <- as.data.frame(txi.kallisto.h5$abundance)
tximportcounts <- tibble::rownames_to_column(tximportcounts, "GENEID")
expids <- "GENEID"
} else if (length(files) == 0) {
txtype <- "Unknown"
}
}
if (kallistotype == "tsv") {
if (getgeofiles == FALSE) {
dir <- readline(prompt = ("Drop a directory containing Kallisto output into R Window or Enter Directory Path: "))
}
files <- list.files(dir, recursive = TRUE, full.names = TRUE, pattern = "abundance.tsv|abundance.tsv.gz")
if (length(files) > 0) {
names(files) <- paste0(tools::file_path_sans_ext(tools::file_path_sans_ext(list.files(dir,
recursive = TRUE, full.names = FALSE, pattern = "abundance.tsv|abundance.tsv.gz"))))
txi.kallisto.tsv <- tximport(files, type = "kallisto", tx2gene = tx2gene,
ignoreTxVersion = TRUE, ignoreAfterBar = TRUE)
tximportcounts <- as.data.frame(txi.kallisto.tsv$abundance)
tximportcounts <- tibble::rownames_to_column(tximportcounts, "GENEID")
expids <- "GENEID"
} else if (length(files) == 0) {
txtype <- "Unknown"
}
}
} else if (txtype == "Stringtie") {
cat("Stringtie suppot not yet implemented\n")
# cat('We can import files produced by running the \'stringtie -eB -G
# transcripts.gff <source_file.bam>\' command per the TXImport tutorial.\n')
# dir <- readline(prompt=('Drop a directory containing Stringtie output folder
# into R Window or Enter Directory Path: ')) samples <- list.files(dir) files <-
# file.path(dir, samples) tmp <- read_tsv(files[1]) print(head(tmp)) strtx <-
# readline(prompt=('Enter the column name that contains the stringtie transcript
# identifiers: ')) strgene <- readline(prompt=('Enter the column name that
# contains gene identifiers for which you have a GSEA compatible chip file (or
# gene symbols): ')) tx2gene <- tmp[, c(strtx, strgene)] print(head(tx2gene))
# readline(prompt=('If this looks correct, press enter to continue...')) txi <-
# tximport(tmp, type = 'stringtie', tx2gene = tx2gene)
FAIL <- TRUE
}
if (txtype == "Unknown") {
cat("Failover Mode. This method isn't really supported. Use at your own risk.\n")
cat("Could not detect transcript quantifications with tximport.\n")
cat(" We're going to have to make a lot of guesses here, but we'll get through this together.\n")
if (getgeofiles == FALSE) {
txmatrix <- readline(prompt = ("Drop Transcript Expression Matrix into R Window or Enter File Path (supports csv or tab delimited txt): "))
library("tools")
txmatrixtype <- file_ext(gsub(".gz$", "", txmatrix))
if (txmatrixtype == "csv") {
full <- read.table(txmatrix, sep = ",", header = T, row.names = NULL)
if (colnames(full)[1] == "X") {
colnames(full)[1] <- colnames(full["ID"])
}
if (colnames(full)[1] == "row.names") {
colnames(full)[1] <- colnames(full["ID"])
}
}
if (txmatrixtype == "txt" | txmatrix == "tabular" | txmatrix == "tsv" |
txmatrix == "tab") {
full <- read.table(txmatrix, sep = "\t", header = T, row.names = NULL)
if (colnames(full)[1] == "X") {
colnames(full)[1] <- colnames(full["ID"])
}
if (colnames(full)[1] == "row.names") {
colnames(full)[1] <- "ID"
}
}
if(txmatrixtype == ""){
message("Directory parsing is not yet supported through this prompt. Sorry.")
FAIL <- TRUE} #Add folder parser HERE
importdata <- as.data.frame(colnames(full), stringsAsFactors = FALSE,
header = FALSE)
colnames(full)[1] <- "EXPERIMENT"
cat("\n")
displayexp <- merge(x = importdata, y = t(full[c(1:3, 11:13), ]), by.x = 1,
by.y = 0)
print(displayexp)
expids <- readline(prompt = ("Enter the name from the EXPERIMENT column or row number above that defines your transcript identifiers: "))
expidnumber <- match(expids, cbind(rownames(importdata), importdata)[,
1])
if (is.na(expidnumber) == TRUE) {
expidnumber <- match(expids, cbind(rownames(importdata), importdata)[,
2])
}
colnames(mergedexp)[expidnumber] <- "TXNAME"
# expids <- "TXNAME"
cat("Transcript expression Matrix Imported\n")
# txlevel <- FALSE
cat("\n")
print(head(full, 3))
cat("\n")
# cat('When you're prompted for a CHIP file, instead provide a table mapping
# Transcript IDs to Gene Symbols and Descriptions USING CHIP HEADERS. Good
# Luck.\n') readline(prompt=('Press enter to continue...'))
}}
if (getgeofiles == TRUE) {
cat("Attempting to parse multiple individually quantified samples into single matrix...\n")
inputsamples <- list.files(outfile)
inputsamplestxt <- list.files(outfile, pattern = ".txt|.tsv|.tabular|.tab")
txtsamplenumber <- length(inputsamplestxt)
inputsamplescsv <- list.files(outfile, pattern = ".csv")
csvsamplenumber <- length(inputsamplescsv)
totalsamplenumber <- txtsamplenumber + csvsamplenumber
if (txtsamplenumber > 0) {
print(inputsamplestxt)
cat(paste(txtsamplenumber), "tabular formatted samples were detected in input directory.\n")
txtsamplepaths <- file.path(outfile, inputsamplestxt)
names(txtsamplepaths) <- paste0(inputsamplestxt)
import_txt <- lapply(txtsamplepaths, read.table, header = FALSE,
row.names = NULL, sep = "\t", stringsAsFactors = FALSE, comment.char = "")
for (i in 1:txtsamplenumber) {
do
colnames(import_txt[[i]]) <- paste(inputsamplestxt[i], colnames(import_txt[[i]]),
sep = "_")
}
}
if (csvsamplenumber > 0) {
print(inputsamplescsv)
cat(paste(csvsamplenumber), "csv formatted samples were detected in input directory.\n")
csvsamplepaths <- file.path(outfile, inputsamplescsv)
names(csvsamplepaths) <- paste0(inputsamplescsv)
import_csv <- lapply(csvsamplepaths, read.table, header = FALSE,
row.names = NULL, sep = ",", stringsAsFactors = FALSE, comment.char = "")
for (i in 1:csvsamplenumber) {
do
colnames(import_csv[[i]]) <- paste(inputsamplestxt[i], colnames(import_csv[[i]]),
sep = "_")
}
}
if ((txtsamplenumber > 0) == (csvsamplenumber > 0)) {
import.list <- append(import_txt, import_csv) #combine csv and txt imports
cat(paste(length(import.list)), "total samples were detected in input directory.\n")
} else if (csvsamplenumber == 0) {
import.list <- import_txt #process txt only
} else if (txtsamplenumber == 0) {
import.list <- import_csv #process csv only
}
keep <- askYesNo("Are all of the quantifications from the same pipeline? ")
if (keep == FALSE) {
list <- list(NA)
for (i in 1:length(names(import.list))) {
do
cat("\n")
cat("Sample: ", paste0(names(import.list[i])), "\n")
value <- askYesNo("Include in analysis? ")
if (value == TRUE) {
list[[1]][i] <- names(import.list[i])
}
}
list <- list[[1]][!is.na(list[[1]])]
import.list <- import.list[list]
}
importdata <- as.data.frame(colnames(import.list[[1]]), stringsAsFactors = FALSE,
header = FALSE)
colnames(importdata)[1] <- "EXPERIMENT"
cat("\n")
displayexp <- merge(x = importdata, y = t(import.list[[1]][c(1:3, 11:13),
]), by.x = 1, by.y = 0)
print(displayexp)
cat("\n")
cat("Selected a sample to use for learning dataset format: \n")
cat("\n")
rebuildheader <- askYesNo("Is there a more descriptive header than the one in the \"EXPERIMENT\" column? ")
if (rebuildheader == TRUE) {
cat("\n")
print(displayexp[2:4])
headnum <- as.numeric(readline(prompt = ("Enter the COLUMN NUMBER above that you want to use as the labels: ")))
importlist2 <- lapply(import.list, function(x) {
colnames(x) = x[headnum, ]
x = x[-headnum, ]
})
import.list <- importlist2
}
expids <- readline(prompt = ("Enter the name from the EXPERIMENT column or row number above that defines your transcript identifiers: "))
expidnumber <- match(expids, cbind(rownames(importdata), importdata)[,
1])
if (is.na(expidnumber) == TRUE) {
expidnumber <- match(expids, cbind(rownames(importdata), importdata)[,
2])
}
mergedexp <- Reduce(function(x, y) merge(x, y, all = FALSE, by = expidnumber,
all.x = TRUE, all.y = TRUE), import.list, accumulate = F)
colnames(mergedexp)[expidnumber] <- "TXNAME"
mergedexp_2 <- mergedexp
colnames(mergedexp_2) <- make.unique(colnames(mergedexp_2))
# Disabled autocleanup - causes issues with too many formats. mergedexp %>%
# select_if(is.numeric) -> mergedexp_2 mergedexp_2 <-
# cbind(mergedexp[expidnumber], mergedexp_2) mergedexp_2 <- mergedexp_2[,
# -grep('ength$', colnames(mergedexp_2))] cat('Cleaned up identifiable extraneous
# non-numeric columns.\n')
fullimportdata <- as.data.frame(colnames(mergedexp_2), stringsAsFactors = FALSE,
header = TRUE)
colnames(fullimportdata)[1] <- "EXPERIMENT"
displayfullexp <- merge(x = fullimportdata, y = t(mergedexp_2[c(1:3,
11:13), ]), by.x = 1, by.y = 0)
print(displayfullexp)
cat("There are", paste(length(colnames(mergedexp_2))), "entries in the Experiment data matrix.\n")
keepcols <- readline(prompt = ("How many are tx quantifications? (this should be one per sample): "))
removecols <- as.numeric(length(colnames(mergedexp_2))) - (1 + as.numeric(keepcols))
if (removecols > 0) {
repeat {
importdataloop <- fullimportdata
colnames(importdataloop) <- c("EXPERIMENT")
fullloop <- mergedexp_2
print(importdataloop)
for (i in 1:as.numeric(removecols)) {
do
cat("Discard everything except your Transcript IDs and your per sample quantifications. \n")
expidsdrop <- readline(prompt = ("Enter a name or row number from the EXPERIMENT column above that defines fields you want to DISCARD: "))
expiddropnumber <- match(expidsdrop, cbind(rownames(importdataloop),
importdataloop)[, 1])
if (is.na(expiddropnumber) == TRUE) {
expiddropnumber <- FALSE
}
if (expiddropnumber == expidsdrop) {
expidsdrop <- importdataloop[expiddropnumber, ]
}
if (length(expidsdrop) == "1") {
cat("Dropping unused identifiers\n")
cat("\n")
fullloop <- fullloop[, -which(names(fullloop) %in% c(expidsdrop))]
importdataloop <- as.data.frame(colnames(fullloop), stringsAsFactors = FALSE,
header = TRUE)
colnames(importdataloop) <- c("EXPERIMENT")
print(importdataloop)
cat("\n")
expidsdrop <- NULL
}
}
check <- askYesNo("Does this display only a single transcript identifier and the sample ids? ")
if (check == TRUE) {
coldata <- importdataloop
full <- fullloop
expids <- expidnumber
print(head(tximportcounts[expidnumber], 3))
break
}
}
} else if (removecols == 0) {
coldata <- fullimportdata
full <- mergedexp_2
expids <- expidnumber
print(head(full[expidnumber], 3))
}
txhasversions <- askYesNo("Do your TRANCRIPT IDs have decimal versions? (eg. ENST00000342771.9)? ")
if (txhasversions == TRUE) {
full[, 1] <- gsub("\\..*", "", full[, 1])
txhasversions <- FALSE
}
cat("\n")
cat("Expression Matrix Imported\n")
cat("\n")
print(head(full[expidnumber], 3))
cat("\n")
# cat('When you're prompted for a CHIP file, instead provide a table mapping
# Transcript IDs to Gene Symbols and Descriptions USING CHIP HEADERS. Good
# Luck.\n') readline(prompt=('Press enter to continue...')) #Implement merge
# with tx2gene.
}}
# Add tx2gene mapper HERE
full <- merge(x = tx2gene, y = full, by.x = "TXNAME", by.y = "TXNAME")
full <- full[, -1]
full <- distinct(full)
full <- full %>% group_by(GENEID) %>% summarise_all(sum) %>% data.frame()
expids <- "GENEID"
}
if (txlevel == FALSE) {
if (iscounts != TRUE) {
iscounts <- askYesNo("Is your dataset gene level COUNTS measurements from HTSeq-counts, FeatureCounts, or similar? ")
if (iscounts == TRUE) {
TYPE <- "COUNTS"
if (isnormalized == FALSE) {
isnormalized <- askYesNo("Are your counts already normalized? ")
if (isnormalized == TRUE) {
NORM <- TRUE
DESEQ2DONE <- FALSE
}
if (isnormalized == FALSE) {
NORM <- FALSE
}
} else if (isnormalized == TRUE) {
NORM <- TRUE
DESEQ2DONE <- FALSE
}
} else if (iscounts == FALSE) {
cat("Your dataset is not supported at this time.\n")
FAIL <- TRUE
}
}
}
if (FAIL == TRUE) {
stop("An unsupported datatype was encountered and processing was terminated.")
}
# Import Gene Expression Matrix ##GEO conditional Needed for genematrix prompt
if (txlevel == FALSE) {
if (getgeofiles == FALSE) {
genematrix <- readline(prompt = ("Drop Gene Expression Matrix into R Window or Enter File Path (supports csv or tab delimited txt): "))
}
library("tools")
genematrixtype <- file_ext(gsub(".gz$", "", genematrix))
if (genematrixtype == "csv") {
full <- read.table(genematrix, sep = ",", header = T, row.names = NULL, comment.char = "")
if (colnames(full)[1] == "X") {
colnames(full)[1] <- "ID"
}
if (colnames(full)[1] == "row.names") {
colnames(full)[1] <- "ID"
}
cat("\n")
cat("Expression Matrix Imported\n")
cat("\n")
print(head(full, 3))
cat("\n")
}
if (genematrixtype == "txt" | genematrixtype == "tabular" | genematrixtype ==
"tsv" | genematrixtype == "tab") {
full <- read.table(genematrix, sep = "\t", header = T, row.names = NULL, comment.char = "")
if (colnames(full)[1] == "X") {
colnames(full)[1] <- "ID"
}
if (colnames(full)[1] == "row.names") {
colnames(full)[1] <- "ID"
}
cat("\n")
cat("Expression Matrix Imported\n")
cat("\n")
print(head(full, 3))
cat("\n")
}
if ((genematrixtype == "") == TRUE) {
is_directory <- TRUE
message("Directory detected. This directory must contain ONLY samples to be imported\n")
cat("Attempting to parse multiple individually quantified samples into single matrix...\n")
inputsamples <- list.files(genematrix)
inputsamplestxt <- list.files(genematrix, pattern = ".txt|.tsv|.tabular|.tab")
txtsamplenumber <- length(inputsamplestxt)
inputsamplescsv <- list.files(genematrix, pattern = ".csv")
csvsamplenumber <- length(inputsamplescsv)
totalsamplenumber <- txtsamplenumber + csvsamplenumber
if (txtsamplenumber > 0) {
print(inputsamplestxt)
cat(paste(txtsamplenumber), "tabular formatted samples were detected in input directory.\n")
txtsamplepaths <- file.path(genematrix, inputsamplestxt)
names(txtsamplepaths) <- paste0(inputsamplestxt)
import_txt <- lapply(txtsamplepaths, read.table, header = FALSE, row.names = NULL,
sep = "\t", stringsAsFactors = FALSE, comment.char = "")
for (i in 1:txtsamplenumber) {
do
colnames(import_txt[[i]]) <- paste(inputsamplestxt[i], colnames(import_txt[[i]]),
sep = "_")
}
}
if (csvsamplenumber > 0) {
print(inputsamplescsv)
cat(paste(csvsamplenumber), "csv formatted samples were detected in input directory.\n")
csvsamplepaths <- file.path(genematrix, inputsamplescsv)
names(csvsamplepaths) <- paste0(inputsamplescsv)
import_csv <- lapply(csvsamplepaths, read.table, header = FALSE, row.names = NULL,
sep = ",", stringsAsFactors = FALSE, comment.char = "")
for (i in 1:csvsamplenumber) {
do
colnames(import_csv[[i]]) <- paste(inputsamplestxt[i], colnames(import_csv[[i]]),
sep = "_")
}
}
if ((txtsamplenumber > 0) == (csvsamplenumber > 0)) {
import.list <- append(import_txt, import_csv) #combine csv and txt imports
cat(paste(length(import.list)), "total samples were detected in input directory.\n")
} else if (csvsamplenumber == 0) {
import.list <- import_txt #process txt only
} else if (txtsamplenumber == 0) {
import.list <- import_csv #process csv only
}
keep <- askYesNo("Are all of the quantifications from the same pipeline? ")
if (keep == FALSE) {
list <- list(NA)
for (i in 1:length(names(import.list))) {
do
cat("\n")
cat("Sample: ", paste0(names(import.list[i])), "\n")
value <- askYesNo("Include in analysis? ")
if (value == TRUE) {
list[[1]][i] <- names(import.list[i])
}
}
list <- list[[1]][!is.na(list[[1]])]
import.list <- import.list[list]
}
importdata <- as.data.frame(colnames(import.list[[1]]), stringsAsFactors = FALSE,
header = FALSE)
colnames(importdata)[1] <- "EXPERIMENT"
cat("\n")
displayexp <- merge(x = importdata, y = t(import.list[[1]][c(1:3, 11:13),
]), by.x = 1, by.y = 0)
print(displayexp)
cat("\n")
cat("Selected a sample to use for learning dataset format: \n")
cat("\n")
rebuildheader <- askYesNo("Is there a more descriptive header than the one in the \"EXPERIMENT\" column? ")
if (rebuildheader == TRUE) {
cat("\n")
print(displayexp[2:4])
headnum <- as.numeric(readline(prompt = ("Enter the COLUMN NUMBER above that you want to use as the descriptors: ")))
importlist2 <- lapply(import.list, function(x) {
colnames(x) = x[headnum, ]
x = x[-headnum, ]
})
import.list <- importlist2
}
expids <- readline(prompt = ("Enter the name from the EXPERIMENT column or row number above that defines your gene identifiers: "))
expidnumber <- match(expids, cbind(rownames(importdata), importdata)[, 1])
if (is.na(expidnumber) == TRUE) {
expidnumber <- match(expids, cbind(rownames(importdata), importdata)[,2])
expids <- expidnumber
}
mergedexp <- Reduce(function(x, y) merge(x, y, all = FALSE, by = expidnumber,
all.x = TRUE, all.y = TRUE), import.list, accumulate = F)
colnames(mergedexp)[expidnumber] <- "GENEID"
mergedexp_2 <- mergedexp
colnames(mergedexp_2) <- make.unique(colnames(mergedexp_2))
# Disabled autocleanup - causes issues with too many formats. mergedexp %>%
# select_if(is.numeric) -> mergedexp_2 mergedexp_2 <-
# cbind(mergedexp[expidnumber], mergedexp_2) mergedexp_2 <- mergedexp_2[,
# -grep('ength$', colnames(mergedexp_2))] cat('Cleaned up identifiable extraneous
# non-numeric columns.\n')
fullimportdata <- as.data.frame(colnames(mergedexp_2), stringsAsFactors = FALSE,
header = TRUE)
colnames(fullimportdata)[1] <- "EXPERIMENT"
displayfullexp <- merge(x = fullimportdata, y = t(mergedexp_2[c(1:3, 11:13),
]), by.x = 1, by.y = 0)
print(displayfullexp)
cat("There are", paste(length(colnames(mergedexp_2))), "entries in the Experiment data matrix.\n")
keepcols <- readline(prompt = ("How many are gene quantifications? (this should be one per sample): "))
removecols <- as.numeric(length(colnames(mergedexp_2))) - (1 + as.numeric(keepcols))
if (removecols > 0) {
repeat {
importdataloop <- fullimportdata
colnames(importdataloop) <- c("EXPERIMENT")
fullloop <- mergedexp_2
print(importdataloop)
for (i in 1:as.numeric(removecols)) {
do
message("Discard everything except your Gene IDs and your per sample quantifications. \n")
expidsdrop <- readline(prompt = ("Enter a name or row number from the EXPERIMENT column above that defines fields you want to DISCARD: "))
expiddropnumber <- match(expidsdrop, cbind(rownames(importdataloop),
importdataloop)[, 1])
if (is.na(expiddropnumber) == TRUE) {
expiddropnumber <- FALSE
}
if (expiddropnumber == expidsdrop) {
expidsdrop <- importdataloop[expiddropnumber, ]
}
if (length(expidsdrop) == "1") {
cat("Dropping unused identifiers\n")
cat("\n")
fullloop <- fullloop[, -which(names(fullloop) %in% c(expidsdrop))]
importdataloop <- as.data.frame(colnames(fullloop), stringsAsFactors = FALSE,
header = TRUE)
colnames(importdataloop) <- c("EXPERIMENT")
print(importdataloop)
cat("\n")
expidsdrop <- NULL
}
}
check <- askYesNo("Does this display only a single gene identifier and the sample ids? ")
if (check == TRUE) {
coldata <- importdataloop
full2 <- fullloop
expids <- expidnumber
displayframe <- as.data.frame(full2[expidnumber][c(1:3, 11:13),
])
colnames(displayframe) <- c("GENEID")
print(displayframe)
break
}
}
} else if (removecols == 0) {
coldata <- fullimportdata
full2 <- mergedexp_2
expids <- expidnumber
displayframe <- as.data.frame(full2[expidnumber][c(1:3, 11:13), ])
colnames(displayframe) <- c("GENEID")
print(displayframe)
}
genehasversions <- askYesNo("Do your GENE IDs have decimal versions? (eg. ENSG00000158321.16)? ")
if (genehasversions == TRUE) {
full2[, 1] <- gsub("\\..*", "", full2[, 1])
genehasversions <- FALSE
}
cat("\n")
cat("Expression Matrix Imported\n")
cat("\n")
displayframe <- as.data.frame(full2[expidnumber][c(1:3, 11:13), ])
colnames(displayframe) <- c("GENEID")
print(displayframe)
cat("\n")
expids <- colnames(full2)[expids]
}
}
if ((txlevel == FALSE | TYPE == "RSEM") == (is_directory == FALSE)) {
cat("There are", paste(length(colnames(full))), "columns in your data table.\n")
samplesize <- readline(prompt = ("How many of these are sequenced SAMPLES? "))
expids <- (length(colnames(full)) - as.numeric(samplesize))
repeat {
if (expids == "1") {
# Prompt User for Original Experiment Namespace to Merge with CHIP On
message("Gene Expression File Header:\n")
cat("\n")
coldata <- as.data.frame(colnames(full), stringsAsFactors = FALSE, header = FALSE)
colnames(coldata) <- c("EXPERIMENT")
print(as.data.frame(coldata))
cat("\n")
expids <- readline(prompt = ("Enter the name from the EXPERIMENT column or row number above that defines your gene identifiers: "))
expidnumber <- match(expids, cbind(rownames(coldata), coldata)[, 1])
if (is.na(expidnumber) == TRUE) {
expidnumber <- FALSE
}
if (expidnumber == expids) {
expids <- coldata[expidnumber, ]
}
# FIX ENSG_SYMBOL MERGE
if (txlevel == FALSE) {
if (all((grepl("_", full[, expids], fixed = TRUE))) == TRUE & length(grepl("NM_", full[, expids], fixed = TRUE)[grepl("NM_", full[, expids], fixed = TRUE)==TRUE])<1000) {
readline(prompt = ("This step requires the CRAN package \"tidyr\". Make sure it is installed, then press enter to continue..."))
library("tidyr")
splitids <- as.data.frame(full[,expids])
splitnames <- separate(splitids, 1, c("ID_1", "ID_2"), sep = "_", remove = TRUE, extra = "warn", fixed=TRUE)
head(splitnames)
print(head(splitnames,3))
cat("\n")
keepid <- menu(c("ID_1","ID_2"), title="Which ID do you want to keep?")
full[,expids] <- splitnames[,keepid]
colnames(full)[1] <- "GENEID"
expids <- "GENEID"
}
if (all((grepl("|", full[, expids], fixed = TRUE))) == TRUE){
readline(prompt = ("This step requires the CRAN package \"tidyr\". Make sure it is installed, then press enter to continue..."))
library("tidyr")
splitids <- as.data.frame(full[,expids])
splitnames <- separate(splitids, 1, c("ID_1", "ID_2"), sep = "\\|", remove = TRUE, extra = "warn", fixed=TRUE)
print(head(splitnames,3))
cat("\n")
keepid <- menu(c("ID_1","ID_2"), title="Which ID do you want to keep?")
full[,expids] <- splitnames[,keepid]
colnames(full)[1] <- "GENEID"
expids <- "GENEID"
}
}
full2 <- full
cat("Gene IDs:\n")
print(head(full2[, expids], 3))
if (txlevel == FALSE) {
genehasversions <- askYesNo("Do your GENE IDs have decimal versions? (eg. ENSG00000158321.16)? ")
if (genehasversions == TRUE) {
full2[, 1] <- gsub("\\..*", "", full2[, 1])
genehasversions <- FALSE
}
}
coldata <- as.data.frame(colnames(full2), stringsAsFactors = FALSE, header = TRUE)
colnames(coldata) <- c("EXPERIMENT")
break
} else if (expids > "1") {
fullloop <- full
# Prompt User for Original Experiment Namespace to Merge with CHIP On
cat("Gene Expression File Header:\n")
cat("\n")
coldata <- as.data.frame(colnames(full), stringsAsFactors = FALSE, header = FALSE)
colnames(coldata) <- c("EXPERIMENT")
print(as.data.frame(coldata))
cat("\n")
message("We now need to pick one set of identifiers to use for downstream processing, and prune away the others one at a time.\n")
message("For example, if you have both ENSEMBL Gene IDs and Gene Symbols columns KEEP the ENSEMBL IDs and DISCARD the Gene Symbols\n")
cat("\n")
expids <- readline(prompt = ("Enter the name from the EXPERIMENT column or row number above that defines the gene identifiers you want to KEEP: "))
expidnumber <- match(expids, cbind(rownames(coldata), coldata)[, 1])
if (is.na(expidnumber) == TRUE) {
expidnumber <- FALSE
}
if (expidnumber == expids) {
expids <- coldata[expidnumber, ]