Class | Bio::SQL::Sequence
In: | lib/bio/db/biosql/sequence.rb
Parent: | Object

### Methods

cdsfeatures comment= comments database database_desc definition definition= delete description description= division division= entry_id entry_id= feature= features get_seqfeature identifier identifier= length length= name name= new organism organism= other_seqids primary_accession primary_accession= reference= references save seq seq= sequence_version sequence_version= species species= taxonomy to_biosequence to_biosql to_fasta to_fasta_reverse_complememt version version=

### Attributes

entry | [R] |

### Public Class methods

new(options={})

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 106
    106:       def initialize(options={})
    107:         #options.assert_valid_keys(:entry, :biodatabase,:biosequence)
    108:         return @entry = options[:entry] unless options[:entry].nil?
    109:
    110:         return to_biosql(options[:biosequence], options[:biodatabase]) unless options[:biosequence].nil? or options[:biodatabase].nil?
    111:
    112:       end

### Public Instance methods

cdsfeatures()

return the seqfeature mapped from BioSQL with a type_term like ‘CDS‘

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 323
    323:       def cdsfeatures
    324:         @entry.cdsfeatures
    325:       end

comment=(value)

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 420
    420:       def comment=(value)
    421:         #DELETE        comment=Comment.new({:bioentry=>@entry, :comment_text=>value, :rank=>@entry.comments.count.succ})
    422:         comment = @entry.comments.build({:comment_text=>value, :rank=>@entry.comments.count.succ})
    423:         comment.save
    424:       end

comments()

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 393
    393:       def comments
    394:         @entry.comments.map do |comment|
    395:           comment.comment_text
    396:         end
    397:       end

database()

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 234
    234:       def database
    235:         @entry.biodatabase.name
    236:       end

database_desc()

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 238
    238:       def database_desc
    239:         @entry.biodatabase.description
    240:       end

definition()

Alias for description

definition=(value)

Alias for description=

delete()

[Source]

        # File lib/bio/db/biosql/sequence.rb, line 85
    85:       def delete
    86:         #TODO: check is references connected to this bioentry are leaf or not.
    87:         #actually I think it should be more sofisticated, check if there are
    88:         #other bioentries connected to references; if not delete 'em
    89:         @entry.references.each { |ref| ref.delete if ref.bioentries.size==1}
    90:         @entry.destroy
    91:       end

description()

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 260
    260:       def description
    261:         @entry.description
    262:       end

description=(value)

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 265
    265:       def description=(value)
    266:         @entry.description=value
    267:       end

division()

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 252
    252:       def division
    253:         @entry.division
    254:       end

division=(value)

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 256
    256:       def division=(value)
    257:         @entry.division=value
    258:       end

entry_id()

Alias for name

entry_id=(value)

Alias for name=

feature=(feat)

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 293
    293:       def feature=(feat)
    294:         #ToDo: avoid Ontology find here, probably more efficient create class variables
    295:         #DELETE        type_term_ontology = Ontology.find_or_create({:name=>'SeqFeature Keys'})
    296:         puts "feature:type_term = #{feat.feature}" if $DEBUG
    297:         type_term = Term.first(:conditions=>["name = ?", feat.feature]) || Term.create({:name=>feat.feature, :ontology=>Ontology.first(:conditions=>["name = ?",'SeqFeature Keys'])})
    298:         #DELETE        source_term_ontology = Ontology.find_or_create({:name=>'SeqFeature Sources'})
    299:         puts "feature:source_term" if $DEBUG
    300:         source_term = Term.first(:conditions=>["name = ?",'EMBLGenBankSwit'])
    301:         puts "feature:seqfeature" if $DEBUG
    302:         seqfeature = @entry.seqfeatures.build({:source_term=>source_term, :type_term=>type_term, :rank=>@entry.seqfeatures.count.succ, :display_name=>''})
    303:         seqfeature.save
    304:         puts "feature:location" if $DEBUG
    305:         feat.locations.each do |loc|
    306:           location = seqfeature.locations.build({:seqfeature=>seqfeature, :start_pos=>loc.from, :end_pos=>loc.to, :strand=>loc.strand, :rank=>seqfeature.locations.count.succ})
    307:           location.save
    308:         end
    309:
    310:         #DELETE        qual_term_ontology = Ontology.find_or_create({:name=>'Annotation Tags'})
    311:
    312:         puts "feature:qualifier" if $DEBUG
    313:         feat.each do |qualifier|
    314:           #DELETE          qual_term = Term.find_or_create({:name=>qualifier.qualifier}, {:ontology=>qual_term_ontology})
    315:           qual_term = Term.first(:conditions=>["name = ?", qualifier.qualifier]) || Term.create({:name=>qualifier.qualifier, :ontology=>Ontology.first(:conditions=>["name = ?", 'Annotation Tags'])})
    316:           qual = seqfeature.seqfeature_qualifier_values.build({:seqfeature=>seqfeature, :term=>qual_term, :value=>qualifier.value.to_s, :rank=>seqfeature.seqfeature_qualifier_values.count.succ})
    317:           qual.save
    318:
    319:         end
    320:       end

