---
# System prepended metadata

title: 2.1. BWAlignment.R
tags: [Source]

---

---
tags: Source
---
# 2.1. BWAlignment.R


# Summary:
# This scripts performs retention time adjustment for multiple bandwidth values
# It uses ObiWarp method

# Inputs:
# Peak picking location
filename_in <- ""
filepath_in <- ""
# example: seq(0.4,2.6,by=0.2), seq(3,5,by=0.5), seq(5,10,by=2)
bw_array <- c()
# TODO: move the PeakDensity and Obiwarp parameters here, but maybe as structs?


# Outputs:
filename_out <- ""
filepath_out <- ""


# Before in pipeline:
# - PeakPicking.R


# Next in pipeline:
# - 


for (bw in bwarray){
    xdata <- readRDS(file=paste(filepath_in, filename_in, sep = ""))
    pdp_pregroup <- PeakDensityParam(sampleGroups = xdata$sample_group, minFraction = 0.95, bw = bw, binSize = 0.924)
    xdata <- groupChromPeaks(xdata, param = pdp_pregroup)
    pgp <- ObiwarpParam(binSize = 0.924, response = 17.65, distFun = "cor_opt",
                        gapInit = 0.64, gapExtend = 2.82, factorDiag = 2, factorGap = 1, localAlignment = FALSE)
    #binSize corresponts to IPO's profStep
    xdata <- adjustRtime(xdata, param = pgp)
    jpeg(paste(filepath_out, filename_out, "_bw", bw, ".jpg", sep = ""))
    plotAdjustedRtime(xdata)
    dev.off()
    saveRDS(xdata, file=paste(filepath_out, filename_out, "_bw", bw, "_algn.rds", sep = ""))
    rm(xdata)
    print(paste("\nDone bw= ",bw))
}
