Skip to content

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
CiaranOMara committed May 9, 2018
2 parents ac9f602 + afed829 commit 31b5338
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 50 deletions.
197 changes: 197 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,200 @@
*.jl.cov
*.jl.*.cov
*.jl.mem
### Linux template
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*
### Windows template
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

/.idea

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/dictionaries
.idea/**/shelf

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# CMake
cmake-build-debug/
cmake-build-release/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests
### Eclipse template

.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders

# External tool builders
.externalToolBuilders/

# Locally stored "Eclipse launch configurations"
*.launch

# PyDev specific (Python IDE for Eclipse)
*.pydevproject

# CDT-specific (C/C++ Development Tooling)
.cproject

# CDT- autotools
.autotools

# Java annotation processor (APT)
.factorypath

# PDT-specific (PHP Development Tools)
.buildpath

# sbteclipse plugin
.target

# Tern plugin
.tern-project

# TeXlipse plugin
.texlipse

# STS (Spring Tool Suite)
.springBeans

# Code Recommenders
.recommenders/

# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet
### Vim template
# Swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]

# Session
Session.vim

# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
### macOS template
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Vim template
# Swap

# Session

# Temporary
# Auto-generated tag files

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ 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:
````julia
using FileIO, BedgraphFiles
Expand Down
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
julia 0.6
TableTraits 0.0.1
IterableTables 0.5.0
FileIO 0.5.1
FileIO 0.6.0
DataFrames 0.9.0
Bedgraph 0.3.0
67 changes: 40 additions & 27 deletions src/BedgraphFiles.jl
Original file line number Diff line number Diff line change
@@ -1,56 +1,69 @@
__precompile__()

module BedgraphFiles

# using Bedgraph
using TableTraits, DataValues, DataFrames
using Bedgraph, TableTraits, IterableTables, DataValues, DataFrames
using FileIO
import IterableTables

try add_format(format"Bedgraph", (), [".bedgraph"], [:BedgraphFiles]) end # TODO: Remove once BedgraphFiles is registered with FileIO.
# try add_format(format"bedGraph", (), [".bedgraph"], [:BedgraphFiles]) end # TODO: Remove once BedgraphFiles is registered with FileIO.

struct BedgraphFile
filename::String
end
BedgraphFile = File{format"bedGraph"}

function load(f::FileIO.File{FileIO.format"Bedgraph"})
return BedgraphFile(f.filename)
function load(file::BedgraphFile)
return BedgraphFile(file.filename)
end

TableTraits.isiterable(x::BedgraphFile) = true
TableTraits.isiterabletable(x::BedgraphFile) = true

function TableTraits.getiterator(file::BedgraphFile)

# TODO: read using bedgraph package.
# df = Bedgraph.read(file.filename, DataFrame)
# Read file using bedgraph package.
tracks = open(file, "r") do stream
Bedgraph.readTracks(stream.io)
end

data = readdlm(file.filename)
# Pack tracks into DataFrame.
df = DataFrame( chrom = Vector{String}() , chromStart = Vector{Int}(), chromEnd = Vector{Int}(), dataValue = Vector{Float64}())

# Track data format: chrom chromStart chromEnd dataValue
df = DataFrame(chrom=data[:,1], chromStart=data[:,2], chromEnd=data[:,3], dataValue=data[:,4])
for track in tracks # Note: Track data format is chrom chrom_start chrom_end data_value.
append!(df, DataFrame(chrom = track.chrom, chromStart = track.chrom_start, chromEnd = track.chrom_end, dataValue = track.data_value))
end

it = getiterator(df)

return it
end

function save(f::FileIO.File{FileIO.format"Bedgraph"}, data)
isiterabletable(data) || error("Can't write this data to a Bedgraph file.")
function save(file::BedgraphFile, data; bump_forward = true)
isiterabletable(data) || error("Can't write this data to bedGraph file.")

it = getiterator(data)

# TODO: save using bedgraph package.
# ds = IterableTables.get_datastreams_source(it)
#
# try
# Bedgraph.write(f.filename, ds)
# finally
# Data.close!(ds)
# end
df = DataFrame(it)

# Pack DataFrame in to a vector of type track.
tracks = Vector{Track}()

for row in eachrow(df)
push!(tracks, Track(row[1], row[2], row[3], row[4])) # Note: using index to allow flexible column names.
end

return save(file, tracks, bump_forward = bump_forward)
end

function save(file::BedgraphFile, tracks::Vector{Bedgraph.Track}; bump_forward = true)

header = Bedgraph.BedgraphHeader( Bedgraph.generateBasicHeader(tracks, bump_forward = bump_forward) )

return save(file, header, tracks)
end

try
output = [convert(Array,it.df[:chrom]) convert(Array,it.df[:chromStart]) convert(Array,it.df[:chromEnd]) convert(Array,it.df[:dataValue]) ]
function save(file::BedgraphFile, header::Bedgraph.BedgraphHeader, tracks::Vector{Bedgraph.Track})

writedlm(f.filename, output)
open(file, "w") do stream
write(stream.io, header)
write(stream.io, tracks)
end

end
Expand Down
9 changes: 9 additions & 0 deletions test/data-headerless.bedgraph
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
chr19 49302000 49302300 -1.0
chr19 49302300 49302600 -0.75
chr19 49302600 49302900 -0.50
chr19 49302900 49303200 -0.25
chr19 49303200 49303500 0.0
chr19 49303500 49303800 0.25
chr19 49303800 49304100 0.50
chr19 49304100 49304400 0.75
chr19 49304400 49304700 1.00
9 changes: 9 additions & 0 deletions test/data.bedgraph
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
browser position chr19:49302001-49304701
browser hide all
browser pack refGene encodeRegions
browser full altGraph
# 300 base wide bar graph, autoScale is on by default == graphing
# limits will dynamically change to always show full range of data
# in viewing window, priority = 20 positions this as the second graph
# Note, zero-relative, half-open coordinate system in use for bedGraph format
track type=bedGraph name="BedGraph Format" description="BedGraph format" visibility=full color=200,100,0 altColor=0,100,200 priority=20
chr19 49302000 49302300 -1.0
chr19 49302300 49302600 -0.75
chr19 49302600 49302900 -0.50
Expand Down
Loading

0 comments on commit 31b5338

Please sign in to comment.