annotate new_imgt.r @ 28:c0ecc31829bd draft

Uploaded
author davidvanzessen
date Wed, 07 Dec 2016 08:17:09 -0500
parents c33d93683a09
children fe44a905aee9
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
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
7 merged = read.table(merged.file, header=T, sep="\t", fill=T, stringsAsFactors=F)
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="")
c33d93683a09 Uploaded
davidvanzessen
parents:
diff changeset
20 dat = read.table(path, header=T, sep="\t", fill=T, quote="", stringsAsFactors=F, check.names=FALSE)
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 }