annotate new_imgt.r @ 66:43a1aa648537 draft

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