#!/usr/bin/env Rscript

root.dir <- rprojroot::find_rstudio_root_file()
setwd(root.dir)

# 1. Scalability benchmark of satuRn

## 1.1. Source the satuRn method file
source("./Scalability_benchmark/DTU_methods/apply_satuRn.R")

## 1.2. Source the first configuration file (specifies #cells and #transcripts in data)
source("./Scalability_benchmark/Configuration/configFile_1.R")

## 1.3. Perform the scalability analysis on the first configuration file

satuRn_1 <- list()
round = 0
invisible(gc())

for (i in L$groupSizes){
	for (j in L$transcripts_amount){
                round = round + 1
		print(paste("Two groups of", i, "cells each with", j, "transcripts"))
		run_satuRn(L, countData, tx2gene) #function outputs the object result
		satuRn_1[round] <- list(result) # runtimes stored in a list

		print(paste0("Runtime (elapsed) = ", unname(result$timing[3]), " seconds"))
		print("---------------------------------------------------") # print progress
	}
}

save(satuRn_1, file = "./Data/Scalability_runtimes/satuRn_1.RData") # I save this list as RData

## 1.4. Source the first configuration file (specifies #cells and #transcripts in data)
source("./Scalability_benchmark/Configuration/configFile_2.R")

## 1.3. Perform the scalability analysis on the first configuration file

satuRn_2 <- list()
round = 0
invisible(gc())

for (i in L$groupSizes){
	for (j in L$transcripts_amount){
                round = round + 1
		print(paste("Two groups of", i, "cells each with", j, "transcripts"))
		run_satuRn(L, countData, tx2gene) #function outputs the object result
		satuRn_2[round] <- list(result) # runtimes stored in a list

		print(paste0("Runtime (elapsed) = ", unname(result$timing[3]), " seconds"))
		print("---------------------------------------------------") # print progress
	}
}

save(satuRn_2, file = "./Data/Scalability_runtimes/satuRn_2.RData") # I save this list as RData


# 2. Scalability benchmark of limma diffsplice

## 2.1. Source the limma diffsplice method file
source("./Scalability_benchmark/DTU_methods/apply_limmaDiffsplice.R")

## 2.2. Source the first configuration file
source("./Scalability_benchmark/Configuration/configFile_1.R")

## 2.3. Perform the scalability analysis on the first configuration file

limmaDiffsplice_1 <- list()
round = 0
invisible(gc())


for (i in L$groupSizes){
	for (j in L$transcripts_amount){
                round = round + 1
		print(paste("Two groups of", i, "cells each with", j, "transcripts"))
		run_limmaDiffsplice(L, countData, tx2gene) #function outputs the object result
		limmaDiffsplice_1[round] <- list(result) # I store this object in a list

		print(paste0("Runtime (elapsed) = ", unname(result$timing[3]), " seconds"))
		print("---------------------------------------------------") # print progress
	}
}

save(limmaDiffsplice_1, file = "./Data/Scalability_runtimes/limmaDiffsplice_1.RData") # I save this list as RData

## 2.4. Source the second configuration file
source("./Scalability_benchmark/Configuration/configFile_2.R")

## 2.5. Perform the scalability analysis on the second configuration file

limmaDiffsplice_2 <- list()
round = 0
invisible(gc())


for (i in L$groupSizes){
	for (j in L$transcripts_amount){
                round = round + 1
		print(paste("Two groups of", i, "cells each with", j, "transcripts"))
		run_limmaDiffsplice(L, countData, tx2gene) #function outputs the object result
		limmaDiffsplice_2[round] <- list(result) # I store this object in a list

		print(paste0("Runtime (elapsed) = ", unname(result$timing[3]), " seconds"))
		print("---------------------------------------------------") # print progress
	}
}

save(limmaDiffsplice_2, file = "./Data/Scalability_runtimes/limmaDiffsplice_2.RData") # I save this list as RData

# 3. Scalability benchmark of edgeR diffsplice

## 3.1. Source the edgeR diffsplice method file
source("./Scalability_benchmark/DTU_methods/apply_edgeRDiffsplice.R")

## 3.2. Source the first configuration file
source("./Scalability_benchmark/Configuration/configFile_1.R")

## 3.3. Perform the scalability analysis on the first configuration file

edgeRDiffsplice_1 <- list()
round = 0
invisible(gc())


for (i in L$groupSizes){
	for (j in L$transcripts_amount){
                round = round + 1
		print(paste("Two groups of", i, "cells each with", j, "transcripts"))
		run_edgeRDiffsplice(L, countData, tx2gene) #function outputs the object result
		edgeRDiffsplice_1[round] <- list(result) # I store this object in a list

		print(paste0("Runtime (elapsed) = ", unname(result$timing[3]), " seconds"))
		print("---------------------------------------------------") # print progress
	}
}

