| 
0
 | 
     1 args <- commandArgs(trailingOnly = TRUE)
 | 
| 
 | 
     2 
 | 
| 
 | 
     3 imgt.dir = args[1]
 | 
| 
 | 
     4 merged.file = args[2]
 | 
| 
 | 
     5 gene = args[3]
 | 
| 
 | 
     6 
 | 
| 
31
 | 
     7 merged = read.table(merged.file, header=T, sep="\t", fill=T, stringsAsFactors=F, comment.char="")
 | 
| 
0
 | 
     8 
 | 
| 
 | 
     9 if(gene != "-"){
 | 
| 
 | 
    10 	merged = merged[grepl(paste("^", gene, sep=""), merged$best_match),]
 | 
| 
55
 | 
    11 }
 | 
| 
 | 
    12 
 | 
| 
 | 
    13 if("best_match" %in% names(merged)){
 | 
| 
0
 | 
    14 	merged = merged[!grepl("unmatched", merged$best_match),]
 | 
| 
 | 
    15 }
 | 
| 
 | 
    16 
 | 
| 
57
 | 
    17 nrow_dat = 0
 | 
| 
 | 
    18 
 | 
| 
0
 | 
    19 for(f in list.files(imgt.dir, pattern="*.txt$")){
 | 
| 
 | 
    20 	#print(paste("filtering", f))
 | 
| 
55
 | 
    21 	path = file.path(imgt.dir, f)
 | 
| 
31
 | 
    22 	dat = read.table(path, header=T, sep="\t", fill=T, quote="", stringsAsFactors=F, check.names=FALSE, comment.char="")
 | 
| 
0
 | 
    23 	
 | 
| 
 | 
    24 	dat = dat[dat[,"Sequence ID"] %in% merged$Sequence.ID,]
 | 
| 
 | 
    25 	
 | 
| 
57
 | 
    26 	nrow_dat = nrow(dat)
 | 
| 
 | 
    27 	
 | 
| 
0
 | 
    28 	if(nrow(dat) > 0 & grepl("^8_", f)){ #change the FR1 columns to 0 in the "8_..." file
 | 
| 
 | 
    29 		dat[,grepl("^FR1", names(dat))] = 0
 | 
| 
 | 
    30 	}
 | 
| 
 | 
    31 	
 | 
| 
 | 
    32 	write.table(dat, path, quote=F, sep="\t", row.names=F, col.names=T, na="")
 | 
| 
 | 
    33 }
 | 
| 
57
 | 
    34 
 | 
| 
 | 
    35 print(paste("Creating new zip for ", gene, "with", nrow_dat, "sequences"))
 |