Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EOFError: read end of file #11

Open
junjunlab opened this issue May 2, 2022 · 1 comment
Open

EOFError: read end of file #11

junjunlab opened this issue May 2, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@junjunlab
Copy link

EOFError: read end of file

Hello, I use while loop to read GFF3 file but I got this error.I do not know how it happens and how to solve it. Here is my code:

# Import the GFF3 module.
using GFF3

exonDict = Dict{String,Int64}()

# Open a GFF3 file.
reader = open(GFF3.Reader, "Homo_sapiens.GRCh38.106.gff3")

# Pre-allocate record.
record = GFF3.Record()

# Iterate over records.
while !eof(reader)
    empty!(record)
    read!(reader,record)
    # do something
    if GFF3.featuretype(record) == "exon"
        transid = split(GFF3.attributes(record,"Parent")[1],":")[2]
        exonLength = abs(GFF3.seqend(record) - GFF3.seqstart(record)) + 1
        # println(exonLength)
        if !haskey(exonDict,transid)
            exonDict[transid] = exonLength
        else
            exonDict[transid] += exonLength
        end
    end
end

# Finally, close the reader.
close(reader)

Thank you for your reply!

@CiaranOMara
Copy link
Member

Your code is reasonable and should work.

In the middle time, you could adjust your loop to use the following, which works because the iterator for the reader catches the EOF error.

for record in reader
    # do something
    if GFF3.featuretype(record) == "exon"
        transid = split(GFF3.attributes(record,"Parent")[1],":")[2]
        exonLength = abs(GFF3.seqend(record) - GFF3.seqstart(record)) + 1
        # println(exonLength)
        if !haskey(exonDict,transid)
            exonDict[transid] = exonLength
        else
            exonDict[transid] += exonLength
        end
    end
end

@CiaranOMara CiaranOMara added the bug Something isn't working label Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants