changeset 6:2ffa8172dce1

Tests for valid RNA Seq bam and warnings when there are no RNA counts
author Vimalkumar Velayudhan <vimal@biotechcoder.com>
date Wed, 12 Aug 2015 16:28:43 +0100
parents cef780bcce01
children 096c6bbf4a04
files riboplot/ribocore.py riboplot/riboplot.py tests/test_riboplot.py
diffstat 3 files changed, 21 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/riboplot/ribocore.py	Wed Aug 12 09:53:06 2015 +0100
+++ b/riboplot/ribocore.py	Wed Aug 12 16:28:43 2015 +0100
@@ -171,6 +171,13 @@
             logging.error('Could not find bedtools in PATH. bedtools is '
                           'required for generating RNA coverage plot.')
             raise
+        # Is this a valid BAM file? i.e., can pysam read it?
+        try:
+            is_bam_valid(rna_file)
+        except ValueError:
+            logging.error('The given RNASeq BAM file is not valid')
+            raise
+
     # If read_length is given, it must be a positive integer or reads of that
     # length must exist in the BAM file
     if read_length:
--- a/riboplot/riboplot.py	Wed Aug 12 09:53:06 2015 +0100
+++ b/riboplot/riboplot.py	Wed Aug 12 16:28:43 2015 +0100
@@ -118,11 +118,11 @@
 
     # plot for frames legend
     ax1 = plt.subplot(gs[0], axisbg='white')
-    ax1.text(0.96, 0.1, "frame 1", size=6, ha="right", va="center", color='white',
+    ax1.text(0.95, 0.1, "frame 1", size=6, ha="right", va="center", color='white',
              bbox=dict(boxstyle="square", color='tomato'))
-    ax1.text(0.98, 0.1, "2", size=6, ha="right", va="center", color='white',
+    ax1.text(0.97, 0.1, "2", size=6, ha="right", va="center", color='white',
              bbox=dict(boxstyle="square", color='limegreen'))
-    ax1.text(1, 0.1, "3", size=6, ha="right", va="center", color='white',
+    ax1.text(0.99, 0.1, "3", size=6, ha="right", va="center", color='white',
              bbox=dict(boxstyle="square", color='deepskyblue'))
 
     # riboseq bar plots
@@ -294,6 +294,11 @@
             except OSError as e:
                 logging.error(e)
                 raise
+
+            if not mrna_counts:
+                logging.warn('No RNA counts for this transcript from the given RNA Seq file. '
+                             'RNA-Seq coverage will not be generated')
+
         else:
             logging.debug('No RNA-Seq data provided. Not generating coverage')
 
--- a/tests/test_riboplot.py	Wed Aug 12 09:53:06 2015 +0100
+++ b/tests/test_riboplot.py	Wed Aug 12 16:28:43 2015 +0100
@@ -111,6 +111,12 @@
         self.assertIsInstance(counts, dict)
         self.assertTrue(len(counts) > 0)
 
+    def test_invalid_rna_file(self):
+        """If an invalid RNA file is provided, generate an error message"""
+        # using transcriptome FASTA file as the invalid RNA file for test
+        parser = riboplot.create_parser()
+        args = parser.parse_args(['-b', RIBO_FILE,  '-f', TRANSCRIPTOME_FASTA, '-t', TRANSCRIPT_NAME, '-n', TRANSCRIPTOME_FASTA])
+        self.assertRaises(ValueError, ribocore.check_optional_arguments, args.ribo_file, args.rna_file)
 
 class RiboPlotTestCase(unittest.TestCase):
 
@@ -158,8 +164,3 @@
     def test_write_ribo_counts(self):
         """Write RiboSeq read counts as CSV."""
         pass
-
-    @unittest.skip('todo')
-    def test_plot_read_counts(self):
-        """Generate riboplots"""
-        pass