Skip to content

Commit

Permalink
Merge branch 'release/v1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
CiaranOMara committed Feb 27, 2019
2 parents 4b7fa4a + 08e56ac commit 00a4e7e
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Bedgraph"
uuid = "0bcc2ff6-69eb-520d-bede-0374fc5bd2fd"
authors = ["Ciarán O'Mara <[email protected]>"]
version = "1.0.5"
version = "1.1.0"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ const lasts = [49302300, 49302600, 49302900, 49303200, 49303500, 49303800, 49304
const values = [-1.0, -0.75, -0.50, -0.25, 0.0, 0.25, 0.50, 0.75, 1.00]

records = convert(Vector{Bedgraph.Record}, chroms, firsts, lasts, values)

sort!(records)

header = Bedgraph.generateBasicHeader(records)

write("data.bedgraph", header, records)
Expand All @@ -93,7 +96,7 @@ open(output_file, "w") do io
end

```
### Expansion and compression of data
### Compression and decompression of data

#### Compress data values
Compress data to chromosome coordinates of the zero-based, half-open format.
Expand All @@ -103,30 +106,31 @@ using Bedgraph

chrom "chr1"
n = 49302000:49304700
expanded_values = [-1.0, -1.0, -1.0, ..., 1.00, 1.00, 1.00]
decompressed_values = [-1.0, -1.0, -1.0, ..., 1.00, 1.00, 1.00]

compressed_records = Bedgraph.compress(chrom, n, expanded_values)
compressed_records = Bedgraph.compress(chrom, n, decompressed_values)
```

```julia
using Bedgraph

const records = [Record("chr19", 49302000, 49302300, -1.0), Record("chr19", 49302300, 49302600, -1.75)]

compressed_records = Bedgraph.compress("chr19", n, expanded_value)
compressed_records = Bedgraph.compress("chr19", n, decompressed_value)
```

#### Expand record data
Expand chromosome coordinates from the zero-based, half-open format.
#### Decompress record data
Decompress chromosome coordinates from the zero-based, half-open format.
> **Note:** please be aware of the order of returned items.
```julia
using Bedgraph

const firsts = [49302000, 49302300, 49302600, 49302900, 49303200, 49303500, 49303800, 49304100, 49304400]
const lasts = [49302300, 49302600, 49302900, 49303200, 49303500, 49303800, 49304100, 49304400, 49304700]
const values = [-1.0, -0.75, -0.50, -0.25, 0.0, 0.25, 0.50, 0.75, 1.00]

(n, expanded_values, expanded_chroms) = Bedgraph.expand(chroms, firsts, lasts, values)
(n, decompressed_values, decompressed_chroms) = Bedgraph.expand(chroms, firsts, lasts, values)
```

```julia
Expand All @@ -135,5 +139,5 @@ using Bedgraph

const records = [Record("chr19", 49302000, 49302300, -1.0), Record("chr19", 49302300, 49302600, -1.75)]

n, expanded_values, expanded_chroms = Bedgraph.expand(records)
n, decompressed_values, decompressed_chroms = Bedgraph.expand(records)
```
2 changes: 1 addition & 1 deletion src/header.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function Base.convert(::Type{String}, header::BedgraphHeader{Vector{String}}) ::
return str
end

function generateBasicHeader(records::Vector{Record}; bump_forward=true) :: BedgraphHeader{Vector{String}}
function generateBasicHeader(records::Vector{Record}; bump_forward=true) :: BedgraphHeader{Vector{String}} #Note: we assume that records are sorted by chrom and left position.

chrom = records[1].chrom

Expand Down
14 changes: 14 additions & 0 deletions src/record.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ function Base.:(==)(a::Record, b::Record)
a.value == b.value
end

function Base.isless(a::Record, b::Record, chrom_isless::Function=isless) :: Bool
if a.chrom != b.chrom
return chrom_isless(a.chrom, b.chrom) :: Bool
elseif a.first != b.first
return a.first < b.first
elseif a.last != b.last
return a.last < b.last
elseif a.value != b.value
return a.value < b.value
else
return false
end
end

function Record(data::Vector{String})
return convert(Record, data)
end
Expand Down
17 changes: 17 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,23 @@ end #testset Matching
end #testset Parsing


@testset "Sorting" begin

# Testing isless function.
@test isless(Record(Bag.line1), Record(Bag.line2)) == true
@test isless(Record(Bag.line2), Record(Bag.line1)) == false

unordered = Bag.records[[9,4,5,6,8,7,1,3,2]]

@test Bag.records != unordered
@test Bag.records == sort(unordered)

# Testing sort by concept.
@test Bag.records == sort(unordered, by=x->[x.chrom, x.first, x.last])

end #testset Sorting


@testset "Conversion" begin

@test_throws ErrorException Bedgraph._convertCells([Bag.cells1; "extra_cell"]) == Bag.cells1
Expand Down

0 comments on commit 00a4e7e

Please sign in to comment.