comparison check_unique_id.r @ 81:b6f9a640e098 draft

Uploaded
author davidvanzessen
date Fri, 19 Feb 2021 15:10:54 +0000
parents
children
comparison
equal deleted inserted replaced
80:a4617f1d1d89 81:b6f9a640e098
1 args <- commandArgs(trailingOnly = TRUE) #first argument must be the summary file so it can grab the
2
3 current_file = args[1]
4
5 current = read.table(current_file, header=T, sep="\t", fill=T, stringsAsFactors=F, quote="", check.names=F)
6
7 if(!("Sequence number" %in% names(current))){
8 stop("First argument doesn't contain the 'Sequence number' column")
9 }
10
11 tbl = table(current[,"Sequence ID"])
12 l_tbl = length(tbl)
13 check = any(tbl > 1)
14
15 #if(l_tbl != nrow(current)){ # non unique IDs?
16 if(check){
17 print("Sequence.ID is not unique for every sequence, adding sequence number to IDs")
18 for(i in 1:length(args)){
19 current_file = args[i]
20 print(paste("Appending 'Sequence number' column to 'Sequence ID' column in", current_file))
21 current = read.table(current_file, header=T, sep="\t", fill=T, stringsAsFactors=F, quote="", check.names=F)
22 current[,"Sequence ID"] = paste(current[,"Sequence ID"], current[,"Sequence number"], sep="_")
23 write.table(x = current, file = current_file, quote = F, sep = "\t", na = "", row.names = F, col.names = T)
24 }
25 }