[med-svn] [Git][med-team/cyvcf2][upstream] New upstream version 0.30.1

Nilesh Patra gitlab at salsa.debian.org
Sat Dec 12 13:23:40 GMT 2020



Nilesh Patra pushed to branch upstream at Debian Med / cyvcf2


Commits:
654e9ee1 by Nilesh Patra at 2020-12-06T20:18:29+05:30
New upstream version 0.30.1
- - - - -


3 changed files:

- cyvcf2/__init__.py
- cyvcf2/cyvcf2.pyx
- cyvcf2/tests/test_reader.py


Changes:

=====================================
cyvcf2/__init__.py
=====================================
@@ -2,4 +2,4 @@ from .cyvcf2 import (VCF, Variant, Writer, r_ as r_unphased, par_relatedness,
                      par_het)
 Reader = VCFReader = VCF
 
-__version__ = "0.30.0"
+__version__ = "0.30.1"


=====================================
cyvcf2/cyvcf2.pyx
=====================================
@@ -1429,7 +1429,7 @@ cdef class Variant(object):
     def set_format(self, name, np.ndarray data not None):
         """
         set the format field given by name..
-        data must be a numpy array of type float or int
+        data must be a numpy array of type float, int or string (fixed length ASCII np.bytes_)
         """
         cdef int n_samples = self.vcf.n_samples
         if len(data) % n_samples != 0:
@@ -1438,6 +1438,7 @@ cdef class Variant(object):
         cdef np.ndarray[np.float32_t, mode="c"] afloat
         cdef np.ndarray[np.int32_t, mode="c"] aint
         cdef char *bytesp
+        cdef size_t i
 
         cdef int size
         cdef int ret
@@ -1452,6 +1453,10 @@ cdef class Variant(object):
             if len((<object>data).shape) > 1:
                 size *= data.shape[1]
             afloat = data.astype(np.float32).reshape((size,))
+            isnan = np.isnan(afloat)
+            for i in range(size):
+                if isnan[i]:
+                    bcf_float_set(&afloat[i], bcf_float_missing)
             ret = bcf_update_format_float(self.vcf.hdr, self.b, to_bytes(name), &afloat[0], size)
         elif np.issubdtype(data.dtype, np.bytes_):
             if len((<object>data).shape) > 1:


=====================================
cyvcf2/tests/test_reader.py
=====================================
@@ -1125,3 +1125,16 @@ def test_no_seqlen():
     with assert_raises(AttributeError) as ae:
         vcf.seqlens
     assert isinstance(ae.exception, AttributeError)
+
+def test_set_unknown_format():
+    vcf = VCF(VCF_PATH)
+    vcf.add_format_to_header({'ID':'NEW', 'Type':'Float', 'Number':1, 'Description':'...'})
+
+    v = next(vcf)
+    arr = np.array([[1.1] for s in vcf.samples])
+    arr[-1][0] = np.nan
+    v.set_format('NEW', arr)
+    record = str(v)
+    parts = record.split()
+    assert parts[-1][-1] == '.'
+    assert parts[-2][-3:] == '1.1'



View it on GitLab: https://salsa.debian.org/med-team/cyvcf2/-/commit/654e9ee114642f38539caed4deca365556c8009d

-- 
View it on GitLab: https://salsa.debian.org/med-team/cyvcf2/-/commit/654e9ee114642f38539caed4deca365556c8009d
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20201212/9aee9127/attachment-0001.html>


More information about the debian-med-commit mailing list