This package is largely -- if not completely -- inspired by the work of David Anthoff.
Use Pkg.add("BedgraphFiles") in Julia to install BedgraphFiles and its dependencies.
Load a Bedgraph file
To read a Bedgraph file into a
DataFrame, use the following Julia code:
using FileIO, BedgraphFiles, DataFrames df = DataFrame(load("data.bedgraph"))
The call to
load returns a
struct that is an IterableTable.jl, so it can be passed to any function that can handle iterable tables, i.e. all the sinks in IterableTable.jl. Here are some examples of materialising a Bedgraph file into data structures that are not a
using FileIO, BedgraphFiles, DataTables, IndexedTables, Gadfly # Load into a DataTable dt = DataTable(load("data.bedgraph")) # Load into an IndexedTable it = IndexedTable(load("data.bedgraph")) # Plot directly with Gadfly plot(load("data.bedgraph"), x=:a, y=:b, Geom.line)
Save a Bedgraph file
Note: saving on top of an existing file will overwrite metadata/header information with a minimal working header.
The following code saves any iterable table as a Bedgraph file:
using FileIO, BedgraphFiles save("output.bedgraph", it)
This will work as long as
it is any of the types supported as sources in IterableTables.jl.
Using the pipe syntax
save also support the pipe syntax. For example, to load a Bedgraph file into a
DataFrame, one can use the following code:
using FileIO, BedgraphFiles, DataFrame df = load("data.bedgraph") |> DataFrame
To save an iterable table, one can use the following form:
using FileIO, BedgraphFiles, DataFrame df = # Aquire a DataFrame somehow df |> save("output.bedgraph")
The pipe syntax is especially useful when combining it with Query.jl queries, for example one can easily load a Bedgraph file, pipe it into a query, then pipe it to the
save function to store the results in a new file.