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.6"
Class Method Summary collapse
Instance Method Summary collapse
- #chroms(*args) ⇒ Object
- #close ⇒ Object
- #closed? ⇒ Boolean
- #entries(chrom, start = 0, stop = -1,, with_string: 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
0 = BigWig.
- #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
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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'ext/bio/bigwig/bigwigext.c', line 216
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_eIOError, "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;
}
|
#closed? ⇒ Boolean
165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'ext/bio/bigwig/bigwigext.c', line 165
static VALUE
bigwig_is_closed(VALUE self)
{
bigWigFile_t *bw = get_bigWigFile(self);
if (bw)
{
return Qfalse;
}
else
{
return Qtrue;
}
}
|
#entries(chrom, start = 0, stop = -1,, with_string: true) ⇒ Object
43 44 45 |
# File 'lib/bio/bigwig.rb', line 43 def entries(chrom, start = 0, stop = -1, with_string: true) entries_raw(chrom, start, stop, with_string) end |
#file_type ⇒ Object
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 |
# File 'ext/bio/bigwig/bigwigext.c', line 691
static VALUE
bw_get_file_type(VALUE self)
{
bigWigFile_t *bw = get_bigWigFile(self);
if (!bw)
{
rb_raise(rb_eIOError, "The bigWig file handle is not opened!");
return Qnil;
}
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
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'ext/bio/bigwig/bigwigext.c', line 180
static VALUE
bw_get_header(VALUE self)
{
bigWigFile_t *bw = get_bigWigFile(self);
VALUE rb_header;
if (!bw)
{
rb_raise(rb_eIOError, "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
0 = BigWig
741 742 743 744 745 |
# File 'ext/bio/bigwig/bigwigext.c', line 741
static VALUE
bw_is_bigbed_q(VALUE self)
{
return bw_is_file_type(self, 1); // 1 = BigBed
}
|
#is_bigwig? ⇒ Boolean
735 736 737 738 739 |
# File 'ext/bio/bigwig/bigwigext.c', line 735
static VALUE
bw_is_bigwig_q(VALUE self)
{
return bw_is_file_type(self, 0); // 0 = BigWig
}
|
#path ⇒ Object
27 28 29 |
# File 'lib/bio/bigwig.rb', line 27 def path @fname end |
#sql ⇒ Object
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 |
# File 'ext/bio/bigwig/bigwigext.c', line 659
static VALUE
bb_get_sql(VALUE self)
{
bigWigFile_t *bw = get_bigWigFile(self);
VALUE ret;
char *str;
if (!bw)
{
rb_raise(rb_eIOError, "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 |