annotate check_unique_id.r @ 69:fefaaa19f30b draft

Uploaded
author davidvanzessen
date Tue, 29 Jan 2019 07:33:58 -0500
parents cb779a45537b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
56
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
1 args <- commandArgs(trailingOnly = TRUE) #first argument must be the summary file so it can grab the
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
2
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
3 current_file = args[1]
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
4
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
5 current = read.table(current_file, header=T, sep="\t", fill=T, stringsAsFactors=F, quote="", check.names=F)
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
6
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
7 if(!("Sequence number" %in% names(current))){
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
8 stop("First argument doesn't contain the 'Sequence number' column")
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
9 }
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
10
57
cb779a45537b Uploaded
davidvanzessen
parents: 56
diff changeset
11 tbl = table(current[,"Sequence ID"])
56
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
12 l_tbl = length(tbl)
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
13 check = any(tbl > 1)
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
14
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
15 #if(l_tbl != nrow(current)){ # non unique IDs?
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
16 if(check){
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
17 print("Sequence.ID is not unique for every sequence, adding sequence number to IDs")
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
18 for(i in 1:length(args)){
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
19 current_file = args[i]
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
20 print(paste("Appending 'Sequence number' column to 'Sequence ID' column in", current_file))
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
21 current = read.table(current_file, header=T, sep="\t", fill=T, stringsAsFactors=F, quote="", check.names=F)
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
22 current[,"Sequence ID"] = paste(current[,"Sequence ID"], current[,"Sequence number"], sep="_")
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
23 write.table(x = current, file = current_file, quote = F, sep = "\t", na = "", row.names = F, col.names = T)
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
24 }
ee807645b224 Uploaded
davidvanzessen
parents:
diff changeset
25 }