local file = io.open(arg[1],"rb") -- 19 byte header -- Header file:seek("set", 5) local header = file:read(8) if header ~= "SnapGene" then print("Error: Not a SnapGene file") os.exit() end -- Data type, 1=DNA 2=Protein 3=RNA file:seek("set", 13) local data_type = string.unpack(">I2", file:read(2)) if data_type ~= 1 then print("Error: File does not contain DNA") os.exit() end -- Search blocks for DNA type (ID 0). file:seek("set", 19) while true do local byte = file:read(1) if byte ~= nil then local block_type = string.unpack(">B", byte) local block_length = string.unpack(">I4",file:read(4)) -- check if DNA sequence if block_type ~= 0 then file:seek("cur", block_length) elseif block_type == 0 then -- property byte then sequence of base char bytes -- ignore property byte file:seek("cur", 1) sequence = file:read(block_length-1) io.write(">"..arg[1].." ("..(block_length-1).."bp)\n") io.write(sequence) end else os.exit() end end