edit

bigWig

Description

bigWig is a binary file format for associating a floating point number with each base in the genome. bigWig files are indexed to quickly fetch specific regions.

I/O tools for bigWig are provided from the GenomicFeatures.BigWig module, which exports following three types:

  • Reader type: BigWig.Reader
  • Writer type: BigWig.Writer
  • Element type: BigWig.Record

Examples

A common workflow is to open a file, iterate over records, and close the file:

# Import the BigWig module.
using GenomicFeatures

# Open a bigWig file (e.g. mapping depth or coverage).
reader = open(BigWig.Reader, "data.cov.bw")

# Iterate over records overlapping with a query interval.
for record in eachoverlap(reader, Interval("Chr2", 5001, 6000))
    # Extract the start position, end position and value of the record,
    startpos = BigWig.chromstart(record)
    endpos = BigWig.chromend(record)
    value = BigWig.value(record)
    # and do something...
end

# Finally, close the reader.
close(reader)

BigWig.values is a handy function that returns a vector of values. This returns a value per position within the query region:

# Get values in Chr2:5001-6000 as a vector of 1000 elements.
BigWig.values(reader, Interval("Chr2", 5001, 6000))

Iterating over all records is also supported:

reader = open(BigWig.Reader, "data.cov.bw")
for record in reader
    # ...
end
close(reader)

Creating a bigWig can be written as follows:

# Open an output file.
file = open("data.cov.bw", "w")

# Initialize a bigWig writer.
writer = BigWig.Writer(file, [("chr1", 2000), ("chr2", 1000)])

# Write records.
write(writer, ("chr1",   1, 100, 1.0))
write(writer, ("chr1", 101, 200, 2.1))
# ...
write(writer, ("chr2",  51, 150, 3.2))

# Close the writer (this closes the file, too).
close(writer)

API

# GenomicFeatures.BigWig.ReaderType.

BigWig.Reader(input::IO)

Create a reader for bigWig file format.

Note that input must be seekable.

source

# GenomicFeatures.BigWig.chromlistFunction.

chromlist(reader::BigWig.Reader)::Vector{Tuple{String,Int}}

Get the (name, length) pairs of chromosomes/contigs.

source

# GenomicFeatures.BigWig.valuesFunction.

values(reader::BigWig.Reader, interval::Interval)::Vector{Float32}

Get a vector of values within interval from reader.

This function fills missing values with NaN32.

source

values(reader::BigWig.Reader, chrom::AbstractString, range::UnitRange)::Vector{Float32}

Get a vector of values within range of chrom from reader.

This function fills missing values with NaN32.

source

# GenomicFeatures.BigWig.WriterType.

BigWig.Writer(output::IO, chromlist; binsize=64, datatype=:bedgraph)

Create a data writer of the bigWig file format.

Arguments

  • output: data sink
  • chromlist: chromosome list with length
  • binsize=64: size of a zoom with the highest resolution
  • datatype=:bedgraph: encoding of values (:bedgraph, :varstep or :fixedstep)

Examples

output = open("data.bw", "w")
writer = BigWig.Writer(output, [("chr1", 12345), ("chr2", 9100)])
write(writer, ("chr1", 501, 600, 1.0))
write(writer, ("chr2", 301, 450, 3.0))
close(writer)

source

# GenomicFeatures.BigWig.RecordType.

BigWig.Record()

Create an unfilled bigWig record.

source

# GenomicFeatures.BigWig.chromFunction.

chrom(record::Record)::String

Get the chromosome name of record.

source

# GenomicFeatures.BigWig.chromidFunction.

chromid(record::Record)::UInt32

Get the chromosome ID of record.

source

# GenomicFeatures.BigWig.chromstartFunction.

chromstart(record::Record)::Int

Get the start position of record.

source

# GenomicFeatures.BigWig.chromendFunction.

chromend(record::Record)::Int

Get the end position of record.

source

# GenomicFeatures.BigWig.valueFunction.

value(record::Record)::Float32

Get the value of record.

source