Mercurial > repos > rhpvorderman > shm_csr
diff new_imgt.r @ 0:64d74ba01a7c draft
"planemo upload commit 78d1fae87dbcf490e49a9f99e7a06de7328e16d4"
| author | rhpvorderman |
|---|---|
| date | Wed, 27 Oct 2021 12:34:47 +0000 |
| parents | |
| children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/new_imgt.r Wed Oct 27 12:34:47 2021 +0000 @@ -0,0 +1,40 @@ +args <- commandArgs(trailingOnly = TRUE) + +imgt.dir = args[1] +merged.file = args[2] +gene = args[3] + +merged = read.table(merged.file, header=T, sep="\t", fill=T, stringsAsFactors=F, comment.char="", quote="") + +if(!("Sequence.ID" %in% names(merged))){ #change-o db + print("Change-O DB changing 'SEQUENCE_ID' to 'Sequence.ID'") + names(merged)[which(names[merged] == "SEQUENCE_ID")] = "Sequence.ID" +} + +if(gene != "-"){ + merged = merged[grepl(paste("^", gene, sep=""), merged$best_match),] +} + +if("best_match" %in% names(merged)){ + merged = merged[!grepl("unmatched", merged$best_match),] +} + +nrow_dat = 0 + +for(f in list.files(imgt.dir, pattern="*.txt$")){ + #print(paste("filtering", f)) + path = file.path(imgt.dir, f) + dat = read.table(path, header=T, sep="\t", fill=T, quote="", stringsAsFactors=F, check.names=FALSE, comment.char="") + + dat = dat[dat[,"Sequence ID"] %in% merged$Sequence.ID,] + + nrow_dat = nrow(dat) + + if(nrow(dat) > 0 & grepl("^8_", f)){ #change the FR1 columns to 0 in the "8_..." file + dat[,grepl("^FR1", names(dat))] = 0 + } + + write.table(dat, path, quote=F, sep="\t", row.names=F, col.names=T, na="") +} + +print(paste("Creating new zip for ", gene, "with", nrow_dat, "sequences"))
