annotate new_imgt.r @ 43:77a7ac76c7b9 draft

Uploaded
author davidvanzessen
date Tue, 11 Apr 2017 08:02:17 -0400
parents fe44a905aee9
children 6cd12c71c3d3
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
31
fe44a905aee9 Uploaded
davidvanzessen
parents: 0
diff changeset
7 merged = read.table(merged.file, header=T, sep="\t", fill=T, stringsAsFactors=F, comment.char="")
0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
8
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
9 if(gene != "-"){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
10 merged = merged[grepl(paste("^", gene, sep=""), merged$best_match),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
11 } else {
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
12 merged = merged[!grepl("unmatched", merged$best_match),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
13 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
14
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
15 merged = merged[!grepl("unmatched", merged$best_match),]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
16
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
17 for(f in list.files(imgt.dir, pattern="*.txt$")){
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
18 #print(paste("filtering", f))
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
19 path = paste(imgt.dir, f, sep="")
31
fe44a905aee9 Uploaded
davidvanzessen
parents: 0
diff changeset
20 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
21
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
22 dat = dat[dat[,"Sequence ID"] %in% merged$Sequence.ID,]
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
23
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
24 if(nrow(dat) > 0 & grepl("^8_", f)){ #change the FR1 columns to 0 in the "8_..." file
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
25 dat[,grepl("^FR1", names(dat))] = 0
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
26 }
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
27
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
28 write.table(dat, path, quote=F, sep="\t", row.names=F, col.names=T, na="")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
29 }