Skip to content

Commit

Permalink
Support writing compressed .jplace files
Browse files Browse the repository at this point in the history
checked via:

    pplacer -p -c vaginal_16s.refpkg src/p4z1r36.fasta.gz -o test.jplace.gz
  • Loading branch information
Connor McCoy committed Nov 19, 2013
1 parent b4e10c4 commit d4701a0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
15 changes: 12 additions & 3 deletions common_src/ppatteries.ml
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,24 @@ module MaybeZipped = struct
let lines_of name =
open_in name |> IO.lines_of

(*let open_out name =
let open_out name =
if is_gzipped name then
let out_chan = Gzip.open_out name in
(* Gzip.output doesn't return the number of characters written,
* hence the Buffer wrapping *)
IO.create_out
~write:(Gzip.output_char out_chan)
~output:(Gzip.output out_chan)
~output:(fun s p l ->
let buf = Buffer.create l in
Buffer.add_substring buf s p l;
Gzip.output out_chan (Buffer.contents buf) 0 (Buffer.length buf);
Buffer.length buf)
~close:(fun () -> Gzip.close_out out_chan)
(* Gzip.flush disposes of the Gzip stream and prevents further writes -
* we don't want that, so no action here. *)
~flush:(fun () -> ())
else
File.open_out name*)
File.open_out name
end

(* parsing *)
Expand Down
8 changes: 6 additions & 2 deletions json_src/json.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ let to_string o =
Buffer.contents buf

let to_file name o =
let file = open_out name in
to_formatter (Format.formatter_of_out_channel file) o;
let file = MaybeZipped.open_out name in
let formatter= Format.make_formatter
(fun s p l -> let _ = IO.output file s p l in ())
(fun () -> IO.flush file)
in
to_formatter formatter o;
close_out file
2 changes: 1 addition & 1 deletion pplacer_src/guppy_cmdobjs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ object (self)

method private write_placefile fname pr =
if fname.[0] = '@' then
let name = Filename.chop_extension
let name = MaybeZipped.chop_extension
(String.sub fname 1 ((String.length fname) - 1))
in
placerun_map := SM.add fname (Placerun.set_name pr name) !placerun_map
Expand Down

0 comments on commit d4701a0

Please sign in to comment.