annotate experimental_design/experimental_design.r @ 52:124b7fd92a3e draft

Uploaded
author davidvanzessen
date Thu, 25 Feb 2021 13:36:15 +0000
parents 106275b54470
children 81b3eb11ed2c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
52
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
1 args <- commandArgs(trailingOnly = TRUE)
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
2
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
3 print(args)
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
4
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
5 inputs = args[1:(length(args) - 1)]
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
6 output = args[length(args)]
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
7
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
8 current.id = ""
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
9 counter = 1
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
10
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
11 result = NULL
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
12
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
13 for(current in inputs){
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
14 if(grepl("/", current)){ #its a path to a file
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
15 print(paste("Adding file", counter, "to", current.id))
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
16 dat = read.table(current, sep="\t", header=T, quote="", fill=T)
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
17
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
18 if(nrow(dat) == 0){
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
19 print(paste(counter, "of", current.id, "has no sequences, skipping"))
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
20 next
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
21 }
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
22
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
23 #IMGT check
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
24
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
25 dat$Sample = current.id
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
26 dat$Replicate = counter
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
27
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
28 if(is.null(result)){
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
29 result = dat[NULL,]
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
30 }
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
31
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
32 result = rbind(result, dat)
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
33
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
34 counter = counter + 1
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
35
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
36 } else { #its an ID of a patient
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
37 print(paste("New patient", current))
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
38 current.id = current
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
39 counter = 1
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
40 }
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
41 }
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
42
124b7fd92a3e Uploaded
davidvanzessen
parents: 40
diff changeset
43 write.table(result, output, sep="\t", quote=F, row.names=F, col.names=T)