9 argv
<- if (!exists("argv")) commandArgs(TRUE) else as
.character(argv
)
11 fpattern
<- "(NFO|HLA|SNP|MED).xlsx?$"
13 readXLS
<- function(xlsname
) {
14 read
<- read_excel(xlsname
,col_types
="text",col_names
=FALSE,.name_repair
= ~ LETTERS
[seq_along(.x
)])
15 tres
<- regexpr('(?<Type>\\w{3}).xls',xlsname
,perl
=TRUE)
16 st
<- attr(tres
, "capture.start")[1, ]
17 tstr
<- toupper(substring(xlsname
,st
,st
+ attr(tres
, "capture.length")[1, ] -1))
18 rdat
<- as
.data
.frame(t(column_to_rownames(read
,var
='A')),row
.names
=make
.names(rep_len(tstr
,length(read
)-1),unique
=TRUE))
22 analyze
<- function(dirname
) {
23 #print(c('Fa',dirname))
24 fnames
<- list
.files(file
.path(fpath
,dirname
),pattern
=fpattern
,ignore
.case
=TRUE,full
.names
=TRUE)
25 NFOname
<- fnames
[grep('NFO.xls',fnames
,ignore
.case
=TRUE)[1]]
26 HLAname
<- fnames
[grep('HLA.xls',fnames
,ignore
.case
=TRUE)[1]]
27 SNPname
<- fnames
[grep('SNP.xls',fnames
,ignore
.case
=TRUE)[1]]
28 MEDname
<- fnames
[grep('MED.xls',fnames
,ignore
.case
=TRUE)[1]]
29 fnGot
<- paste0(dirname
,':N=',NFOname
,',S=',SNPname
,',H=',HLAname
,',M=',MEDname
)
33 reads
<- sapply(c(NFOname
,HLAname
,SNPname
),readXLS
,USE
.NAMES
=F)
35 return(c(fnGot
,'---'))
38 if (dir
.exists(fpath
)) {
39 flist
<- list
.dirs(fpath
,full
.names
=FALSE,recursive
=FALSE)
41 ret
<- sapply(flist
,analyze
)
44 cat(paste("[!]Usage: ./do.r <path>\n"))