- my ( $fh, # file handle
- $cols, # columns to read - OPTIONAL (3,4,5,6,8,9 or 12)
- $check, # check integrity of BED values - OPTIONAL
- ) = @_;
-
- # Returns a hash.
-
- my ( $line, %entry );
-
- $line = <$fh>;
-
- $line =~ tr/\n\r//d; # some people have carriage returns in their BED files -> Grrrr
-
- return if not defined $line;
-
- if ( not defined $cols ) {
- $cols = 1 + $line =~ tr/\t//;
- }
-
- if ( $cols == 3 )
- {
- (
- $entry{ 'chrom' },
- $entry{ 'chromStart' },
- $entry{ 'chromEnd' }
- ) = split "\t", $line, $cols + 1;
- }
- elsif ( $cols == 4 )
- {
- (
- $entry{ 'chrom' },
- $entry{ 'chromStart' },
- $entry{ 'chromEnd' },
- $entry{ 'name' }
- ) = split "\t", $line, $cols + 1;
- }
- elsif ( $cols == 5 )
- {
- (
- $entry{ 'chrom' },
- $entry{ 'chromStart' },
- $entry{ 'chromEnd' },
- $entry{ 'name' },
- $entry{ 'score' }
- ) = split "\t", $line, $cols + 1;
- }
- elsif ( $cols == 6 )
- {
- (
- $entry{ 'chrom' },
- $entry{ 'chromStart' },
- $entry{ 'chromEnd' },
- $entry{ 'name' },
- $entry{ 'score' },
- $entry{ 'strand' }
- ) = split "\t", $line, $cols + 1;
- }
- elsif ( $cols == 8 )
- {
- (
- $entry{ 'chrom' },
- $entry{ 'chromStart' },
- $entry{ 'chromEnd' },
- $entry{ 'name' },
- $entry{ 'score' },
- $entry{ 'strand' },
- $entry{ 'thickStart' },
- $entry{ 'thickEnd' },
- ) = split "\t", $line, $cols + 1;
- }
- elsif ( $cols == 9 )
- {
- (
- $entry{ 'chrom' },
- $entry{ 'chromStart' },
- $entry{ 'chromEnd' },
- $entry{ 'name' },
- $entry{ 'score' },
- $entry{ 'strand' },
- $entry{ 'thickStart' },
- $entry{ 'thickEnd' },
- $entry{ 'itemRgb' },
- ) = split "\t", $line, $cols + 1;
- }
- elsif ( $cols == 12 )
- {
- (
- $entry{ 'chrom' },
- $entry{ 'chromStart' },
- $entry{ 'chromEnd' },
- $entry{ 'name' },
- $entry{ 'score' },
- $entry{ 'strand' },
- $entry{ 'thickStart' },
- $entry{ 'thickEnd' },
- $entry{ 'itemRgb' },
- $entry{ 'blockCount' },
- $entry{ 'blockSizes' },
- $entry{ 'blockStarts' }
- ) = split "\t", $line, $cols + 1;
- }
- else
- {
- Maasha::Common::error( qq(Bad BED entry column count: $cols) );
- }
-
- bed_entry_check( \%entry ) if $check;
-
- return wantarray ? %entry : \%entry;
-}
-
-
-sub bed_entry_get_list
-{
- # Martin A. Hansen, September 2008.
-
- # Reads a BED entry given a filehandle.
-