annotate new_imgt.r @ 0:8a5a2abbb870 draft default tip

Uploaded
author davidvanzessen
date Mon, 29 Aug 2016 05:36:10 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
1 args <- commandArgs(trailingOnly = TRUE)
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
2
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
3 imgt.dir = args[1]
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
4 merged.file = args[2]
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
5 gene = args[3]
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
6
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
7 merged = read.table(merged.file, header=T, sep="\t", fill=T, stringsAsFactors=F)
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
8
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
9 if(gene != "-"){
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
10 merged = merged[grepl(gene, merged$best_match),]
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
11 }
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
12
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
13 merged = merged[!grepl("unmatched", merged$best_match),]
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
14
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
15 for(f in list.files(imgt.dir, pattern="*.txt$")){
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
16 #print(paste("filtering", f))
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
17 path = paste(imgt.dir, f, sep="")
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
18 dat = read.table(path, header=T, sep="\t", fill=T, quote="", stringsAsFactors=F, check.names=FALSE)
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
19
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
20 dat = dat[dat[,"Sequence ID"] %in% merged$Sequence.ID,]
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
21
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
22 if(nrow(dat) > 0 & grepl("^8_", f)){ #change the FR1 columns to 0 in the "8_..." file
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
23 dat[,grepl("^FR1", names(dat))] = 0
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
24 }
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
25
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
26 write.table(dat, path, quote=F, sep="\t", row.names=F, col.names=T, na="")
8a5a2abbb870 Uploaded
davidvanzessen
parents:
diff changeset
27 }