Skip to content

Commit

Permalink
Merge branch 'release/v2.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
CiaranOMara committed Jul 4, 2019
2 parents 390742a + 3f1ed9d commit d7c295a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
11 changes: 6 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "BedgraphFiles"
uuid = "85eb9095-274b-55ce-be28-9e90f41ac741"
authors = ["Ciarán O'Mara <Ciaran.OMara@utas.edu.au>"]
version = "2.1.1"
version = "2.1.2"

[deps]
Bedgraph = "0bcc2ff6-69eb-520d-bede-0374fc5bd2fd"
Expand All @@ -15,19 +15,20 @@ TableTraits = "3783bdb8-4a98-5b6b-af9a-565f29a5fe9c"
TableTraitsUtils = "382cd787-c1b6-5bf2-a167-d5b971a19bda"

[compat]
julia = "0.7, ^1"
Bedgraph = "^1.1"
FileIO = "^1.0.1"
IteratorInterfaceExtensions = "^0.1.1, ^1"
IterableTables = ">=0.9.0"
IteratorInterfaceExtensions = "^0.1.1, ^1"
TableShowUtils = "^0.2.0"
TableTraits = "^0.4, ^1"
TableTraitsUtils = "^0.3, ^0.4"
julia = "0.7, ^1"

[extras]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Query = "1a8c2f83-1ff3-5112-b086-8aa67b057ba1"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"

[targets]
test = ["DataFrames", "Test", "Query"]
test = ["DataFrames", "Test", "Query", "Logging"]
43 changes: 17 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@

## Overview

This package provides load and save support for [Bedgraph files](https://github.com/CiaranOMara/Bedgraph.jl)
under the [FileIO.jl](https://github.com/JuliaIO/FileIO.jl) package.

This package is largely -- if not completely -- inspired by the work of [David Anthoff](https://github.com/davidanthoff).
This package provides load and save support for [Bedgraph](https://github.com/CiaranOMara/Bedgraph.jl)
under the [FileIO](https://github.com/JuliaIO/FileIO.jl) package, and also implements the [IterableTables](https://github.com/davidanthoff/IterableTables.jl) interface for easy conversion between tabular data structures.

## Installation
Install BedgraphFiles from the Julia REPL:
You can install BedgraphFiles from the Julia REPL:
```julia
using Pkg
add("BedgraphFiles")
Expand All @@ -23,21 +21,20 @@ add("BedgraphFiles")

## Usage

### Loading a Bedgraph file

To load a Bedgraph file into a ``Vector{Bedgraph.Record}``, use the following Julia code:
### Loading bedGraph files

To load a bedGraph file into a ``Vector{Bedgraph.Record}``, use the following Julia code:
````julia
using FileIO, BedgraphFiles, Bedgraph

records = Vector{Bedgraph.Record}(load("data.bedgraph"))
````

### Saving a Bedgraph file
### Saving bedGraph files

> **Note:** saving on top of an existing file will overwrite metadata/header information with a minimal working header.
The following example saves a ``Vector{Bedgraph.Record}`` to a Bedgraph file:
The following example saves a ``Vector{Bedgraph.Record}`` to a bedGraph file:
````julia
using FileIO, BedgraphFiles, Bedgraph

Expand All @@ -47,18 +44,16 @@ save("output.bedgraph", records)
````

### IterableTables
The call to ``load`` returns a ``struct`` that is an [IterableTable.jl](https://github.com/davidanthoff/IterableTables.jl), so it can be passed to any function that can handle iterable tables, i.e. all the sinks in [IterableTable.jl](https://github.com/davidanthoff/IterableTables.jl).

To load a Bedgraph file into a `DataFrame`, use the following Julia code:
The execution of ``load`` returns a ``struct`` that adheres to the [IterableTables](https://github.com/davidanthoff/IterableTables.jl) interface, and can be passed to any function that also implements the interface, i.e. all the sinks in [IterableTable.jl](https://github.com/davidanthoff/IterableTables.jl).

The following code shows an example of loading a bedGraph file into a [DataFrame](https://github.com/JuliaData/DataFrames.jl):
```julia
using FileIO, BedgraphFiles, DataFrames

df = DataFrame(load("data.bedgraph"))
```

Here are some examples of materialising a Bedgraph file into data structures that are not a `DataFrame`:

Here are some more examples of materialising a bedGraph file into other data structures:
```julia
using FileIO, BedgraphFiles, DataTables, IndexedTables, Gadfly

Expand All @@ -69,49 +64,45 @@ dt = DataTable(load("data.bedgraph"))
it = IndexedTable(load("data.bedgraph"))

# Plot directly with Gadfly
plot(load("data.bedgraph"), x=:a, y=:b, Geom.line)
plot(load("data.bedgraph"), xmin=:leftposition, xmax=:rightposition, y=:value, Geom.bar)
```

The following code saves any iterable table as a Bedgraph file:
The following code saves any compatible source to a bedGraph file:
```julia
using FileIO, BedgraphFiles

it = getiterator(data)

save("output.bedgraph", it)
```
This will work as long as `it` is any of the types supported as sources in [IterableTables.jl](https://github.com/davidanthoff/IterableTables.jl).


### Using the pipe syntax

Both `load` and `save` also support the pipe syntax. For example, to load a Bedgraph file into a `DataFrame`, one can use the following code:

Both `load` and `save` also support the pipe syntax. For example, to load a bedGraph file into a `DataFrame`, one can use the following code:
```julia
using FileIO, BedgraphFiles, DataFrame

df = load("data.bedgraph") |> DataFrame
```

To save an iterable table, one can use the following form:

```julia
using FileIO, BedgraphFiles, DataFrame

df = # Aquire a DataFrame somehow
df = # Aquire a DataFrame somehow.

df |> save("output.bedgraph")
```

The `save` method returns the data provided or `Vector{Bedgraph.Record}`. This is useful when periodically saving your work during a sequence of operations.

```julia
records = some sequence of operations |> save("output.bedgraph")
```

The pipe syntax is especially useful when combining it with [Query.jl](https://github.com/davidanthoff/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.

The pipe syntax is especially useful when combining it with [Query.jl](https://github.com/davidanthoff/Query.jl) queries. For example, one can easily load a bedGraph file, pipe its data into a query, and then store the query result by piping it to the `save` function.
```julia
using FileIO, BedgraphFiles, Query
load("data.bedgraph") |> @filter(_.chrom == "chr19") |> save("data-chr19.bedgraph")
```
## Acknowledgements
This package is largely -- if not completely -- inspired by the work of [David Anthoff](https://github.com/davidanthoff). Other influences are from the [BioJulia](https://github.com/BioJulia) community.

2 comments on commit d7c295a

@CiaranOMara
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/1788

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v2.1.2 -m "<description of version>" d7c295a0f2673a2b6f508e9135583af3dc5d2581
git push origin v2.1.2

Please sign in to comment.