features()

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 287
    287:       def features
    288:         @entry.seqfeatures.collect do |sf|
    289:           self.get_seqfeature(sf)
    290:         end
    291:       end

get_seqfeature(sf)

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 93
     93:       def get_seqfeature(sf)
     94:
     95:         #in seqfeature BioSQL class
     96:         locations_str = sf.locations.map{|loc| loc.to_s}.join(',')
     97:         #pp sf.locations.inspect
     98:         locations_str = "join(#{locations_str})" if sf.locations.count>1
     99:         Bio::Feature.new(sf.type_term.name, locations_str,sf.seqfeature_qualifier_values.collect{|sfqv| Bio::Feature::Qualifier.new(sfqv.term.name,sfqv.value)})
    100:       end

identifier()

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 270
    270:       def identifier
    271:         @entry.identifier
    272:       end

identifier=(value)

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 275
    275:       def identifier=(value)
    276:         @entry.identifier=value
    277:       end

length()

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 365
    365:       def length
    366:         @entry.biosequence.length
    367:       end

length=(len)

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 102
    102:       def length=(len)
    103:         @entry.biosequence.length=len
    104:       end

name()

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 195
    195:       def name
    196:         @entry.name
    197:       end

name=(value)

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 200
    200:       def name=(value)
    201:         @entry.name=value
    202:       end

organism()

TODO def secondary_accession

            @entry.bioentry_qualifier_values
          end

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 217
    217:       def organism
    218:         @entry.taxon.nil? ? "" : "#{@entry.taxon.taxon_scientific_name.name}"+ (@entry.taxon.taxon_genbank_common_name ? "(#{@entry.taxon.taxon_genbank_common_name.name})" : '')
    219:       end

organism=(value)

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 222
    222:       def organism=(value)
    223:         #FIX there is a shortcut
    224:         taxon_name=TaxonName.first(:conditions=>["name = ? and name_class = ?",value.gsub(/\s+\(.+\)/,''),'scientific name'])
    225:         if taxon_name.nil?
    226:           puts "Error value doesn't exists in taxon_name table with scientific name constraint."
    227:         else
    228:           @entry.taxon_id=taxon_name.taxon_id
    229:           @entry.save
    230:         end
    231:       end

other_seqids()

Alias for identifier

primary_accession()

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 205
    205:       def primary_accession
    206:         @entry.accession
    207:       end

primary_accession=(value)

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 209
    209:       def primary_accession=(value)
    210:         @entry.accession=value
    211:       end

reference=(value)

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 399
    399:       def reference=(value)
    400:         locations=Array.new
    401:         locations << "journal=#{value.journal}" unless value.journal.empty?
    402:         locations << "volume=#{value.volume}" unless value.volume.empty?
    403:         locations << "issue=#{value.issue}" unless value.issue.empty?
    404:         locations << "pages=#{value.pages}" unless value.pages.empty?
    405:         locations << "year=#{value.year}" unless value.year.empty?
    406:         locations << "pubmed=#{value.pubmed}" unless value.pubmed.empty?
    407:         locations << "medline=#{value.medline}" unless value.medline.empty?
    408:         locations << "doi=#{value.doi}" unless value.doi.nil?
    409:         locations << "abstract=#{value.abstract}" unless value.abstract.empty?
    410:         locations << "url=#{value.url}" unless value.url.nil?
    411:         locations << "mesh=#{value.mesh}" unless value.mesh.empty?
    412:         locations << "affiliations=#{value.affiliations}" unless value.affiliations.empty?
    413:         locations << "comments=#{value.comments.join('~')}"unless value.comments.nil?
    414:         start_pos, end_pos = value.sequence_position ? value.sequence_position.gsub(/\s*/,'').split('-') : [nil,nil]
    415:         reference= Reference.first(:conditions=>["title = ?",value.title]) || Reference.create({:title=>value.title,:authors=>value.authors.join(' '), :location=>locations.join('|')})
    416:         bio_reference=@entry.bioentry_references.build({:reference=>reference,:rank=>value.embl_gb_record_number, :start_pos=>start_pos, :end_pos=>end_pos})
    417:         bio_reference.save
    418:       end

