class BED extends Regions
Support for parsing, filtering, and manipuulating BED files.
This class provides and implementation for Regions that is backed by a file in BED format.
Some methods hit the file directly, while others rely on reading it into memory. In cases where the data set will not fit into memory, you should check how the method is going to operate and choose accordingly.
Note that the constructor does not load the contents of the BED file. To actually load the BED file you need to call load().
The fourth column of the BED file is referred to as the extra
attribute. This is not loaded by default. You can request that it be loaded
by adding the option withExtra
to either the constructor or
the load() method.
Modifiers | Name | Description |
---|---|---|
class |
BED.1 |
Type | Name and description |
---|---|
java.io.File |
bedFile File from which bed is read |
java.io.InputStream |
bedFileStream The stream from which bed line will be read |
int |
chrColumn Columns for reading the position data - these can be overridden to allow loading of any "bed-like" file |
java.util.List<java.lang.String> |
columnNames |
int |
endColumn |
boolean |
isLoaded Some functions require loading of the BED file into memory. |
boolean |
readColumnNames |
int |
startColumn |
boolean |
withExtra Use 'extra' field to allow additional data to be attached to ranges in the bed file |
boolean |
withProperties If true, column names will be set as properties on the regions |
Constructor and description |
---|
BED
(java.util.Map attributes) Empty bed file |
BED
(java.util.Map attributes, java.lang.String fileName) |
BED
(java.util.Map attributes, java.io.File file, groovy.lang.Closure c) |
BED
(java.util.Map attributes, java.io.InputStream inStream, groovy.lang.Closure c) |
BED
(java.util.Map attributes, java.lang.Iterable<gngs.Region> regions) Create a BED from a list of regions |
Type Params | Return Type | Name and description |
---|---|---|
|
BED |
add(java.lang.String chr, int start, int end, java.lang.Object extra) Add the specified range to this BED file. |
|
static BED |
eachInputRange(groovy.lang.Closure c) |
|
void |
eachLoadedRange(groovy.lang.Closure c) |
|
void |
eachLoadedRange(java.util.Map options, groovy.lang.Closure c) |
|
void |
eachOverlap(java.lang.String chr, int pos, groovy.lang.Closure c) Call closure c for each range that overlaps the given position |
|
void |
eachPosition(groovy.lang.Closure c) Iterate each position in a BED file and call the given closure with it |
|
static void |
eachPosition(java.lang.String fileName, groovy.lang.Closure c) Iterate every single base in the regions of the specified bed file |
|
void |
eachRange(java.util.Map options, groovy.lang.Closure c) Iterate over each line in the BED file and invoke the specified closure with bed file information for the line. |
|
boolean |
isCase(IRegion region) |
|
BED |
load(java.util.Map options) Load the data for this BED file into memory. |
|
static BED |
parse() |
|
static BED |
parse(java.lang.String fileName) |
|
java.lang.String |
toString() |
Methods inherited from class | Name |
---|---|
class Regions |
addRegion, addRegion, backward, balancedSplit, bkr, contains, coverage, distanceTo, distanceTo, eachOverlap, eachRange, eachRange, endingAt, enhance, forward, getAt, getAtIndex, getContigRegions, getExtrasAtPosition, getNumberOfRanges, getOverlapRegions, getOverlaps, getOverlaps, getSpan, intersect, intersect, intersect, intersect, intersectImpl, intersectRegion, intersectRegions, isEmpty, iterator, nearest, nextRange, overlaps, overlaps, overlaps, overlaps, plus, previousRange, reduce, regionsEndingAt, regionsStartingAt, remove, save, save, save, size, startingAt, subtract, subtractFrom, subtractFrom, thin, thinnedIndices, toHTML, toListMap, toString, uniquify, widen, window |
File from which bed is read
The stream from which bed line will be read
Columns for reading the position data - these can be overridden to allow loading of any "bed-like" file
Some functions require loading of the BED file into memory. Others can use it optionally. So keep a flag to know if the BED was loaded, and if it was, use memory for all operations to be faster.
Use 'extra' field to allow additional data to be attached to ranges in the bed file
If true, column names will be set as properties on the regions
Empty bed file
Create a BED from a list of regions
Add the specified range to this BED file.
NOTE: the 'end' is treated as exclusive of the range covered. This is consistent with BED file notation, but different to Groovy ranges. Since most methods in this class use Groovy ranges, you will generally get a Range object out that has end one less than the end you put in with add. Thus if you are iterating through one BED file and adding the ranges to another with this method, you must add one to the end position that you pass to this method!
Will trigger the flag to indicate this BED is loaded in memory.
Call closure c for each range that overlaps the given position
Iterate each position in a BED file and call the given closure with it
NOTE: this only works on an actual BED file, not in-memory BED file. @TODO: merge overlapping regions
Iterate every single base in the regions of the specified bed file
Iterate over each line in the BED file and invoke the specified closure with bed file information for the line.
Options can be provided as a Map argument, including:
Load the data for this BED file into memory.
If withExtra is false, only the range data will be loaded. This is very compact and fast. Otherwise, the optional 4th column will be loaded as well and stored in memory too, as the 'extra' attribute on the GRange objects.
Note: this method returns the same BED object as a result to enable chaining
Groovy Documentation