From 3aa47fe7f791f01501036d3125f8b8ee5712e647 Mon Sep 17 00:00:00 2001 From: Steffen Moeller Date: Fri, 14 Sep 2018 10:43:38 +0200 Subject: [PATCH] New upstream version 0.15.1+ds --- .gitignore | 1 + NEWS | 39 +++++++++++++++++++------------ bcftools/config.h | 2 -- doc/release.rst | 9 +++++++ pysam/libcalignmentfile.pyx | 7 +++++- tests/AlignmentFileHeader_test.py | 3 +-- tests/AlignmentFile_test.py | 31 ++++++++++++++++++++---- tests/pysam_data/Makefile | 1 + tests/samtools_test.py | 3 ++- 9 files changed, 71 insertions(+), 25 deletions(-) delete mode 100644 bcftools/config.h diff --git a/.gitignore b/.gitignore index 74fde57..fd28d6d 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ tests/cbcf_data tests/tabix_data samtools/config.h +bcftools/config.g htslib/config.status htslib/config.h htslib/config.log diff --git a/NEWS b/NEWS index 61b9254..0ac7303 100644 --- a/NEWS +++ b/NEWS @@ -5,10 +5,19 @@ http://pysam.readthedocs.io/en/latest/release.html Release notes ============= +Release 0.15.1 +============== + +Bugfix release. + +* [#716] raise ValueError if tid is out of range when writing +* [#697] release version using cython 0.28.5 for python 3.7 + compatibility + Release 0.15.0 ============== -This release wraps htslib/samtools/bcftools version 1.9.0. +This release wraps htslib (and friends) version 1.9. * [#673] permit dash in chromosome name of region string * [#656] Support `text` when opening a SAM file for writing @@ -67,13 +76,13 @@ Backwards incompatible changes: The rationale for this change is to have consistency between AlignmentFile and VariantFile. - + * AlignmentFile and FastaFile now raise IOError instead of OSError Medium term we plan to have a 1.0 release. The pysam interface has grown over the years and the API is cluttered with deprecated names (Samfile, getrname(), gettid(), ...). To work towards -this, the next release (0.15.0) will yield DeprecationWarnings +this, the next release (0.15.0) will yield DeprecationWarnings for any parts of the API that are considered obsolete and will not be in 1.0. Once 1.0 has been reached, we will use semantic versioning. @@ -142,7 +151,7 @@ are created will need to change as the constructor requires a header:: header = pysam.AlignmentHeader( reference_names=["chr1", "chr2"], reference_lengths=[1000, 1000]) - + read = pysam.AlignedSegment(header) This will affect all code that instantiates AlignedSegment objects @@ -212,7 +221,7 @@ Release 0.11.0 This release wraps the latest versions of htslib/samtools/bcftools and implements a few bugfixes. -* [#413] Wrap HTSlib/Samtools/BCFtools 1.4 +* [#413] Wrap HTSlib/Samtools/BCFtools 1.4 * [#422] Fix missing pysam.sort.usage() message * [#411] Fix BGZfile initialization bug * [#412] Add seek support for BGZFile @@ -355,7 +364,7 @@ Potential isses when upgrading from v0.8.3: * binary tags are now returned as python arrays -* renamed several methods for pep8 compatibility, old names still retained for +* renamed several methods for pep8 compatibility, old names still retained for backwards compatibility, but should be considered deprecated. * gettid() is now get_tid() * getrname() is now get_reference_name() @@ -365,7 +374,7 @@ Potential isses when upgrading from v0.8.3: names being present: * fromQualityString() is now qualitystring_to_array() * toQualityString() is now qualities_to_qualitystring() - + * faidx now returns strings and not binary strings in py3. * The cython components have been broken up into smaller files with @@ -474,7 +483,7 @@ Release 0.8.2 with reading and writing capability. However, the interface is still incomplete and preliminary and lacks capability to mutate the resulting data. - + Release 0.8.1 ============= @@ -485,8 +494,8 @@ Release 0.8.1 * issue #42: skip tests requiring network if none available * issue #19: multiple iterators can now be made to work on the same tabix file * issue #24: All strings returned from/passed to the pysam API are now unicode in python 3 - * issue #5: type guessing for lists of integers fixed - + * issue #5: type guessing for lists of integers fixed + * API changes for consistency. The old API is still present, but deprecated. In particular: @@ -516,7 +525,7 @@ Release 0.8.1 * qstart -> query_alignment_start * qend -> query_alignment_end * qlen -> query_alignment_length - * mrnm -> next_reference_id + * mrnm -> next_reference_id * mpos -> next_reference_start * rname -> reference_id * isize -> template_length @@ -539,7 +548,7 @@ Backwards incompatible changes * Empty cigarstring now returns None (intstead of '') * Empty cigar now returns None (instead of []) * When using the extension classes in cython modules, AlignedRead - needs to be substituted with AlignedSegment. + needs to be substituted with AlignedSegment. * fancy_str() has been removed * qual, qqual now return arrays @@ -603,18 +612,18 @@ Release 0.7.5 Release 0.7.4 ============= - + * further bugfixes to setup.py and package layout Release 0.7.3 ============= - + * further bugfixes to setup.py * upgraded distribute_setup.py to 0.6.34 Release 0.7.2 ============= - + * bugfix in installer - failed when cython not present * changed installation locations of shared libraries diff --git a/bcftools/config.h b/bcftools/config.h deleted file mode 100644 index f8fff59..0000000 --- a/bcftools/config.h +++ /dev/null @@ -1,2 +0,0 @@ -/* empty config.h created by pysam */ -/* conservative compilation options */ diff --git a/doc/release.rst b/doc/release.rst index 0e3b963..ed3afb2 100644 --- a/doc/release.rst +++ b/doc/release.rst @@ -2,6 +2,15 @@ Release notes ============= +Release 0.15.1 +============== + +Bugfix release. + +* [#716] raise ValueError if tid is out of range when writing +* [#697] release version using cython 0.28.5 for python 3.7 + compatibility + Release 0.15.0 ============== diff --git a/pysam/libcalignmentfile.pyx b/pysam/libcalignmentfile.pyx index 9e4f5a7..1d42dda 100644 --- a/pysam/libcalignmentfile.pyx +++ b/pysam/libcalignmentfile.pyx @@ -1713,8 +1713,13 @@ cdef class AlignmentFile(HTSFile): if not self.is_open: return 0 + if self.header.ptr.n_targets <= read._delegate.core.tid: + raise ValueError( + "AlignedSegment refers to reference number {} that " + "is larger than the number of references ({}) in the header".format( + read._delegate.core.tid, self.header.ptr.n_targets)) + cdef int ret - with nogil: ret = sam_write1(self.htsfile, self.header.ptr, diff --git a/tests/AlignmentFileHeader_test.py b/tests/AlignmentFileHeader_test.py index 1cf733e..b72c8ef 100644 --- a/tests/AlignmentFileHeader_test.py +++ b/tests/AlignmentFileHeader_test.py @@ -120,8 +120,7 @@ class TestHeaderConstruction(unittest.TestCase): reference_lengths=[1575, 1584]) self.compare_headers(header, self.header_without_text) self.check_name_mapping(header) - - + class TestHeaderSAM(unittest.TestCase): """testing header manipulation""" diff --git a/tests/AlignmentFile_test.py b/tests/AlignmentFile_test.py index 0068bb7..ec0f5e1 100644 --- a/tests/AlignmentFile_test.py +++ b/tests/AlignmentFile_test.py @@ -1259,7 +1259,7 @@ class TestWrongFormat(unittest.TestCase): 'rb') -class TestRegionParsiong(unittest.TestCase): +class TestRegionParsing(unittest.TestCase): def test_dash_in_chr(self): with pysam.AlignmentFile( @@ -1290,7 +1290,7 @@ class TestDeNovoConstruction(unittest.TestCase): def setUp(self): header = pysam.AlignmentHeader.from_dict(self.header) - + a = pysam.AlignedSegment(header) a.query_name = "read_28833_29006_6945" a.query_sequence = "AGCTTAGCTAGCTACCTATATCTTGGTCTTGGCCG" @@ -1407,7 +1407,30 @@ class TestEmptyHeader(unittest.TestCase): self.assertTrue("SQ" in s.header.to_dict()) self.assertTrue("@SQ" in str(s.header)) - + +class TestMismatchingHeader(unittest.TestCase): + '''see issue 716.''' + + def testMismatchingHeader(self): + # Note: no chr2 + header = { + 'SQ': [{'SN': 'chr1', 'LN': 1575}], + 'PG': [{'ID': 'bwa', 'PN': 'bwa', 'VN': '0.7.15', 'CL': 'bwa mem xx -'}], + } + + dest = get_temp_filename("tmp_ex3.bam") + with pysam.AlignmentFile(os.path.join(BAM_DATADIR, 'ex3.bam')) as inf: + with pysam.AlignmentFile(dest, mode="wb", header=header) as outf: + for read in inf: + if read.reference_name == "chr1": + outf.write(read) + else: + self.assertRaises(ValueError, + outf.write, + read) + os.unlink(dest) + + class TestHeaderWithProgramOptions(unittest.TestCase): '''see issue 39.''' @@ -1436,7 +1459,7 @@ class TestTruncatedBAM(unittest.TestCase): pysam.AlignmentFile, os.path.join(BAM_DATADIR, 'ex2_truncated.bam')) - def testTruncatedBam2(self): + def testTruncatedBamIterator(self): s = pysam.AlignmentFile(os.path.join(BAM_DATADIR, 'ex2_truncated.bam'), ignore_truncation=True) diff --git a/tests/pysam_data/Makefile b/tests/pysam_data/Makefile index bb38a4f..bae50db 100644 --- a/tests/pysam_data/Makefile +++ b/tests/pysam_data/Makefile @@ -91,6 +91,7 @@ clean: rm -fr *.bam *.bai *.fai *.pileup* *.cram \ *~ calDepth *.dSYM pysam_*.sam \ ex2.sam ex2.sam.gz ex1.sam \ + with_md.sam.gz \ *.fq.gz %.fq.gz: %.fq diff --git a/tests/samtools_test.py b/tests/samtools_test.py index e84c7e5..40d84c0 100644 --- a/tests/samtools_test.py +++ b/tests/samtools_test.py @@ -266,7 +266,8 @@ class SamtoolsTest(unittest.TestCase): # ignore commands that exit or cause other failures # TODO: check - if reheader or phase is run in testStatements, sort fails # here - if command in ("view", "sort", "bam2fq", "flagstat", "reheader", "stats"): + if command in ("view", "sort", "bam2fq", "flagstat", "reheader", + "stats", "idxstats"): continue mapped_command = self.get_command(statement, map_to_internal=True) pysam_method = getattr(self.module, mapped_command) -- 2.30.2