Skip to content

Commit

Permalink
Essentiality files are outputed and unit tests adjusted.
Browse files Browse the repository at this point in the history
  • Loading branch information
sbastkowski committed Dec 20, 2019
1 parent 851ad6f commit d8a740b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 22 deletions.
5 changes: 4 additions & 1 deletion albatradis/BlockInsertions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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")

Expand All @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion albatradis/TradisComparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from tempfile import mkstemp
import os
import csv
import shutil


class GeneEssentiality:
Expand All @@ -24,14 +25,16 @@ 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
self.verbose = verbose
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()
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions albatradis/TradisEssentiality.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
15 changes: 0 additions & 15 deletions albatradis/tests/AlbaTraDIS_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
2 changes: 1 addition & 1 deletion albatradis/tests/PresenceAbsence_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

5 changes: 3 additions & 2 deletions albatradis/tests/ScatterPlot_test.py
Original file line number Diff line number Diff line change
@@ -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__))
Expand All @@ -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")

0 comments on commit d8a740b

Please sign in to comment.