modified: pixi.toml
[GalaxyCodeBases.git] / R / FGI / 2021triUni / do.r
blob66b4e2e6d1ddf6e958bc9132e9b03aba4ede5060
1 #!/usr/bin/env littler
3 require(readxl)
4 require(tibble)
6 # 设置数值显示位数
7 options(scipen = 200)
9 argv <- if (!exists("argv")) commandArgs(TRUE) else as.character(argv)
10 fpath <- argv[1]
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))
19 return(rdat)
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)
30 readXLS(NFOname)
31 readXLS(HLAname)
32 readXLS(SNPname)
33 reads <- sapply(c(NFOname,HLAname,SNPname),readXLS,USE.NAMES=F)
34 print(reads)
35 return(c(fnGot,'---'))
38 if (dir.exists(fpath)) {
39 flist <- list.dirs(fpath,full.names=FALSE,recursive=FALSE)
40 #print(flist)
41 ret <- sapply(flist,analyze)
42 print(ret)
43 } else {
44 cat(paste("[!]Usage: ./do.r <path>\n"))