save(edgeRDiffsplice_1, file = "./Data/Scalability_runtimes/edgeRDiffsplice_1.RData") # I save this list as RData

## 3.4. Source the second configuration file
source("./Scalability_benchmark/Configuration/configFile_2.R")

## 3.5. Perform the scalability analysis on the second configuration file

edgeRDiffsplice_2 <- list()
round = 0
invisible(gc())


for (i in L$groupSizes){
	for (j in L$transcripts_amount){
                round = round + 1
		print(paste("Two groups of", i, "cells each with", j, "transcripts"))
		run_edgeRDiffsplice(L, countData, tx2gene) #function outputs the object result
		edgeRDiffsplice_2[round] <- list(result) # I store this object in a list

		print(paste0("Runtime (elapsed) = ", unname(result$timing[3]), " seconds"))
		print("---------------------------------------------------") # print progress
	}
}

save(edgeRDiffsplice_2, file = "./Data/Scalability_runtimes/edgeRDiffsplice_2.RData") # I save this list as RData

# 4. Scalability benchmark of DoubleExpSeq

## 4.1. Source the DoubleExpSeq method file
source("./Scalability_benchmark/DTU_methods/apply_doubleExpSeq.R")

## 4.2. Source the first configuration file
source("./Scalability_benchmark/Configuration/configFile_1.R")

## 4.3. Perform the scalability analysis on the first configuration file

DoubleExpSeq_1 <- list()
round = 0
invisible(gc())

for (i in L$groupSizes){
	for (j in L$transcripts_amount){
                round = round + 1
		print(paste("Two groups of", i, "cells each with", j, "transcripts"))
		run_doubleExpSeq(L, countData, tx2gene) #function outputs the object result
		DoubleExpSeq_1[round] <- list(result) # I store this object in a list

		print(paste0("Runtime (elapsed) = ", unname(result$timing[3]), " seconds"))
		print("---------------------------------------------------") # print progress
	}
}

save(DoubleExpSeq_1, file = "./Data/Scalability_runtimes/DoubleExpSeq_1.RData") # I save this list as RData

## 4.4. Source the second configuration file
source("./Scalability_benchmark/Configuration/configFile_2.R")

## 4.5. Perform the scalability analysis on the second configuration file

DoubleExpSeq_2 <- list()
round = 0
invisible(gc())


for (i in L$groupSizes){
	for (j in L$transcripts_amount){
                round = round + 1
		print(paste("Two groups of", i, "cells each with", j, "transcripts"))
		run_doubleExpSeq(L, countData, tx2gene) #function outputs the object result
		DoubleExpSeq_2[round] <- list(result) # I store this object in a list

		print(paste0("Runtime (elapsed) = ", unname(result$timing[3]), " seconds"))
		print("---------------------------------------------------") # print progress
	}
}

save(DoubleExpSeq_2, file = "./Data/Scalability_runtimes/DoubleExpSeq_2.RData") # I save this list as RData

# 5. Scalability benchmark of DRIMSeq

## 5.1. Source the DRIMSeq method file
source("./Scalability_benchmark/DTU_methods/apply_DRIMSeq.R")

## 5.2. Source the first configuration file
source("./Scalability_benchmark/Configuration/configFile_1.R")

## 5.3. Perform the scalability analysis on the first configuration file

DRIMSeq_1 <- list()
round = 0
invisible(gc())

for (i in L$groupSizes){
	for (j in L$transcripts_amount){
                round = round + 1
		print(paste("Two groups of", i, "cells each with", j, "transcripts"))
		run_DRIMSeq(L, countData, tx2gene) #function outputs the object result
		DRIMSeq_1[round] <- list(result) # I store this object in a list

		print(paste0("Runtime (elapsed) = ", unname(result$timing[3]), " seconds"))
		print("---------------------------------------------------") # print progress
	}
}

save(DRIMSeq_1, file = "./Data/Scalability_runtimes/DRIMSeq_1.RData") # I save this list as RData

## 5.4. Source the second configuration file
source("./Scalability_benchmark/Configuration/configFile_2.R")

## 5.5. Perform the scalability analysis on the second configuration file

DRIMSeq_2 <- list()
round = 0
invisible(gc())

for (i in L$groupSizes){
	for (j in L$transcripts_amount){
                round = round + 1
		print(paste("Two groups of", i, "cells each with", j, "transcripts"))
		run_DRIMSeq(L, countData, tx2gene) #function outputs the object result
		DRIMSeq_2[round] <- list(result) # I store this object in a list

		print(paste0("Runtime (elapsed) = ", unname(result$timing[3]), " seconds"))
		print("---------------------------------------------------") # print progress
	}
}

