Conditional statement stops file writer

Hi, I’m writing code that depends on the FASTX and BioSequences packages.

My hope is that this issue is independent of the packages I am using.

What I am trying to do is very simple… I have a set of fasta entries (A file with a header followed by a sequence, header, sequence, etc…) that I what to extract by a unique ID, which are contained in a set.

When I include this if statement to check for set membership, nothing is written to the file. When I remove the if statement, all the entries are properly written to the file. The remaining code is properly executed in both cases.

My hope is that this issue is independent of the packages I am using. Any ideas?

function getrecords(in::IO,out::IO,s::Set)
    reader,writer = FASTQ.Reader(in),FASTA.Writer(out)
    for record ∈ reader
        id = identifier(record)
        if id ∉ s
            continue
        end 
        seq = sequence(LongRNA{2},record)
        seq = convert(LongDNA{2},seq)
        write(writer,FASTA.Record(id,description(record),seq)) # must specify this for nanopore! 

    end 
    return 
end 

Could it be that the output has not been flushed to file? So if you explicitly call close(out) or flush(out) before returning from the function does that fix it?

1 Like

My first instinct is that id ∉ s is always true

a debugging method could be

if ! (id ∉ s)
   error("ok, some id are in s, this was a bad idea")         
end