When comparing bam files in the test framework, convert them to sam for comparison.

This commit is contained in:
Nate Coraor
2011-02-23 14:53:54 -05:00
parent 668d03ba7d
commit e1ea63eb9a
2 changed files with 16 additions and 2 deletions
+15 -1
View File
@@ -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:
+1 -1
View File
@@ -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( '<span class="bam">bam</span>' )
# Make sure the Bam index was created
assert hda.metadata.bam_index is not None, "Bam index was not correctly created for 1.bam"