Mercurial > repos > mahtabm > ensembl
comparison variant_effect_predictor/Bio/EnsEMBL/Utils/BitString.pm @ 0:1f6dce3d34e0
Uploaded
author | mahtabm |
---|---|
date | Thu, 11 Apr 2013 02:01:53 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:1f6dce3d34e0 |
---|---|
1 =head1 LICENSE | |
2 | |
3 Copyright (c) 1999-2012 The European Bioinformatics Institute and | |
4 Genome Research Limited. All rights reserved. | |
5 | |
6 This software is distributed under a modified Apache license. | |
7 For license details, please see | |
8 | |
9 http://www.ensembl.org/info/about/code_licence.html | |
10 | |
11 =head1 CONTACT | |
12 | |
13 Please email comments or questions to the public Ensembl | |
14 developers list at <dev@ensembl.org>. | |
15 | |
16 Questions may also be sent to the Ensembl help desk at | |
17 <helpdesk@ensembl.org>. | |
18 | |
19 =cut | |
20 | |
21 =head1 NAME | |
22 | |
23 Bio::EnsEMBL::Utils::BitString - bitstring object implementation | |
24 | |
25 =head1 DESCRIPTION | |
26 | |
27 This is an implementation of a bitstring object, taken from Damian | |
28 Convey's book "Object Oriented Perl". | |
29 | |
30 =head1 METHODS | |
31 | |
32 =cut | |
33 | |
34 | |
35 package Bio::EnsEMBL::Utils::BitString; | |
36 | |
37 use strict; | |
38 use warnings; | |
39 no warnings 'uninitialized'; | |
40 | |
41 | |
42 sub new { | |
43 my $class = ref($_[0])||$_[0]; | |
44 my $initbits = join '', map {$_?1:0} @_[1..$#_]; | |
45 my $bs = pack 'b*', $initbits; | |
46 bless \$bs, $class; | |
47 } | |
48 | |
49 | |
50 sub get { | |
51 my ($self, $bitnum) = @_; | |
52 return vec($$self,$bitnum,1); | |
53 } | |
54 | |
55 | |
56 sub set { | |
57 my ($self, $bitnum, $newval) = @_; | |
58 vec($$self,$bitnum,1) = $newval?1:0; | |
59 } | |
60 | |
61 | |
62 sub bitcount { | |
63 8 * length ${$_[0]}; | |
64 } | |
65 | |
66 | |
67 sub complement { | |
68 my ($self) = @_; | |
69 my $complement = ~$$self; | |
70 bless \$complement, ref($self); | |
71 } | |
72 | |
73 | |
74 sub print_me { | |
75 my ($self) = @_; | |
76 for (my $i=0; $i < $self->bitcount(); $i++) | |
77 { | |
78 print $self->get($i); | |
79 print ' ' unless ($i+1)%8; | |
80 print "\n" unless ($i+1)%64; | |
81 } | |
82 print "\n"; | |
83 } | |
84 | |
85 | |
86 1; | |
87 |