Commit 78b07f36 authored by maxime mano's avatar maxime mano
Browse files

Run with barcode visualisation, part 1 before migration to git

parent 648e628e
......@@ -32,13 +32,15 @@ class Run_stats (Analysis):
This module make some statistic from ONT run with graphs
"""
def define_parameters(self, sequencing_summary_file, archive_name="RunStats_archive.tar.gz"):
def define_parameters(self, sequencing_summary_file, barcoded=False, archive_name="RunStats_archive.tar.gz"):
logging.getLogger("jflow").debug("Begin Run_stats parameters")
self.add_input_file( "sequencing_summary_file", "Input ont sequencing summary file from Albacore", default=sequencing_summary_file, file_format = "txt", required=True)
self.add_parameter("barcoded", "Indicate that barcodes are used for this run", default=barcoded, type='str')
self.add_parameter("archive_name", "Archive name", default=archive_name)
self.add_output_file_list("stderr", "stderr ouput file",pattern='{basename_woext}.stderr', items = self.sequencing_summary_file)
self.add_output_file_list("stderr", "stderr ouput file",pattern='Run_stats.stderr', items = self.sequencing_summary_file)
if self.barcoded == "yes":
self.add_output_file_list("stderr_barcoded", "stderr ouput barcoded file",pattern='Run_stats_barcoded.stderr', items = self.sequencing_summary_file)
def get_version(self):
......@@ -46,7 +48,7 @@ class Run_stats (Analysis):
#p = Popen(cmd, stdout=PIPE, stderr=PIPE)
#stdout, stderr = p.communicate()
#return stdout.split()[1]
return "v1"
return "v1.1"
def define_analysis(self):
self.name = "RUNStats"
......@@ -82,9 +84,26 @@ class Run_stats (Analysis):
if parts[0] == "median_yield_per_sec": stats["median_yield_per_sec"] = parts[1]
if parts[0] == "mean_yield_per_sec": stats["mean_yield_per_sec"] = parts[1]
if parts[0] == "nb_actif_channel": stats["nb_actif_channel"] = parts[1]
print(stats)
#print(stats)
return stats
def __parse_barcode_file (self, barcode_file):
"""
Parse the barcode file
@param barcode_file : the runstatsR barcode file
@return : {"" : "", ...}
"""
stats = {}
barcode_names = []
logging.getLogger("jflow").debug("Begin post_process _parse_barcode_file!")
for line in open(barcode_file, 'r').readlines():
parts = line.strip().split(",")
stats[parts[0]] = parts
barcode_names.append(parts[0])
#print(barcode_names)
#print(stats)
return stats,barcode_names
def post_process(self):
logging.getLogger("jflow").debug("Begin Run_stats.post_process! "+self.output_directory)
results_files = []
......@@ -113,7 +132,6 @@ class Run_stats (Analysis):
metrics.append(group)
self._add_result_element("metrics", "headers", ','.join(["nb_reads", "total_bases", "median_read_length", "N50_read_length", "L50_read_length", "median_yield_per_sec", "nb_actif_channel"]), group)
self._add_result_element(sample, "nb_reads", str(stat_info["nb_reads"]),group),
self._add_result_element(sample, "total_bases", str(stat_info["total_bases"]),group),
self._add_result_element(sample, "median_read_length", str(stat_info["median_read_length"]),group),
self._add_result_element(sample, "mean_read_length", str(stat_info["mean_read_length"]),group),
......@@ -159,6 +177,50 @@ class Run_stats (Analysis):
sample + ".poreactivity.png"), group)
results_files.append(os.path.join(self.output_directory, "plot_poreactivity.png"))
if self.barcoded == "yes":
barcodefile = os.path.join(self.output_directory,"plot_barcoded_statsbarcodes.txt")
if os.path.isfile(barcodefile):
barcode_info, barcode_names = self.__parse_barcode_file(os.path.join(self.output_directory, "plot_barcoded_statsbarcodes.txt"))
group = 'barcode'
metrics.append(group)
self._add_result_element("metrics", "headers", ','.join(["barcode_score","nb_reads","total_bases","median_read_length","N50_read_length","L50_read_length","median_read_quality","nb_read_Q>10","total_bases_Q>10","median_yield_per_sec","nb_actif_channel"]), group)
self._add_result_element("metrics", "names", ','.join(barcode_names),group)
for barcode in barcode_names :
group = barcode
self._add_result_element(sample, "barcode_score", str(barcode_info[barcode][1]),group),
self._add_result_element(sample, "nb_reads", str(barcode_info[barcode][2]),group),
self._add_result_element(sample, "total_bases", str(barcode_info[barcode][3]),group),
self._add_result_element(sample, "median_read_length", str(barcode_info[barcode][4]),group),
self._add_result_element(sample, "N50_read_length", str(barcode_info[barcode][6]),group),
self._add_result_element(sample, "L50_read_length", str(barcode_info[barcode][7]),group),
self._add_result_element(sample, "median_read_quality", str(barcode_info[barcode][8]),group),
self._add_result_element(sample, "nb_read_Q>10", str(barcode_info[barcode][12]),group),
self._add_result_element(sample, "total_bases_Q>10", str(barcode_info[barcode][13]),group),
self._add_result_element(sample, "median_yield_per_sec", str(barcode_info[barcode][16]),group),
self._add_result_element(sample, "nb_actif_channel", str(barcode_info[barcode][18]),group),
group = 'plots_barcode'
metrics.append(group)
self._add_result_element("metrics", "headers", ','.join(["qscoreboxplot", "qscorepertimeintervalsboxplot", "qscorevariation"]), group)
if os.path.isfile(os.path.join(self.output_directory, "plot_barcoded_qscoreboxplot.png")):
self._add_result_element(sample, "qscoreboxplot", self._save_file(os.path.join(self.output_directory, "plot_barcoded_qscoreboxplot.png"),
sample + ".barcoded_qscoreboxplot.png"), group)
results_files.append(os.path.join(self.output_directory, "plot_barcoded_qscoreboxplot.png"))
if os.path.isfile(os.path.join(self.output_directory, "plot_barcoded_qscorepertimeintervalsboxplot.png")):
self._add_result_element(sample, "qscorepertimeintervalsboxplot", self._save_file(os.path.join(self.output_directory, "plot_barcoded_qscorepertimeintervalsboxplot.png"),
sample + ".barcoded_qscorepertimeintervalsboxplot.png"), group)
results_files.append(os.path.join(self.output_directory, "plot_barcoded_qscorepertimeintervalsboxplot.png"))
if os.path.isfile(os.path.join(self.output_directory, "plot_barcoded_qscorevariation.png")):
self._add_result_element(sample, "qscorevariation", self._save_file(os.path.join(self.output_directory, "plot_barcoded_qscorevariation.png"),
sample + ".barcoded_qscorevariation.png"), group)
results_files.append(os.path.join(self.output_directory, "plot_barcoded_qscorevariation.png"))
# Finaly create and add the archive to the analysis
self._create_and_archive(results_files,self.archive_name)
......@@ -167,11 +229,19 @@ class Run_stats (Analysis):
#print (self.sequencing_summary_file)
self.add_shell_execution(self.get_exec_path("Rscript") +" /save/sbsuser/trunk/ont/graph_albacoresummary.R " +' -f '+ '$1' +' --out ' + self.output_directory + " 2> " +' $2',
self.add_shell_execution(self.get_exec_path("Rscript") +" /work/ng6-test/claire/test_ont_qc/graph_albacoresummary.R " +' -f '+ '$1' +' --out ' + self.output_directory + " 2> " +' $2',
cmd_format='{EXE} {IN} {OUT}' ,
map=False,
inputs = self.sequencing_summary_file,
outputs = self.stderr)
if self.barcoded == "yes" :
self.add_shell_execution(self.get_exec_path("Rscript") +" /work/ng6-test/claire/test_ont_qc/graph_albacoresummary_barcode.R " +' -f '+ '$1' +' --out ' + self.output_directory + " 2> " +' $2',
cmd_format='{EXE} {IN} {OUT}' ,
map=False,
inputs = self.sequencing_summary_file,
outputs = self.stderr_barcoded)
#self.add_shell_execution('tar -czf '+ self.output_directory +'/'+'Run_stats_archive.tar.gz -C '+ self.output_directory +' plot_stats.txt -C '+ self.output_directory +' *.png ', cmd_format='{EXE} {OUT}',
# map=False, outputs = self.archive_name)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment