annotate merge.r @ 0:8a5a2abbb870 draft default tip

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