News:

:) Please keep your software updated for best results!

Main Menu

Reading K-raws for duplicate elements

Started by Ben Buse, August 07, 2024, 05:14:40 AM

Previous topic - Next topic

Ben Buse

Just sharing this R code in case useful, it extracts the K-raws from the .wt files, prompting you to select file after file



library(rstudioapi)
library(svDialogs)
setwd(selectDirectory())
NumberofSamples<-as.numeric(dlgInput("Enter number of samples")$res)
NumberofElements<-as.numeric(dlgInput("Enter number of Elements")$res)
StoreKraws<-data.frame(matrix(NA,NumberofSamples,NumberofElements))
for(i in 1:NumberofSamples){
  QuantResult<-read.table(selectFile(path=getwd()),header=FALSE,sep="",fill=TRUE)
  for(ii in 1:NumberofElements){
    El1<-which(QuantResult[,1]==ii)
    rowdecimals<-str_extract(QuantResult[El1,],".*[0-9]\\...[0-9]")
    rowdecimals<-rowdecimals[!is.na(rowdecimals)]
    ExtractedKraw<-rowdecimals[length(rowdecimals)]
    StoreKraws[i,ii]<-ExtractedKraw
  }
}
write.csv(StoreKraws,file=file.path(getwd(),"RStudio_Extract_Kraws.csv"))



Columns are elements and rows are samples


Ben Buse

#1
And a slight modification to read X number of files within a 000X QNT folder. For example if 0011QNT contains 6 files (6 points), then can read from point 1 to point X (as specified)

library(rstudioapi)
library(svDialogs)
setwd(selectDirectory(caption="Select 0000 QNT folder"))
NumberofSamples<-as.numeric(dlgInput("Enter number of samples")$res)
NumberofElements<-as.numeric(dlgInput("Enter number of Elements")$res)
StoreKraws<-data.frame(matrix(NA,NumberofSamples,NumberofElements))
for(i in 1:NumberofSamples){
  QuantResult<-read.table(paste(getwd(),"/Pos_",stri_pad(i,4,pad="0"),"/1.wt",sep=""),header=FALSE,sep="",fill=TRUE)
  for(ii in 1:NumberofElements){
    El1<-which(QuantResult[,1]==ii)
    rowdecimals<-str_extract(QuantResult[El1,],".*[0-9]\\...[0-9]")
    rowdecimals<-rowdecimals[!is.na(rowdecimals)]
    ExtractedKraw<-rowdecimals[length(rowdecimals)]
    StoreKraws[i,ii]<-ExtractedKraw
  }
}
write.csv(StoreKraws,file=file.path(getwd(),"RStudio_Extract_Kraws_Points.csv"))