diff --git a/albatradis/BlockInsertions.py b/albatradis/BlockInsertions.py index b405b28..2dad6ca 100644 --- a/albatradis/BlockInsertions.py +++ b/albatradis/BlockInsertions.py @@ -128,6 +128,7 @@ def essentiality(self, plotfile_objects, plotfile, filetype): if self.verbose: print("Essentiality:\t" + filetype + "\t" + e.output_filename) + return pe def run_essentiality(self, plotfile_objects): @@ -171,12 +172,13 @@ def generate_logfc_plot(self, analysis_type, essentiality_files): mid = int(len(files) / 2) t = TradisComparison(files[:mid], files[mid:], self.verbose, self.minimum_block, only_ess_files[:mid], - only_ess_files[mid:]) + only_ess_files[mid:], analysis_type, self.prefix) t.run() p = PlotLog(t.output_filename, self.genome_length, self.minimum_logfc, self.pvalue, self.qvalue, self.minimum_logcpm, self.window_size, self.span_gaps, self.report_decreased_insertions, annotation_files[0]) p.construct_plot_file() + renamed_csv_file = os.path.join(self.prefix, analysis_type + ".csv") renamed_plot_file = os.path.join(self.prefix, analysis_type + ".plot") @@ -185,6 +187,7 @@ def generate_logfc_plot(self, analysis_type, essentiality_files): os.remove(t.output_filename) os.remove(p.output_filename) + if self.verbose: print("Comparison:\t" + renamed_csv_file) print("Plot log:\t" + renamed_plot_file) diff --git a/albatradis/TradisComparison.py b/albatradis/TradisComparison.py index c93b546..0a16e4e 100644 --- a/albatradis/TradisComparison.py +++ b/albatradis/TradisComparison.py @@ -2,6 +2,7 @@ from tempfile import mkstemp import os import csv +import shutil class GeneEssentiality: @@ -24,7 +25,7 @@ def status(self): class TradisComparison: def __init__(self, condition_files, control_files, verbose, minimum_block, only_ess_files_condition, - only_ess_files_control, exec="tradis_comparison.R"): + only_ess_files_control, analysis_type, prefix, exec="tradis_comparison.R"): self.condition_files = condition_files self.control_files = control_files self.exec = exec @@ -32,6 +33,8 @@ def __init__(self, condition_files, control_files, verbose, minimum_block, only_ self.minimum_block = minimum_block self.only_ess_files_condition = only_ess_files_condition self.only_ess_files_control = only_ess_files_control + self.analysis_type = analysis_type + self.prefix = prefix fd, self.output_filename = mkstemp() fd, self.conditions_fofn = mkstemp() @@ -65,6 +68,12 @@ def all_gene_essentiality(self, input_filename): for e in ess_gene_names: if e in genes_ess: genes_ess[e].control += 1 + + condition_name = os.path.join(self.prefix, self.analysis_type + "_condition_essen.ess") + shutil.copy(self.only_ess_files_condition[0], condition_name) + control_name = os.path.join(self.prefix, self.analysis_type + "_control_essen.ess") + shutil.copy(self.only_ess_files_control[0], control_name) + return genes_ess def create_fofn(self): diff --git a/albatradis/TradisEssentiality.py b/albatradis/TradisEssentiality.py index c8a8acd..945f2a2 100644 --- a/albatradis/TradisEssentiality.py +++ b/albatradis/TradisEssentiality.py @@ -23,7 +23,7 @@ def run(self): self.replace_comma_tabs(self.tabfile +".all.csv", self.output_filename) shutil.copy(self.tabfile +".essen.csv", self.essential_filename) - + if self.verbose: print("all.csv\t" + self.output_filename) print("essen.csv\t" + self.essential_filename) @@ -32,7 +32,7 @@ def run(self): os.remove(self.tabfile +".essen.csv") os.remove(self.tabfile +".ambig.csv") os.remove(self.tabfile +".QC_and_changepoint_plots.pdf") - os.remove(self.tabfile ) + os.remove(self.tabfile) return self diff --git a/albatradis/tests/AlbaTraDIS_test.py b/albatradis/tests/AlbaTraDIS_test.py index 51e5d6f..caf5e60 100644 --- a/albatradis/tests/AlbaTraDIS_test.py +++ b/albatradis/tests/AlbaTraDIS_test.py @@ -70,18 +70,3 @@ def test_small_use_annotation(self): self.assertTrue(t.run()) self.assertTrue(os.path.exists('testoutput')) shutil.rmtree("testoutput") - - # def test_example_toy(self): - # case = os.path.join(example_dir, '025mgLTricRep1.insert_site_plot_short.gz') - # control = os.path.join(example_dir, 'controlLBrep1.insert_site_plot_short.gz') - # emblfile = os.path.join(example_dir, 'reference_BW25113_short.embl') - # out_dir = (os.path.join(base_dir, 'albatradis_output:/work')) - # - # cmd = " ".join( - # ['docker run --rm -v', out_dir, 'quadraminstitute/albatradis:latest albatradis -v -a ', emblfile, case, control]) - # - # subprocess.call(cmd, shell=True) - # - # self.assertTrue(os.path.exists(os.path.join(base_dir, 'albatradis_output/output'))) - # self.assertTrue(os.path.exists(os.path.join(base_dir, 'albatradis_output/output/gene_report.csv'))) - # shutil.rmtree(os.path.join(base_dir,'albatradis_output')) \ No newline at end of file diff --git a/albatradis/tests/PresenceAbsence_test.py b/albatradis/tests/PresenceAbsence_test.py index 2be4a39..b5548dc 100644 --- a/albatradis/tests/PresenceAbsence_test.py +++ b/albatradis/tests/PresenceAbsence_test.py @@ -40,5 +40,5 @@ def test_valid_file(self): self.assertTrue(nj_tree) self.assertTrue(filecmp.cmp(exp_lfc, all_outputfile)) - #sshutil.rmtree('testoutput') + shutil.rmtree('testoutput') diff --git a/albatradis/tests/ScatterPlot_test.py b/albatradis/tests/ScatterPlot_test.py index 0788210..d231831 100644 --- a/albatradis/tests/ScatterPlot_test.py +++ b/albatradis/tests/ScatterPlot_test.py @@ -1,7 +1,5 @@ import unittest import os -import logging -import filecmp from albatradis.ScatterPlot import ScatterPlot test_modules_dir = os.path.dirname(os.path.realpath(__file__)) @@ -19,3 +17,6 @@ def test_valid(self): self.assertTrue(s.create_linear_plot()) self.assertTrue(s.create_abs_scatter_plot()) + os.remove("scattertest_absscatter.png") + os.remove("scattertest_linear.png") + os.remove("scattertest_scatter.png")