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.Reader
— Type.
BigWig.Reader(input::IO)
Create a reader for bigWig file format.
Note that input
must be seekable.
#
GenomicFeatures.BigWig.chromlist
— Function.
chromlist(reader::BigWig.Reader)::Vector{Tuple{String,Int}}
Get the (name, length)
pairs of chromosomes/contigs.
#
GenomicFeatures.BigWig.values
— Function.
values(reader::BigWig.Reader, interval::Interval)::Vector{Float32}
Get a vector of values within interval
from reader
.
This function fills missing values with NaN32
.
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
.
#
GenomicFeatures.BigWig.Writer
— Type.
BigWig.Writer(output::IO, chromlist; binsize=64, datatype=:bedgraph)
Create a data writer of the bigWig file format.
Arguments
output
: data sinkchromlist
: chromosome list with lengthbinsize=64
: size of a zoom with the highest resolutiondatatype=: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)
#
GenomicFeatures.BigWig.Record
— Type.
BigWig.Record()
Create an unfilled bigWig record.
#
GenomicFeatures.BigWig.chrom
— Function.
chrom(record::Record)::String
Get the chromosome name of record
.
#
GenomicFeatures.BigWig.chromid
— Function.
chromid(record::Record)::UInt32
Get the chromosome ID of record
.
#
GenomicFeatures.BigWig.chromstart
— Function.
chromstart(record::Record)::Int
Get the start position of record
.
#
GenomicFeatures.BigWig.chromend
— Function.
chromend(record::Record)::Int
Get the end position of record
.
#
GenomicFeatures.BigWig.value
— Function.
value(record::Record)::Float32
Get the value of record
.