Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in example #9

Open
jpearl01 opened this issue May 18, 2014 · 3 comments
Open

Error in example #9

jpearl01 opened this issue May 18, 2014 · 3 comments

Comments

@jpearl01
Copy link

Hi pjotrp,

Was just trying to get some of your examples to work, and I ran into an issue, essentially I used this file 'short_trial.aln.fasta'

43617/31050-31061
accaatatcgcc
46P47B1/31054-31065
gccaatatcgcc
7169/31137-31148
gccaatatcgcc
B496/31053-31064
gccaatatcgcc
B502/31118-31129
accaatatcgcc
B503/31055-31066
gccaatatcgcc
B507/31052-31063
accaatatcgcc
B508/31057-31068
accaatatcgcc
B583/31081-31092
accaatatcgcc
B615/31109-31120
accaatatcgcc
B616/31296-31307
gccaatattatt
B617/31057-31068
accaatatcgcc
B618/31052-31063
accaatatcgcc
B619/31062-31073
gccaatatcgcc

Then ran these commands in irb:
require 'bio-alignment'
require 'bigbio' # for the Fasta reader
include Bio::BioAlignment # Namespace
aln = Alignment.new
fasta = FastaReader.new('short_trial.aln.fasta')
fasta.each do | rec |
aln.sequences << rec
end
aln[3][0]

And at this point I get the error:
irb(main):012:0> aln[3][0]
NoMethodError: undefined method []' for #<FastaRecord:0x0000000251f3e0> from (irb):12 from /usr/bin/irb:12:in

'
irb(main):013:0> aln[3]
=> #<FastaRecord:0x0000000251f3e0 @id="46P47B1/31054-31065", @Descr="46P47B1/31054-31065", @seq="gccaatatcgcc">

Am I messing this up somehow?

~josh

@pjotrp
Copy link
Owner

pjotrp commented May 18, 2014

Hi Josh,

FastaRecord does not support indexed retrieval. You need to wrap it with a Sequence object. There are some examples in the bio-alignment README.

Pj.

@jpearl01
Copy link
Author

Yeah, I ended up changing the line:

aln.sequence << rec

to

aln.sequences << Sequence.new(rec.descr,rec.seq)

which worked fine. I just wanted to let you know, because in the file doc/bio-alignment-design.md beginning on line 130 there is a code example that appears to do what I was doing above, but would not work.

Thanks,
~josh

@pjotrp
Copy link
Owner

pjotrp commented May 23, 2014

I'll fix that. Note that it would be trivial to add a def [] method to FastaRecord (you can even add that yourself by just reopening the class definition in your source). The reason I don't add it in the original is that I have the policy to add minimal functionality to modules and classes - so as to keep them simple.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants