From 65210755cc2b66a0bcf0f141a703f301d5a2a85e Mon Sep 17 00:00:00 2001 From: Eric Coissac Date: Thu, 29 Sep 2022 14:48:05 +0200 Subject: [PATCH] Patch reading of annotation from stdin --- pkg/obiformats/fastseq_read.c | 4 ++++ pkg/obiformats/fastseq_read.go | 12 ++++++++++-- pkg/obitools/obiconvert/sequence_reader.go | 6 +++--- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/pkg/obiformats/fastseq_read.c b/pkg/obiformats/fastseq_read.c index 5a06a45..a4bccaa 100644 --- a/pkg/obiformats/fastseq_read.c +++ b/pkg/obiformats/fastseq_read.c @@ -52,6 +52,7 @@ fast_kseq_p open_fast_sek_fd(int fd, bool keep_open, int shift) { fd = dup(fd); fp = gzdopen(fd, "r"); + return _open_fast_sek(fp, shift); } @@ -67,8 +68,11 @@ int64_t next_fast_sek(fast_kseq_t* iterator) { return -3; l = kseq_read(iterator->seq); + if (l < 0) l = 0; + iterator->finished = l==0; if (l>0) l = gzoffset(iterator->filez); + return l; } diff --git a/pkg/obiformats/fastseq_read.go b/pkg/obiformats/fastseq_read.go index 0b3ee7c..372cd69 100644 --- a/pkg/obiformats/fastseq_read.go +++ b/pkg/obiformats/fastseq_read.go @@ -26,8 +26,7 @@ func _FastseqReader(seqfile C.fast_kseq_p, slice := obiseq.MakeBioSequenceSlice() - for l := int64(C.next_fast_sek(seqfile)); l > 0; l = int64(C.next_fast_sek(seqfile)) { - + for l := int64(C.next_fast_sek(seqfile)); l != 0; l = int64(C.next_fast_sek(seqfile)) { s := seqfile.seq sequence := C.GoBytes(unsafe.Pointer(s.seq.s), C.int(s.seq.l)) @@ -77,6 +76,9 @@ func _FastseqReader(seqfile C.fast_kseq_p, i++ ii = 0 } + + // log.Println("longueur : ",l,rep.Length()) + } if len(slice) > 0 { iterator.Push(obiiter.MakeBioSequenceBatch(i, slice)) @@ -148,6 +150,12 @@ func ReadFastSeqBatchFromStdin(options ...WithOption) obiiter.IBioSequenceBatch go _FastseqReader(C.open_fast_sek_stdin(C.int32_t(opt.QualityShift())), newIter, opt.BatchSize()) + parser := opt.ParseFastSeqHeader() + + if parser != nil { + return IParseFastSeqHeaderBatch(newIter, options...) + } + return newIter } diff --git a/pkg/obitools/obiconvert/sequence_reader.go b/pkg/obitools/obiconvert/sequence_reader.go index 6ab8fca..8a29e96 100644 --- a/pkg/obitools/obiconvert/sequence_reader.go +++ b/pkg/obitools/obiconvert/sequence_reader.go @@ -82,7 +82,7 @@ func ReadBioSequencesBatch(filenames ...string) (obiiter.IBioSequenceBatch, erro opts = append(opts, obiformats.OptionsFastSeqHeaderParser(obiformats.ParseGuessedFastSeqHeader)) } - nworkers := obioptions.CLIParallelWorkers() / 4 + nworkers := obioptions.CLIParallelWorkers() // / 4 if nworkers < 2 { nworkers = 2 } @@ -94,7 +94,7 @@ func ReadBioSequencesBatch(filenames ...string) (obiiter.IBioSequenceBatch, erro opts = append(opts, obiformats.OptionsQualityShift(CLIInputQualityShift())) if len(filenames) == 0 { - + log.Printf("Reading sequences from stdin in %s\n", CLIInputFormat()) switch CLIInputFormat() { case "ecopcr": iterator = obiformats.ReadEcoPCRBatch(os.Stdin, opts...) @@ -129,7 +129,7 @@ func ReadBioSequencesBatch(filenames ...string) (obiiter.IBioSequenceBatch, erro if CLINoInputOrder() { nreader = obioptions.CLIParallelWorkers() } - + iterator = obiformats.ReadSequencesBatchFromFiles( filenames, reader,