# Bioruby-Name error: uninitialized constant

**URL:** <https://www.ruby-forum.com/t/bioruby-name-error-uninitialized-constant/129884>\
**Category:** Ruby\
**Created:** [February 22, 2008, 11:58am UTC](https://www.ruby-forum.com/t/bioruby-name-error-uninitialized-constant/129884 "2008-02-22T11:58:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![calvin76](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9de053/32.png) [@calvin76](https://www.ruby-forum.com/u/calvin76)\
**Post date:** [February 22, 2008, 11:58am UTC](https://www.ruby-forum.com/t/bioruby-name-error-uninitialized-constant/129884/1 "2008-02-22T11:58:33Z")

</div>

I’m very new to both programming in general and to programming in Ruby.

I have tried to write a programme in BioRuby:

require ‘bio’

fasta = open(’…/sequence.fasta’)  
fasta\_string = fasta.read

a = Bio::Alignment::MultiFastaFormat.new(fasta\_string).alignment

a.each\_site do|bases\_at\_site|  
puts bases\_at\_site.join(’’)

When I run the programme in irb, I get the following output:

irb(main):001:0\> require ‘bio’  
=\> true  
irb(main):002:0\>

irb(main):003:0\* fasta = open(’…/sequence.fasta’)  
=\> #\<File:…/sequence.fasta\>

irb(main):004:0\> fasta\_string = fasta.read  
=\> "\>ref|NT\_039674.7|Mm18\_39714\_37:58262030-58293988 Mus musculus  
chromosome 18 genomic contig, strain  
C57BL/6J\r\nTTTCTATTTCAGCAGAAAAAAAAAAAGACGACTAGTCTTTGGGTT  
#I cut out the rest of the file since it’s very long.

irb(main):005:0\>  
irb(main):006:0\* a =  
Bio::Alignment::MultiFastaFormat.new(fasta\_string).alignment  
NameError: uninitialized constant Bio::Alignment::MultiFastaFormat  
from (irb):6

irb(main):007:0\>  
irb(main):008:0\* a.each\_site do|bases\_at\_site|  
irb(main):009:1\* puts bases\_at\_site.join(’’)

The solution is probably very simple, but I have played around with the  
code for half a day now and can’t get any further. I realise that the  
problem is with how I have used Bio::Alignment, but not sure where I  
have gone wrong.

---

<div class="post-metadata">

**Author:** ![calvin76](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9de053/32.png) [@calvin76](https://www.ruby-forum.com/u/calvin76)\
**Post date:** [February 22, 2008, 1:00pm UTC](https://www.ruby-forum.com/t/bioruby-name-error-uninitialized-constant/129884/2 "2008-02-22T13:00:25Z")

</div>

On Fri, Feb 22, 2008 at 11:58 AM, Carl O. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I’m very new to both programming in general and to programming in Ruby.

\> \> The solution is probably very simple, but I have played around with the \> code for half a day now and can't get any further. I realise that the \> problem is with how I have used Bio::Alignment, but not sure where I \> have gone wrong. \>

I don’t know anything about BioRuby, but I took nonetheless a look at  
the gem. Did you take a look at the tutorial? You can view it with the  
gem server. Just type

> gem server  
> in you console and you can access the RDocs of all your installed gems  
> at [http://localhost:8808/](http://localhost:8808/). Maybe you can find your solution there.

Regards, Thomas

---

<div class="post-metadata">

**Author:** ![calvin76](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9de053/32.png) [@calvin76](https://www.ruby-forum.com/u/calvin76)\
**Post date:** [February 22, 2008, 4:53pm UTC](https://www.ruby-forum.com/t/bioruby-name-error-uninitialized-constant/129884/3 "2008-02-22T16:53:34Z")

</div>

I get the same problem if I install with “gem install bioruby” (which  
installs bioruby 0.6.4). If I do “gem install bio”, which installs  
bioruby 1.2.1, I don’t have the problem.

(I didn’t actually try loading anything, but  
Bio::Alignment::MultiFastaFormat produces an uninitialized constant  
error in the first case, and refers to a real class in the second.)

---

<div class="post-metadata">

**Author:** ![calvin76](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9de053/32.png) [@calvin76](https://www.ruby-forum.com/u/calvin76)\
**Post date:** [February 25, 2008, 3:27pm UTC](https://www.ruby-forum.com/t/bioruby-name-error-uninitialized-constant/129884/4 "2008-02-25T15:27:51Z")

</div>

Christopher D. wrote:

> I get the same problem if I install with “gem install bioruby” (which  
> installs bioruby 0.6.4). If I do “gem install bio”, which installs  
> bioruby 1.2.1, I don’t have the problem.
> 
> (I didn’t actually try loading anything, but  
> Bio::Alignment::MultiFastaFormat produces an uninitialized constant  
> error in the first case, and refers to a real class in the second.)

I managed to get rid of the error message by just adding the line:

require ‘rubygems’

as a first line in the code. I’m not sure exactly why this works, but  
the advice was given by one of my supervisors. I don’t have  
administrator’s access to my computer so I cannot install any updates  
without going via the IT department, something that usually takes a  
couple of days.

---

<div class="post-metadata">

**Author:** ![calvin76](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9de053/32.png) [@calvin76](https://www.ruby-forum.com/u/calvin76)\
**Post date:** [February 25, 2008, 11:55pm UTC](https://www.ruby-forum.com/t/bioruby-name-error-uninitialized-constant/129884/5 "2008-02-25T23:55:16Z")

</div>

Carl O. wrote:

> I managed to get rid of the error message by just adding the line:
> 
> require ‘rubygems’
> 
> as a first line in the code. I’m not sure exactly why this works, but  
> the advice was given by one of my supervisors. I don’t have  
> administrator’s access to my computer so I cannot install any updates  
> without going via the IT department, something that usually takes a  
> couple of days.

You must require ‘rubygems’ for any libraries that are installed as  
gems.

-Justin

---

<div class="post-metadata">

**Author:** ![calvin76](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9de053/32.png) [@calvin76](https://www.ruby-forum.com/u/calvin76)\
**Post date:** [February 26, 2008, 12:21am UTC](https://www.ruby-forum.com/t/bioruby-name-error-uninitialized-constant/129884/6 "2008-02-26T00:21:45Z")

</div>

On Mon, Feb 25, 2008 at 11:53 PM, Justin C.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> You must require ‘rubygems’ for any libraries that are installed as gems.

If you don’t set the enviroment variable RUBYOPT to ‘-rubygems’
