| 
0
 | 
     1 args <- commandArgs(trailingOnly = TRUE)
 | 
| 
 | 
     2 
 | 
| 
 | 
     3 input=args[1]
 | 
| 
 | 
     4 column=as.numeric(args[2])
 | 
| 
 | 
     5 header=(args[3] == "yes")
 | 
| 
2
 | 
     6 regex_filter=args[4]
 | 
| 
 | 
     7 out_file=args[5]
 | 
| 
 | 
     8 
 | 
| 
 | 
     9 print(regex_filter)
 | 
| 
0
 | 
    10 
 | 
| 
1
 | 
    11 dat = read.table(input, header=header, sep="\t", fill=T, stringsAsFactors=F, quote="")
 | 
| 
0
 | 
    12 
 | 
| 
2
 | 
    13 dat.names = names(dat)
 | 
| 
0
 | 
    14 
 | 
| 
2
 | 
    15 dat$filtered = gsub("\\(.*", "", dat[,column])
 | 
| 
 | 
    16 
 | 
| 
 | 
    17 duplicates = dat[duplicated(dat$filtered),"filtered"]
 | 
| 
0
 | 
    18 
 | 
| 
2
 | 
    19 dat = dat[dat[,"filtered"] %in% duplicates,]
 | 
| 
0
 | 
    20 
 | 
| 
2
 | 
    21 dat = dat[order(dat[,"filtered"]),]
 | 
| 
 | 
    22 
 | 
| 
 | 
    23 write.table(dat[,dat.names], out_file, sep="\t", row.names=F, col.names=header, quote=F)
 |