@@ -476,6 +476,57 @@ VcfEncoder_encode(VcfEncoder *self, PyObject *args)
476
476
return ret ;
477
477
}
478
478
479
+ static PyObject *
480
+ VcfEncoder_encode_all (VcfEncoder * self , PyObject * args )
481
+ {
482
+ bool allowed_threads = false;
483
+
484
+ if (VcfEncoder_check_state (self ) != 0 ) {
485
+ goto out ;
486
+ }
487
+
488
+ Py_BEGIN_ALLOW_THREADS
489
+ allowed_threads = true;
490
+ const size_t num_variants = self -> vcf_encoder -> num_variants ;
491
+ size_t bufsize = 1024 ;
492
+
493
+ for (size_t row = 0 ; row < num_variants ; row ++ ) {
494
+ while (true) {
495
+ char * const buf = PyMem_RawMalloc (bufsize );
496
+
497
+ if (buf == NULL ) {
498
+ PyErr_NoMemory ();
499
+ goto out ;
500
+ }
501
+
502
+ const int64_t line_length = vcz_variant_encoder_encode (
503
+ self -> vcf_encoder , row , buf , bufsize );
504
+
505
+ if (line_length < 0 ) {
506
+ PyMem_RawFree (buf );
507
+
508
+ if (line_length == VCZ_ERR_BUFFER_OVERFLOW ) {
509
+ bufsize *= 2 ;
510
+ } else {
511
+ handle_library_error ((int ) line_length );
512
+ goto out ;
513
+ }
514
+ } else {
515
+ puts (buf );
516
+ PyMem_RawFree (buf );
517
+ break ;
518
+ } // if (line_length < 0)
519
+ } // while (true)
520
+ }
521
+
522
+ out :
523
+ if (allowed_threads ) {
524
+ Py_END_ALLOW_THREADS
525
+ }
526
+
527
+ Py_RETURN_NONE ;
528
+ }
529
+
479
530
static PyObject *
480
531
VcfEncoder_print_state (VcfEncoder * self , PyObject * args )
481
532
{
@@ -546,6 +597,10 @@ static PyMethodDef VcfEncoder_methods[] = {
546
597
.ml_meth = (PyCFunction ) VcfEncoder_encode ,
547
598
.ml_flags = METH_VARARGS ,
548
599
.ml_doc = "Return the specified row of VCF text" },
600
+ { .ml_name = "encode_all" ,
601
+ .ml_meth = (PyCFunction ) VcfEncoder_encode_all ,
602
+ .ml_flags = METH_VARARGS ,
603
+ .ml_doc = "Print all rows of VCF text" },
549
604
{ NULL } /* Sentinel */
550
605
};
551
606
0 commit comments