references()

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 369
    369:       def references
    370:         #return and array of hash, hash has these keys ["title", "dbxref_id", "reference_id", "authors", "crc", "location"]
    371:         #probably would be better to d a class refrence to collect these informations
    372:         @entry.bioentry_references.collect do |bio_ref|
    373:           hash = Hash.new
    374:           hash['authors'] = bio_ref.reference.authors.gsub(/\.\s/, "\.\s\|").split(/\|/)
    375:
    376:           hash['sequence_position'] = "#{bio_ref.start_pos}-#{bio_ref.end_pos}" if (bio_ref.start_pos and bio_ref.end_pos)
    377:           hash['title'] = bio_ref.reference.title
    378:           hash['embl_gb_record_number'] = bio_ref.rank
    379:           #TODO: solve the problem with specific comment per reference.
    380:           #TODO: get dbxref
    381:           #take a look when location is build up in def reference=(value)
    382:
    383:           bio_ref.reference.location.split('|').each do |element|
    384:             key,value=element.split('=')
    385:             hash[key]=value
    386:           end unless bio_ref.reference.location.nil?
    387:
    388:           hash['xrefs'] = bio_ref.reference.dbxref ? "#{bio_ref.reference.dbxref.dbname}; #{bio_ref.reference.dbxref.accession}." : ''
    389:           Bio::Reference.new(hash)
    390:         end
    391:       end

save()

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 426
    426:       def save
    427:         #I should add chks for SQL errors
    428:         @entry.biosequence.save
    429:         @entry.save
    430:       end

seq()

Returns the sequence. Returns a Bio::Sequence::Generic object.

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 330
    330:       def seq
    331:         s = @entry.biosequence
    332:         Bio::Sequence::Generic.new(s ? s.seq : '')
    333:       end

seq=(value)

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 335
    335:       def seq=(value)
    336:         #TODO: revise this piece of code.
    337:         #chk which type of alphabet is, NU/NA/nil
    338:         if @entry.biosequence.nil?
    339:           #DELETE          puts "intoseq1"
    340:           @entry.biosequence = Biosequence.new(:seq=>value)
    341:           #          biosequence = @entry.biosequence.build({:seq=>value})
    342:           @entry.biosequence.save
    343:           #          biosequence.save
    344:         else
    345:           @entry.biosequence.seq=value
    346:         end
    347:         self.length=value.length
    348:         #DELETE        #@entry.biosequence.length=value.length
    349:         #DELETE        #break
    350:         @entry.save
    351:       end

sequence_version()

Alias for version

sequence_version=(value)

Alias for version=

species()

Alias for organism

species=(value)

Alias for organism=

taxonomy()

report parents and exclude info with "no rank". Now I report rank == class but … Question ? Have to be reported taxonomy with rank=="class"?

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 354
    354:       def taxonomy
    355:         tax = []
    356:         taxon = Taxon.first(:conditions=>["taxon_id = ?",@entry.taxon.parent_taxon_id])
    357:         while taxon and taxon.taxon_id != taxon.parent_taxon_id and taxon.node_rank!='no rank'
    358:           tax << taxon.taxon_scientific_name.name if taxon.node_rank!='class'
    359:           #Note: I don't like this call very much, correct with a relationship in the ref class.
    360:           taxon = Taxon.first(:conditions=>["taxon_id = ?",taxon.parent_taxon_id])
    361:         end
    362:         tax.reverse
    363:       end

