annotate merge.r @ 4:5ffd52fc35c4 draft

Uploaded
author davidvanzessen
date Mon, 12 Dec 2016 05:22:37 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
1 args <- commandArgs(trailingOnly = TRUE)
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
2
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
3 input.1 = args[1]
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
4 input.2 = args[2]
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
5
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
6 fields.1 = args[3]
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
7 fields.2 = args[4]
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
8
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
9 field.1 = args[5]
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
10 field.2 = args[6]
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
11
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
12 output = args[7]
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
13
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
14 dat1 = read.table(input.1, header=T, sep="\t", quote="", stringsAsFactors=F, fill=T, row.names=NULL)
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
15 if(fields.1 != "all"){
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
16 fields.1 = unlist(strsplit(fields.1, ","))
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
17 dat1 = dat1[,fields.1]
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
18 }
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
19 dat2 = read.table(input.2, header=T, sep="\t", quote="", stringsAsFactors=F, fill=T, row.names=NULL)
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
20 if(fields.2 != "all"){
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
21 fields.2 = unlist(strsplit(fields.2, ","))
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
22 dat2 = dat2[,fields.2]
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
23 }
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
24
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
25 dat3 = merge(dat1, dat2, by.x=field.1, by.y=field.2)
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
26
5ffd52fc35c4 Uploaded
davidvanzessen
parents:
diff changeset
27 write.table(dat3, output, sep="\t",quote=F,row.names=F,col.names=T)