Class: Bio::BigWig
- Inherits:
-
Object
- Object
- Bio::BigWig
- Defined in:
- lib/bio/bigwig.rb,
lib/bio/bigwig/version.rb,
ext/bio/bigwig/bigwigext.c
Constant Summary collapse
- VERSION =
"0.0.1"
Class Method Summary collapse
Instance Method Summary collapse
- #chroms(*args) ⇒ Object
- #close ⇒ Object
- #entries(chrom, start = 0, stop = -1,, text: true) ⇒ Object
- #file_type ⇒ Object
- #header ⇒ Object
-
#initialize(fname, mode = "r") ⇒ BigWig
constructor
A new instance of BigWig.
- #intervals(chrom, start = 0, stop = -1)) ⇒ Object
- #is_bigbed? ⇒ Boolean
- #is_bigwig? ⇒ Boolean
- #path ⇒ Object
- #sql ⇒ Object
- #stats(chrom, start = nil, stop = nil, nbins: nil, type: nil, exact: nil) ⇒ Object
- #values(chrom, start, stop) ⇒ Object
Constructor Details
#initialize(fname, mode = "r") ⇒ BigWig
Returns a new instance of BigWig.
20 21 22 23 24 25 |
# File 'lib/bio/bigwig.rb', line 20 def initialize(fname, mode = "r") raise "BigWig::new() does not take block; use BigWig::open() instead" if block_given? @fname = fname initialize_raw(fname, mode) end |
Class Method Details
.open(*args, **kwargs) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/bio/bigwig.rb', line 8 def self.open(*args, **kwargs) file = new(*args, **kwargs) return file unless block_given? begin yield file ensure file.close end file end |
Instance Method Details
#chroms(*args) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'ext/bio/bigwig/bigwigext.c', line 201
static VALUE
bw_get_chroms(int argc, VALUE *argv, VALUE self)
{
bigWigFile_t *bw = get_bigWigFile(self);
VALUE rb_chrom, val, ret;
char *chrom = NULL;
uint32_t i;
ret = Qnil; // return nil if no chrom is found
if (!bw)
{
rb_raise(rb_eRuntimeError, "The bigWig file handle is not opened!");
return Qnil;
}
if (bw->isWrite == 1)
{
rb_raise(rb_eRuntimeError, "Chromosomes cannot be accessed in files opened for writing!");
return Qnil;
}
rb_scan_args(argc, argv, "01", &rb_chrom);
if (argc == 0)
{
ret = rb_hash_new();
for (i = 0; i < bw->cl->nKeys; i++)
{
val = ULONG2NUM(bw->cl->len[i]);
rb_hash_aset(ret, rb_str_new2(bw->cl->chrom[i]), val);
}
}
else
{
chrom = StringValueCStr(rb_chrom);
for (i = 0; i < bw->cl->nKeys; i++)
{
if (strcmp(bw->cl->chrom[i], chrom) == 0)
{
ret = ULONG2NUM(bw->cl->len[i]);
break;
}
}
}
return ret;
}
|
#close ⇒ Object
151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'ext/bio/bigwig/bigwigext.c', line 151
static VALUE
bigwig_close(VALUE self)
{
bigWigFile_t *bw = get_bigWigFile(self);
if (bw)
{
bwClose(bw);
DATA_PTR(self) = NULL;
}
return Qnil;
}
|
#entries(chrom, start = 0, stop = -1,, text: true) ⇒ Object
43 44 45 |
# File 'lib/bio/bigwig.rb', line 43 def entries(chrom, start = 0, stop = -1, text: true) entries_raw(chrom, start, stop, text) end |
#file_type ⇒ Object
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 |
# File 'ext/bio/bigwig/bigwigext.c', line 681
static VALUE
bw_get_file_type(VALUE self)
{
bigWigFile_t *bw = get_bigWigFile(self);
if (bw->type == 0)
{
return rb_str_new2("BigWig");
}
else if (bw->type == 1)
{
return rb_str_new2("BigBed");
}
return rb_str_new2("Unknown");
}
|
#header ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'ext/bio/bigwig/bigwigext.c', line 165
static VALUE
bw_get_header(VALUE self)
{
bigWigFile_t *bw = get_bigWigFile(self);
VALUE rb_header;
if (!bw)
{
rb_raise(rb_eRuntimeError, "The bigWig file handle is not opened!");
return Qnil;
}
if (bw->isWrite == 1)
{
rb_raise(rb_eRuntimeError, "The header cannot be accessed in files opened for writing!");
return Qnil;
}
rb_header = rb_hash_new();
// FIXME return int or double?
rb_hash_aset(rb_header, ID2SYM(rb_intern("version")), ULONG2NUM(bw->hdr->version));
rb_hash_aset(rb_header, ID2SYM(rb_intern("levels")), ULONG2NUM(bw->hdr->nLevels));
rb_hash_aset(rb_header, ID2SYM(rb_intern("bases_covered")), ULL2NUM(bw->hdr->nBasesCovered));
rb_hash_aset(rb_header, ID2SYM(rb_intern("min_val")), INT2NUM((int)bw->hdr->minVal));
rb_hash_aset(rb_header, ID2SYM(rb_intern("max_val")), INT2NUM((int)bw->hdr->maxVal));
rb_hash_aset(rb_header, ID2SYM(rb_intern("sum_data")), INT2NUM((int)bw->hdr->sumData));
rb_hash_aset(rb_header, ID2SYM(rb_intern("sum_squared")), INT2NUM((int)bw->hdr->sumSquared));
return rb_header;
error:
rb_raise(rb_eRuntimeError, "Received an error while getting the bigWig header!");
return Qnil;
}
|
#intervals(chrom, start = 0, stop = -1)) ⇒ Object
39 40 41 |
# File 'lib/bio/bigwig.rb', line 39 def intervals(chrom, start = 0, stop = -1) intervals_raw(chrom, start, stop) end |
#is_bigbed? ⇒ Boolean
713 714 715 716 717 718 719 720 721 722 723 724 725 726 |
# File 'ext/bio/bigwig/bigwigext.c', line 713
static VALUE
bw_is_bigbed_q(VALUE self)
{
bigWigFile_t *bw = get_bigWigFile(self);
if (bw->type == 1)
{
return Qtrue;
}
else
{
return Qfalse;
}
}
|
#is_bigwig? ⇒ Boolean
698 699 700 701 702 703 704 705 706 707 708 709 710 711 |
# File 'ext/bio/bigwig/bigwigext.c', line 698
static VALUE
bw_is_bigwig_q(VALUE self)
{
bigWigFile_t *bw = get_bigWigFile(self);
if (bw->type == 0)
{
return Qtrue;
}
else
{
return Qfalse;
}
}
|
#path ⇒ Object
27 28 29 |
# File 'lib/bio/bigwig.rb', line 27 def path @fname end |
#sql ⇒ Object
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 |
# File 'ext/bio/bigwig/bigwigext.c', line 649
static VALUE
bb_get_sql(VALUE self)
{
bigWigFile_t *bw = get_bigWigFile(self);
VALUE ret;
char *str;
if (!bw)
{
rb_raise(rb_eRuntimeError, "The bigBed file handle is not opened!");
return Qnil;
}
if (bw->type == 0)
{
rb_raise(rb_eRuntimeError, "bigWig files have no entries!");
return Qnil;
}
str = bbGetSQL(bw);
if (!str)
{
return Qnil;
}
ret = rb_str_new2(str);
if (str)
free(str);
return ret;
}
|
#stats(chrom, start = nil, stop = nil, nbins: nil, type: nil, exact: nil) ⇒ Object
31 32 33 |
# File 'lib/bio/bigwig.rb', line 31 def stats(chrom, start = nil, stop = nil, nbins: nil, type: nil, exact: nil) stats_raw(chrom, start, stop, nbins, type&.to_s, exact) end |
#values(chrom, start, stop) ⇒ Object
35 36 37 |
# File 'lib/bio/bigwig.rb', line 35 def values(chrom, start, stop) values_raw(chrom, start, stop) end |