to_biosequence()

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 439
    439:       def to_biosequence
    440:         Bio::Sequence.adapter(self,Bio::Sequence::Adapter::BioSQL)
    441:       end

to_biosql(bs,biodatabase)

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 114
    114:       def to_biosql(bs,biodatabase)
    115:         #DELETE        #Transcaction works greatly!!!
    116:         begin
    117:           #DELETE          Bioentry.transaction do
    118:           @entry = biodatabase.bioentries.build({:name=>bs.entry_id})
    119:
    120:           puts "primary" if $DEBUG
    121:           self.primary_accession = bs.primary_accession
    122:
    123:           puts "def" if $DEBUG
    124:           self.definition = bs.definition unless bs.definition.nil?
    125:
    126:           puts "seqver" if $DEBUG
    127:           self.sequence_version = bs.sequence_version || 0
    128:
    129:           puts "divi" if $DEBUG
    130:           self.division = bs.division unless bs.division.nil?
    131:
    132:           puts "identifier" if $DEBUG
    133:           self.identifier = bs.other_seqids.collect{|dblink| "#{dblink.database}:#{dblink.id}"}.join(';') unless bs.other_seqids.nil?
    134:           @entry.save
    135:           puts "secacc" if $DEBUG
    136:
    137:           bs.secondary_accessions.each do |sa|
    138:             puts "#{sa}" if $DEBUG
    139:             #write as qualifier every secondary accession into the array
    140:             self.secondary_accessions = sa
    141:           end unless bs.secondary_accessions.nil?
    142:
    143:
    144:           #to create the sequence entry needs to exists
    145:           puts "seq" if $DEBUG
    146:           puts bs.seq if $DEBUG
    147:           self.seq = bs.seq unless bs.seq.nil?
    148:           puts "mol" if $DEBUG
    149:
    150:           self.molecule_type = bs.molecule_type unless bs.molecule_type.nil?
    151:           puts "dc" if $DEBUG
    152:
    153:           self.data_class = bs.data_class unless bs.data_class.nil?
    154:           puts "top" if $DEBUG
    155:           self.topology = bs.topology unless bs.topology.nil?
    156:           puts "datec" if $DEBUG
    157:           self.date_created = bs.date_created unless bs.date_created.nil?
    158:           puts "datemod" if $DEBUG
    159:           self.date_modified = bs.date_modified unless bs.date_modified.nil?
    160:           puts "key" if $DEBUG
    161:
    162:           bs.keywords.each do |kw|
    163:             #write as qualifier every secondary accessions into the array
    164:             self.keywords = kw
    165:           end unless bs.keywords.nil?
    166:
    167:           puts "spec" if $DEBUG
    168:           #self.species = bs.species unless bs.species.nil?
    169:           self.species = bs.species unless bs.species.empty?
    170:           puts "Debug: #{bs.species}" if $DEBUG
    171:           puts "Debug: feat..start" if $DEBUG
    172:
    173:           bs.features.each do |feat|
    174:             self.feature=feat
    175:           end unless bs.features.nil?
    176:
    177:           puts "Debug: feat...end" if $DEBUG
    178:           bs.references.each do |reference|
    179:             self.reference=reference
    180:           end unless bs.references.nil?
    181:
    182:           bs.comments.each do |comment|
    183:             self.comment=comment
    184:           end unless bs.comments.nil?
    185:
    186:           #DELETE          end #transaction
    187:           return self
    188:         rescue Exception => e
    189:           puts "to_biosql exception: #{e}"
    190:           puts $!
    191:         end #rescue
    192:       end

to_fasta()

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 431
    431:       def to_fasta
    432:         ">" + accession + "\n" + seq.gsub(Regexp.new(".{1,#{60}}"), "\\0\n")
    433:       end

to_fasta_reverse_complememt()

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 435
    435:       def to_fasta_reverse_complememt
    436:         ">" + accession + "\n" + seq.reverse_complement.gsub(Regexp.new(".{1,#{60}}"), "\\0\n")
    437:       end

version()

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 242
    242:       def version
    243:         @entry.version
    244:       end

version=(value)

[Source]

         # File lib/bio/db/biosql/sequence.rb, line 247
    247:       def version=(value)
    248:         @entry.version=value
    249:       end

[Validate]