let expand_header_line l =
let version = ref None in
let sorting_order = ref (Ok `unknown) in
let unknown =
List.filter_map l (function
| ("VN", s) -> version := Some s; None
| "SO", "unknown" -> sorting_order := Ok `unknown; None
| "SO", "unsorted" -> sorting_order := Ok `unsorted; None
| "SO", "queryname" -> sorting_order := Ok `queryname; None
| "SO", "coordinate" -> sorting_order := Ok `coordinate; None
| "SO", any -> sorting_order := Error any; None
| other -> Some other) in
match !version, !sorting_order with
| Some v, Ok so -> Ok (`header_line (v, so, unknown))
| None, _ -> Error (`header_line_without_version l)
| _, Error s -> Error (`header_line_wrong_sorting s)