save(DRIMSeq_2, file = "./Data/Scalability_runtimes/DRIMSeq_2.RData") # I save this list as RData


# 6. Scalability benchmark of DEXSeq

## 6.1. Source the DEXSeq method file
source("./Scalability_benchmark/DTU_methods/apply_DEXSeq.R")

## 6.2. Source the second (!) configuration file
source("./Scalability_benchmark/Configuration/configFile_2.R")

## 6.3. Perform the scalability analysis on the second configuration file

DEXSeq_2 <- list()
round = 0
invisible(gc())


for (i in L$groupSizes){
	for (j in L$transcripts_amount){
                round = round + 1
		print(paste("Two groups of", i, "cells each with", j, "transcripts"))
		run_DEXSeq(L, countData, tx2gene) #function outputs the object result
		DEXSeq_2[round] <- list(result) # I store this object in a list

		print(paste0("Runtime (elapsed) = ", unname(result$timing[3]), " seconds"))
		print("---------------------------------------------------") # print progress
	}
}

save(DEXSeq_2, file = "./Data/Scalability_runtimes/DEXSeq_2.RData") # I save this list as RData

## 6.4. Source the third (!) configuration file
source("./Scalability_benchmark/Configuration/configFile_3.R")

## 6.5. Perform the scalability analysis on the third configuration file

DEXSeq_3 <- list()
round = 0
invisible(gc())

for (i in L$groupSizes){
	for (j in L$transcripts_amount){
                round = round + 1
		print(paste("Two groups of", i, "cells each with", j, "transcripts"))
		run_DEXSeq(L, countData, tx2gene) #function outputs the object result
		DEXSeq_3[round] <- list(result) # I store this object in a list

		print(paste0("Runtime (elapsed) = ", unname(result$timing[3]), " seconds"))
		print("---------------------------------------------------") # print progress
	}
}

save(DEXSeq_3, file = "./Data/Scalability_runtimes/DEXSeq_3.RData") # I save this list as RData

## 6.6. Source the fourth (!) configuration file
source("./Scalability_benchmark/Configuration/configFile_4.R")

## 6.7. Perform the scalability analysis on the fourth configuration file

DEXSeq_4 <- list()
round = 0
invisible(gc())

for (i in L$groupSizes){
	for (j in L$transcripts_amount){
                round = round + 1
		print(paste("Two groups of", i, "cells each with", j, "transcripts"))
		run_DEXSeq(L, countData, tx2gene) #function outputs the object result
		DEXSeq_4[round] <- list(result) # I store this object in a list

		print(paste0("Runtime (elapsed) = ", unname(result$timing[3]), " seconds"))
		print("---------------------------------------------------") # print progress
	}
}

save(DEXSeq_4, file = "./Data/Scalability_runtimes/DEXSeq_4.RData") # I save this list as RData

# 7. Scalability benchmark of BANDITS

## 7.1. Source the BANDITS method file
source("./Scalability_benchmark/DTU_methods/apply_BANDITS.R")

## 7.2. Source the fifth (!) configuration file
source("./Scalability_benchmark/Configuration/configFile_5.R")

## 7.3. Perform the scalability analysis on the fifth configuration file

BANDITS_5 <- list()
round = 0
invisible(gc())


for (i in L$groupSizes){
	for (j in L$transcripts_amount){
                round = round + 1
		print(paste("Two groups of", i, "cells each with", j, "transcripts"))
		run_BANDITS(L, countData, tx2gene) #function outputs the object result
		BANDITS_5[round] <- list(result) # I store this object in a list

		print(paste0("Runtime (elapsed) = ", unname(result$timing[3]), " seconds"))
		print("---------------------------------------------------") # print progress
	}
}

save(BANDITS_5, file = "./Data/Scalability_runtimes/BANDITS_5.RData") # I save this list as RData

## 7.4. Source the sixth (!) configuration file
source("./Scalability_benchmark/Configuration/configFile_6.R")

## 7.5. Perform the scalability analysis on the second configuration file

BANDITS_6 <- list()
round = 0
invisible(gc())


for (i in L$groupSizes){
	for (j in L$transcripts_amount){
                round = round + 1
		print(paste("Two groups of", i, "cells each with", j, "transcripts"))
		run_BANDITS(L, countData, tx2gene) #function outputs the object result
		BANDITS_6[round] <- list(result) # I store this object in a list

		print(paste0("Runtime (elapsed) = ", unname(result$timing[3]), " seconds"))
		print("---------------------------------------------------") # print progress
	}
}

save(BANDITS_6, file = "./Data/Scalability_runtimes/BANDITS_6.RData") # I save this list as RData


