annotate new_imgt.r @ 90:6809c63d9161 draft

"planemo upload commit fd64827ff6e63df008f6f50ddb8576ad2b1dbb26"
author rhpvorderman
date Tue, 25 Jan 2022 11:28:29 +0000
parents b6f9a640e098
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
81
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
1 args <- commandArgs(trailingOnly = TRUE)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
2
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
3 imgt.dir = args[1]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
4 merged.file = args[2]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
5 gene = args[3]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
6
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
7 merged = read.table(merged.file, header=T, sep="\t", fill=T, stringsAsFactors=F, comment.char="", quote="")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
8
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
9 if(!("Sequence.ID" %in% names(merged))){ #change-o db
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
10 print("Change-O DB changing 'SEQUENCE_ID' to 'Sequence.ID'")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
11 names(merged)[which(names[merged] == "SEQUENCE_ID")] = "Sequence.ID"
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
12 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
13
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
14 if(gene != "-"){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
15 merged = merged[grepl(paste("^", gene, sep=""), merged$best_match),]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
16 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
17
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
18 if("best_match" %in% names(merged)){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
19 merged = merged[!grepl("unmatched", merged$best_match),]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
20 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
21
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
22 nrow_dat = 0
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
23
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
24 for(f in list.files(imgt.dir, pattern="*.txt$")){
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
25 #print(paste("filtering", f))
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
26 path = file.path(imgt.dir, f)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
27 dat = read.table(path, header=T, sep="\t", fill=T, quote="", stringsAsFactors=F, check.names=FALSE, comment.char="")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
28
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
29 dat = dat[dat[,"Sequence ID"] %in% merged$Sequence.ID,]
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
30
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
31 nrow_dat = nrow(dat)
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
32
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
33 if(nrow(dat) > 0 & grepl("^8_", f)){ #change the FR1 columns to 0 in the "8_..." file
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
34 dat[,grepl("^FR1", names(dat))] = 0
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
35 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
36
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
37 write.table(dat, path, quote=F, sep="\t", row.names=F, col.names=T, na="")
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
38 }
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
39
b6f9a640e098 Uploaded
davidvanzessen
parents:
diff changeset
40 print(paste("Creating new zip for ", gene, "with", nrow_dat, "sequences"))