Ticket #486: Illumina conversion.txt

File Illumina conversion.txt, 1.8 KB (added by base, 15 years ago)

R script to convert a multi-array Illumina .csv output file into multiple single-array files.

Line 
1# Set the wd:
2setwd("C:/BASE/Illumina imports/BeadStudio output")
3
4# Choose the file:
5filename <- "gene_profile.csv"
6
7#Set the number of arrays per chip:
8arraysPerChip = 8; # 6
9columnsPerArray = 8;
10
11# assign the column headers:
12headerColumnNames <-c("MIN_Signal","AVG_Signal","MAX_Signal","NARRAYS","ARRAY_STDEV","BEAD_STDEV","Avg_NBEADS","Detection"
13
14illumina <- read.csv(file=paste(getwd(),"/",filename,sep=""),skip=7,header=TRUE,row.name=1)
15
16ncol(illumina)
17nrow(illumina)
18
19numData = ncol(illumina) -
20numArrays = numData / columnsPerArray # 8 data columns per array
21numChips = numArrays/arraysPerChip  #
22
23numChips
24
25if numChips%%1 ~= 0
26  "ERROR: an incomplete chip is in this file!"
27
28colnames(illumina) -> myCols
29
30# Derive the Chip names from the colnames:
31# Format of first entry: "MIN_Signal.XXXXXXXXXX_A" ( 10 Xs: maybe different?)
32
33lenFirstData <-nchar(headerColumnNames[1])
34
35chipNums = NULL
36arrayNames = NULL
37
38# Derive names of arrays:
39for (k in 1:numChips){
40   
41  # Get the numbers of the chips:
42colNum = 1 + (k-1)* (arraysPerChip *columnsPerArray)
43chipNums = c(chipNums, substr(myCols [colNum],lenFirstData+2,nchar(myCols[colNum])-2))
44
45  # Get names of all the arrays
46  labels = c("A","B","C","D","E","F","G","H")
47  labels = labels[1: arraysPerChip]
48  arrayNames = c(arrayNames, paste(chipNums[k],labels,sep="_"))
49}
50chipNums
51arrayNames
52
53
54# output arrays (groups of columnsPerArray columns, plus gene names)
55for (k in 1:length(arrayNames))
56{
57  outputCols <- c(1: columnsPerArray) + columnsPerArray * (k-1)
58  outputData <- illumina[,outputCols]
59  outputData <- cbind(rownames(illumina),outputData)
60
61  colnames(outputData) <- as.character(c("TargetID",headerColumnNames))
62
63  write.table(outputData,file = paste(arrayNames[k],".txt",sep=""),sep = "\t",row.names=FALSE,na="")
64}