From e1ea63eb9a6f6db15d6ea2272a7713b94845b2ca Mon Sep 17 00:00:00 2001 From: Nate Coraor Date: Wed, 23 Feb 2011 14:53:54 -0500 Subject: [PATCH] When comparing bam files in the test framework, convert them to sam for comparison. --- test/base/twilltestcase.py | 16 +++++++++++++++- test/functional/test_get_data.py | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/test/base/twilltestcase.py b/test/base/twilltestcase.py index a78cad0d68b..6e103108681 100644 --- a/test/base/twilltestcase.py +++ b/test/base/twilltestcase.py @@ -1,7 +1,7 @@ import pkg_resources pkg_resources.require( "twill==0.9" ) -import StringIO, os, sys, random, filecmp, time, unittest, urllib, logging, difflib, tarfile, zipfile, tempfile, re, shutil +import StringIO, os, sys, random, filecmp, time, unittest, urllib, logging, difflib, tarfile, zipfile, tempfile, re, shutil, subprocess from itertools import * import twill @@ -633,6 +633,9 @@ class TwillTestCase( unittest.TestCase ): try: if attributes is None: attributes = {} + if attributes.get( 'ftype', None ) == 'bam': + local_fh, temp_name = self._bam_to_sam( local_name, temp_name ) + local_name = local_fh.name compare = attributes.get( 'compare', 'diff' ) extra_files = attributes.get( 'extra_files', None ) if compare == 'diff': @@ -658,6 +661,17 @@ class TwillTestCase( unittest.TestCase ): finally: os.remove( temp_name ) + def _bam_to_sam( self, local_name, temp_name ): + temp_local = tempfile.NamedTemporaryFile( suffix='.sam', prefix='local_bam_converted_to_sam_' ) + fd, temp_temp = tempfile.mkstemp( suffix='.sam', prefix='history_bam_converted_to_sam_' ) + os.close( fd ) + p = subprocess.Popen( args="samtools view %s -o %s" % ( local_name, temp_local.name ), shell=True ) + assert not p.wait(), 'Converting local (test-data) bam to sam failed' + p = subprocess.Popen( args="samtools view %s -o %s" % ( temp_name, temp_temp ), shell=True ) + assert not p.wait(), 'Converting history bam to sam failed' + os.remove( temp_name ) + return temp_local, temp_temp + def verify_extra_files_content( self, extra_files, hda_id ): files_list = [] for extra_type, extra_value, extra_name, extra_attributes in extra_files: diff --git a/test/functional/test_get_data.py b/test/functional/test_get_data.py index 024bb919fc1..85253d14de4 100644 --- a/test/functional/test_get_data.py +++ b/test/functional/test_get_data.py @@ -389,7 +389,7 @@ class UploadData( TwillTestCase ): self.upload_file( '1.bam' ) hda = get_latest_hda() assert hda is not None, "Problem retrieving hda from database" - self.verify_dataset_correctness( '1.bam', hid=str( hda.hid ) ) + self.verify_dataset_correctness( '1.bam', hid=str( hda.hid ), attributes={ 'ftype' : 'bam' } ) self.check_history_for_string( 'bam' ) # Make sure the Bam index was created assert hda.metadata.bam_index is not None, "Bam index was not correctly created for 1.bam"