Working_directory ="T:\\TimelapseData\\201029GA14" setwd(Working_directory) require(EBImage) csv_raw = read.table("allquant.csv", header = TRUE, sep = ",") csv_raw = csv_raw[which(csv_raw$TimePoint==2),] csv_raw= as.data.frame(csv_raw) # get position folders in directory all.files <- list.files(rec=F) foldersInDIR = all.files[file.info(all.files)$isdir] # get the valid position folders positionFolders = grep('_p', foldersInDIR, value=TRUE) # for each position folder for (posFolder in positionFolders) { print(posFolder) # get the position id posID = as.numeric(strsplit(posFolder,"_p")[[1]][2]) cellsInPositionDF = subset(csv_raw, Position==posID ) # get the info about this position # load the image on which to plot the clusterID if (nrow(cellsInPositionDF)>0){ setwd(paste(posFolder, sep = "\\")) imgFilename = paste(posFolder, "_t00001_z001_w04.png", sep = "") imgFilenameOut = paste(posFolder,"_t00001_z001_w05.png", sep = "") img = readImage(imgFilename) imgEnhanced = img * 2000 h<-dim(img)[1] w<-dim(img)[2] png(imgFilenameOut, width=w, height=h) display(img, method="raster") for (i in 1:length(rownames(cellsInPositionDF))) { Xcoord = as.numeric(as.character(cellsInPositionDF$SeedX[i])) Ycoord = as.numeric(as.character(cellsInPositionDF$SeedY[i])) ClusterID = paste(cellsInPositionDF$M1[i],cellsInPositionDF$mCh[i],sep="") #add cluster id on the image text(x = Xcoord, y = Ycoord, label = ClusterID, col = "white", cex = 2) } #close image dev.off() Working_directory ="T:\\TimelapseData\\200616GA13" setwd(Working_directory) } }