+ filename = "example.vcf40"
+
+ columns = ("contig", "pos", "id",
+ "ref", "alt", "qual",
+ "filter", "info", "format" )
+
+ # tests failing while parsing
+ fail_on_parsing = ( (5, "Flag fields should not have a value"),
+ (9, "aouao" ),
+ (13, "aoeu" ),
+ (18, "Error BAD_NUMBER_OF_PARAMETERS" ),
+ (24, "Error HEADING_NOT_SEPARATED_BY_TABS" ) )
+
+ # tests failing on opening
+ fail_on_opening = ( (24, "Error HEADING_NOT_SEPARATED_BY_TABS" ),
+ )
+
+ def setUp( self ):
+
+ self.vcf = pysam.VCF()
+ self.compare = loadAndConvert( self.filename )
+
+ def testParsing( self ):
+
+ fn = os.path.basename( self.filename )
+ with open(self.filename) as f:
+
+ for x, msg in self.fail_on_opening:
+ if "%i.vcf" % x == fn:
+ self.assertRaises( ValueError, self.vcf.parse, f )
+ return
+ else:
+ iter = self.vcf.parse(f)
+
+ for x, msg in self.fail_on_parsing:
+ if "%i.vcf" % x == fn:
+ self.assertRaises( ValueError, list, iter )
+ break
+ # python 2.7
+ # self.assertRaisesRegexp( ValueError, re.compile(msg), self.vcf.parse, f )
+ else:
+ for ln in iter:
+ pass
+
+############################################################################
+# create a test class for each example vcf file.
+# Two samples are created -
+# 1. Testing pysam/tabix access
+# 2. Testing the VCF class
+vcf_files = glob.glob( "vcf-examples/*.vcf" )
+
+for vcf_file in vcf_files:
+ n = "VCFFromTabixTest_%s" % os.path.basename( vcf_file[:-4] )
+ globals()[n] = type( n, (TestVCFFromTabix,), dict( filename=vcf_file,) )
+ n = "VCFFromVCFTest_%s" % os.path.basename( vcf_file[:-4] )
+ globals()[n] = type( n, (TestVCFFromVCF,), dict( filename=vcf_file,) )
+
+############################################################################
+class TestRemoteFileHTTP( unittest.TestCase):
+
+ url = "http://genserv.anat.ox.ac.uk/downloads/pysam/test/example.gtf.gz"
+ region = "chr1:1-1000"
+ local = "example.gtf.gz"
+
+ def testFetchAll( self ):
+ remote_file = pysam.Tabixfile(self.url, "r")
+ remote_result = list(remote_file.fetch())
+ local_file = pysam.Tabixfile(self.local, "r")
+ local_result = list(local_file.fetch())
+
+ self.assertEqual( len(remote_result), len(local_result) )
+ for x, y in zip(remote_result, local_result):
+ self.assertEqual( x, y )