# File lib/bio/db/biosql/sequence.rb 205 def primary_accession 206 @entry.accession 207 end
class Bio::SQL::Sequence
Attributes
entry[R]
Public Class Methods
new(options={})
click to toggle source
# File lib/bio/db/biosql/sequence.rb 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
Private Class Methods
bioentry_qualifier_anchor(sym, *args)
click to toggle source
TODO: implement setting for more than a qualifier-vale.
# File lib/bio/db/biosql/sequence.rb 21 def self.bioentry_qualifier_anchor(sym, *args) 22 options = args.first || Hash.new 23 #options.assert_valid_keys(:rank,:synonym,:multi) 24 method_reader = sym.to_s.to_sym 25 method_writer_operator = (sym.to_s+"=").to_sym 26 method_writer_modder = (sym.to_s+"_update").to_sym 27 synonym = options[:synonym].nil? ? sym.to_s : options[:synonym] 28 29 #DELETE #Bio::SQL::Term.create(:name=>synonym, :ontology=> Bio::SQL::Ontology.find_by_name('Annotation Tags')) unless Bio::SQL::Term.exists?(:name =>synonym) 30 send :define_method, method_reader do 31 #return an array of bioentry_qualifier_values 32 begin 33 #DELETE ontology_annotation_tags = Ontology.find_or_create({:name=>'Annotation Tags'}) 34 term = Term.first(:conditions=>["name = ?",synonym]) || Term.create({:name => synonym, :ontology=> Ontology.first(:conditions=>["name = ?",'Annotation Tags'])}) 35 bioentry_qualifier_values = @entry.bioentry_qualifier_values.all(:conditions=>["term_id = ?",term.term_id]) 36 data = bioentry_qualifier_values.map{|row| row.value} unless bioentry_qualifier_values.nil? 37 begin 38 # this block try to check if the data retrived is a 39 # Date or not and change it according to GenBank/EMBL format 40 # in that case return a string 41 # otherwise the [] 42 Date.parse(data.to_s).strftime("%d-%b-%Y").upcase 43 rescue ArgumentError, TypeError, NoMethodError, NameError 44 data 45 end 46 rescue Exception => e 47 puts "Reader Error: #{synonym} #{e.message}" 48 end 49 end 50 51 send :define_method, method_writer_operator do |value| 52 begin 53 #DELETE ontology_annotation_tags = Ontology.find_or_create({:name=>'Annotation Tags'}) 54 term = Term.first(:conditions=>["name = ?",synonym]) || Term.create({:name => synonym, :ontology=> Ontology.first(:conditions=>["name = ?",'Annotation Tags'])}) 55 datas = @entry.bioentry_qualifier_values.all(:conditions=>["term_id = ?",term.term_id]) 56 #add an element incrementing the rank or setting the first to 1 57 be_qu_va=@entry.bioentry_qualifier_values.build({:term=>term, :rank=>(datas.empty? ? 1 : datas.last.rank.succ), :value=>value}) 58 be_qu_va.save 59 rescue Exception => e 60 puts "WriterOperator= Error: #{synonym} #{e.message}" 61 end 62 end 63 64 send :define_method, method_writer_modder do |value, rank| 65 begin 66 #DELETE ontology_annotation_tags = Ontology.find_or_create({:name=>'Annotation Tags'}) 67 term = Term.first(:conditions=>["name = ?",synonym]) || Term.create({:name => synonym, :ontology=> Ontology.first(:conditions=>["name = ?",'Annotation Tags'])}) 68 data = @entry.bioentry_qualifier_values.all(:term_id=>term.term_id, :rank=>rank) 69 if data.nil? 70 send method_writer_operator, value 71 else 72 data.value=value 73 data.save 74 end 75 rescue Exception => e 76 puts "WriterModder Error: #{synonym} #{e.message}" 77 end 78 end 79 80 end
Public Instance Methods
cdsfeatures()
click to toggle source
return the seqfeature mapped from BioSQL with a type_term like 'CDS'
# File lib/bio/db/biosql/sequence.rb 323 def cdsfeatures 324 @entry.cdsfeatures 325 end
comment=(value)
click to toggle source
# File lib/bio/db/biosql/sequence.rb 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()
click to toggle source
# File lib/bio/db/biosql/sequence.rb 393 def comments 394 @entry.comments.map do |comment| 395 comment.comment_text 396 end 397 end
database()
click to toggle source
# File lib/bio/db/biosql/sequence.rb 234 def database 235 @entry.biodatabase.name 236 end
database_desc()
click to toggle source
# File lib/bio/db/biosql/sequence.rb 238 def database_desc 239 @entry.biodatabase.description 240 end
delete()
click to toggle source
# File lib/bio/db/biosql/sequence.rb 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()
click to toggle source
# File lib/bio/db/biosql/sequence.rb 260 def description 261 @entry.description 262 end
Also aliased as: definition
description=(value)
click to toggle source
# File lib/bio/db/biosql/sequence.rb 265 def description=(value) 266 @entry.description=value 267 end
Also aliased as: definition=
division()
click to toggle source
# File lib/bio/db/biosql/sequence.rb 252 def division 253 @entry.division 254 end
division=(value)
click to toggle source
# File lib/bio/db/biosql/sequence.rb 256 def division=(value) 257 @entry.division=value 258 end
feature=(feat)
click to toggle source
# File lib/bio/db/biosql/sequence.rb 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()
click to toggle source
# File lib/bio/db/biosql/sequence.rb 287 def features 288 @entry.seqfeatures.collect do |sf| 289 self.get_seqfeature(sf) 290 end 291 end
get_seqfeature(sf)
click to toggle source
# File lib/bio/db/biosql/sequence.rb 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()
click to toggle source
# File lib/bio/db/biosql/sequence.rb 270 def identifier 271 @entry.identifier 272 end
Also aliased as: other_seqids
identifier=(value)
click to toggle source
# File lib/bio/db/biosql/sequence.rb 275 def identifier=(value) 276 @entry.identifier=value 277 end
length()
click to toggle source
# File lib/bio/db/biosql/sequence.rb 365 def length 366 @entry.biosequence.length 367 end
length=(len)
click to toggle source
# File lib/bio/db/biosql/sequence.rb 102 def length=(len) 103 @entry.biosequence.length=len 104 end
name()
click to toggle source
# File lib/bio/db/biosql/sequence.rb 195 def name 196 @entry.name 197 end
Also aliased as: entry_id
name=(value)
click to toggle source
# File lib/bio/db/biosql/sequence.rb 200 def name=(value) 201 @entry.name=value 202 end
Also aliased as: entry_id=
organism()
click to toggle source
TODO def secondary_accession
@entry.bioentry_qualifier_values end
# File lib/bio/db/biosql/sequence.rb 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
Also aliased as: species
organism=(value)
click to toggle source
# File lib/bio/db/biosql/sequence.rb 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
Also aliased as: species=
primary_accession()
click to toggle source
primary_accession=(value)
click to toggle source
# File lib/bio/db/biosql/sequence.rb 209 def primary_accession=(value) 210 @entry.accession=value 211 end
reference=(value)
click to toggle source
# File lib/bio/db/biosql/sequence.rb 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()
click to toggle source
# File lib/bio/db/biosql/sequence.rb 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(/\|/) if (bio_ref.reference and bio_ref.reference.authors) 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()
click to toggle source
# File lib/bio/db/biosql/sequence.rb 426 def save 427 #I should add chks for SQL errors 428 @entry.biosequence.save 429 @entry.save 430 end
seq()
click to toggle source
Returns the sequence. Returns a Bio::Sequence::Generic object.
# File lib/bio/db/biosql/sequence.rb 330 def seq 331 s = @entry.biosequence 332 Bio::Sequence::Generic.new(s ? s.seq : '') 333 end
seq=(value)
click to toggle source
# File lib/bio/db/biosql/sequence.rb 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
taxonomy()
click to toggle source
report parents and exclude info with “no rank”. Now I report rank == class but … Question ? Have to be reported taxonomy with rank==“class”?
# File lib/bio/db/biosql/sequence.rb 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()
click to toggle source
# File lib/bio/db/biosql/sequence.rb 439 def to_biosequence 440 Bio::Sequence.adapter(self,Bio::Sequence::Adapter::BioSQL) 441 end
to_biosql(bs,biodatabase)
click to toggle source
# File lib/bio/db/biosql/sequence.rb 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()
click to toggle source
# File lib/bio/db/biosql/sequence.rb 431 def to_fasta 432 ">" + accession + "\n" + seq.gsub(Regexp.new(".{1,#{60}}"), "\\0\n") 433 end
to_fasta_reverse_complememt()
click to toggle source
# File lib/bio/db/biosql/sequence.rb 435 def to_fasta_reverse_complememt 436 ">" + accession + "\n" + seq.reverse_complement.gsub(Regexp.new(".{1,#{60}}"), "\\0\n") 437 end
version()
click to toggle source
# File lib/bio/db/biosql/sequence.rb 242 def version 243 @entry.version 244 end
Also aliased as: sequence_version
version=(value)
click to toggle source
# File lib/bio/db/biosql/sequence.rb 247 def version=(value) 248 @entry.version=value 249 end
Also aliased as: sequence_version=