#!/usr/bin/env Rscript
args = commandArgs(trailingOnly=TRUE)
print(args)

t1 <- as.data.frame(read.table(args[1]))  #load the names of ALL the reads
t2 <- as.data.frame(read.table(args[2]))  #load the repeatmasker cluster and read association, FIRST column

df <- merge(t1, t2, by.x=c("V1"), by.y=c("V1"), all.x=TRUE) #merge by the read id

stopifnot(length(rownames(t1))==length(rownames(df))) #we want to see all reads in an output, either with a cluster assignment or without

write.table(df, file = "read_cluster_association.tab", sep = "\t", row.names = FALSE, col.names = FALSE, quote = FALSE)
#join -1 2 -2 1 -e 'NA' ${renamedReads}.sorted cluster_read_mapping.tab.sorted
