[BioRuby-cvs] bioruby/lib/bio/io sql.rb,1.5,1.6

Katayama Toshiaki k at dev.open-bio.org
Fri Dec 15 14:24:44 UTC 2006


Update of /home/repository/bioruby/bioruby/lib/bio/io
In directory dev.open-bio.org:/tmp/cvs-serv19598

Modified Files:
	sql.rb 
Log Message:
* a patch contributed from Raoul Pierre Bonnai Jean (RJP)
  which is improved to catch up with the recent BioSQL schema.


Index: sql.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/io/sql.rb,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** sql.rb	19 Sep 2006 05:49:19 -0000	1.5
--- sql.rb	15 Dec 2006 14:24:42 -0000	1.6
***************
*** 3,6 ****
--- 3,7 ----
  #
  # Copyright::  Copyright (C) 2002 Toshiaki Katayama <k at bioruby.org>
+ # Copyright::  Copyright (C) 2006 Raoul Pierre Bonnal Jean <raoul.bonnal at itb.cnr.it>
  # License::    Ruby's
  #
***************
*** 69,74 ****
        return unless row
  
!       mol = row['molecule']
!       seq = row['biosequence_str']
  
        case mol
--- 70,75 ----
        return unless row
  
!       mol = row['alphabet']
!       seq = row['seq']
  
        case mol
***************
*** 83,92 ****
      def subseq(from, to)
        length = to - from + 1
!       query = "select molecule, substring(biosequence_str, ?, ?) as subseq" +
                " from biosequence where bioentry_id = ?"
        row = @dbh.execute(query, from, length, @bioentry_id).fetch
        return unless row
  
!       mol = row['molecule']
        seq = row['subseq']
  
--- 84,93 ----
      def subseq(from, to)
        length = to - from + 1
!       query = "select alphabet, substring(seq, ?, ?) as subseq" +
                " from biosequence where bioentry_id = ?"
        row = @dbh.execute(query, from, length, @bioentry_id).fetch
        return unless row
  
!       mol = row['alphabet']
        seq = row['subseq']
  
***************
*** 108,114 ****
  
          f_id = row['seqfeature_id']
!         k_id = row['seqfeature_key_id']
!         s_id = row['seqfeature_source_id']
!         rank = row['seqfeature_rank'].to_i - 1
  
          # key : type (gene, CDS, ...)
--- 109,115 ----
  
          f_id = row['seqfeature_id']
!         k_id = row['type_term_id']
!         s_id = row['source_term_id']
!         rank = row['rank'].to_i - 1
  
          # key : type (gene, CDS, ...)
***************
*** 143,156 ****
  
          hash = {
!           'start'	=> row['reference_start'],
!           'end'	=> row['reference_end'],
!           'journal'	=> row['reference_location'],
!           'title'	=> row['reference_title'],
!           'authors'	=> row['reference_authors'],
!           'medline'	=> row['reference_medline']
          }
          hash.default = ''
  
!         rank = row['reference_rank'].to_i - 1
          array[rank] = hash
        end
--- 144,157 ----
  
          hash = {
!           'start'	=> row['start_pos'],
!           'end'		=> row['end_pos'],
!           'journal'	=> row['location'],
!           'title'	=> row['title'],
!           'authors'	=> row['authors'],
!           'medline'	=> row['crc']
          }
          hash.default = ''
  
!         rank = row['rank'].to_i - 1
          array[rank] = hash
        end
***************
*** 172,176 ****
        @dbh.execute(query, @bioentry_id).fetch_all.each do |row|
          next unless row
!         rank = row['comment_rank'].to_i - 1
          array[rank] = row['comment_text']
        end
--- 173,177 ----
        @dbh.execute(query, @bioentry_id).fetch_all.each do |row|
          next unless row
!         rank = row['rank'].to_i - 1
          array[rank] = row['comment_text']
        end
***************
*** 211,222 ****
      def taxonomy
        query = <<-END
!         select full_lineage, common_name, ncbi_taxa_id
!         from bioentry_taxa, taxa
!         where bioentry_id = ? and bioentry_taxa.taxa_id = taxa.taxa_id
        END
        row = @dbh.execute(query, @bioentry_id).fetch
!       @lineage = row ? row['full_lineage'] : ''
!       @common_name = row ? row['common_name'] : ''
!       @ncbi_taxa_id = row ? row['ncbi_taxa_id'] : ''
        row ? [@lineage, @common_name, @ncbi_taxa_id] : []
      end
--- 212,223 ----
      def taxonomy
        query = <<-END
!         select taxon_name.name, taxon.ncbi_taxon_id from bioentry
!         join taxon_name using(taxon_id) join taxon using (taxon_id)
!         where bioentry_id = ?
        END
        row = @dbh.execute(query, @bioentry_id).fetch
! #     @lineage = row ? row['full_lineage'] : ''
!       @common_name = row ? row['name'] : ''
!       @ncbi_taxa_id = row ? row['ncbi_taxon_id'] : ''
        row ? [@lineage, @common_name, @ncbi_taxa_id] : []
      end
***************
*** 241,267 ****
  
      def feature_key(k_id)
!       query = "select * from seqfeature_key where seqfeature_key_id = ?"
        row = @dbh.execute(query, k_id).fetch
!       row ? row['key_name'] : ''
      end
  
      def feature_source(s_id)
!       query = "select * from seqfeature_source where seqfeature_source_id = ?"
        row = @dbh.execute(query, s_id).fetch
!       row ? row['source_name'] : ''
      end
  
      def feature_locations(f_id)
        locations = []
!       query = "select * from seqfeature_location where seqfeature_id = ?"
        @dbh.execute(query, f_id).fetch_all.each do |row|
          next unless row
  
          location = Bio::Location.new
!         location.strand = row['seq_strand']
!         location.from = row['seq_start']
!         location.to = row['seq_end']
  
!         xref = feature_locations_remote(row['seqfeature_location_id'])
          location.xref_id = xref.shift unless xref.empty?
  
--- 242,268 ----
  
      def feature_key(k_id)
!       query = "select * from term where term_id= ?"
        row = @dbh.execute(query, k_id).fetch
!       row ? row['name'] : ''
      end
  
      def feature_source(s_id)
!       query = "select * from term where term_id = ?"
        row = @dbh.execute(query, s_id).fetch
!       row ? row['name'] : ''
      end
  
      def feature_locations(f_id)
        locations = []
!       query = "select * from location where seqfeature_id = ?"
        @dbh.execute(query, f_id).fetch_all.each do |row|
          next unless row
  
          location = Bio::Location.new
!         location.strand = row['strand']
!         location.from = row['start_pos']
!         location.to = row['end_pos']
  
!         xref = feature_locations_remote(row['dbxref_if'])
          location.xref_id = xref.shift unless xref.empty?
  
***************
*** 269,273 ****
          #feature_locations_qv(row['seqfeature_location_id'])
  
!         rank = row['location_rank'].to_i - 1
          locations[rank] = location
        end
--- 270,274 ----
          #feature_locations_qv(row['seqfeature_location_id'])
  
!         rank = row['rank'].to_i - 1
          locations[rank] = location
        end
***************
*** 276,280 ****
  
      def feature_locations_remote(l_id)
!       query = "select * from remote_seqfeature_name where seqfeature_location_id = ?"
        row = @dbh.execute(query, l_id).fetch
        row ? [row['accession'], row['version']] : []
--- 277,281 ----
  
      def feature_locations_remote(l_id)
!       query = "select * from  dbxref where dbxref_id = ?"
        row = @dbh.execute(query, l_id).fetch
        row ? [row['accession'], row['version']] : []
***************
*** 282,288 ****
  
      def feature_locations_qv(l_id)
!       query = "select * from location_qualifier_value where seqfeature_location_id = ?"
        row = @dbh.execute(query, l_id).fetch
!       row ? [row['qualifier_value'], row['slot_value']] : []
      end
  
--- 283,289 ----
  
      def feature_locations_qv(l_id)
!       query = "select * from location_qualifier_value where location_id = ?"
        row = @dbh.execute(query, l_id).fetch
!       row ? [row['value'], row['int_value']] : []
      end
  
***************
*** 293,301 ****
          next unless row
  
!         key = feature_qualifiers_key(row['seqfeature_qualifier_id'])
!         value = row['qualifier_value']
          qualifier = Bio::Feature::Qualifier.new(key, value)
  
!         rank = row['seqfeature_qualifier_rank'].to_i - 1
          qualifiers[rank] = qualifier
        end
--- 294,302 ----
          next unless row
  
!         key = feature_qualifiers_key(row['seqfeature_id'])
!         value = row['value']
          qualifier = Bio::Feature::Qualifier.new(key, value)
  
!         rank = row['rank'].to_i - 1
          qualifiers[rank] = qualifier
        end
***************
*** 304,310 ****
  
      def feature_qualifiers_key(q_id)
!       query = "select * from seqfeature_qualifier where seqfeature_qualifier_id = ?"
        row = @dbh.execute(query, q_id).fetch
!       row ? row['qualifier_name'] : ''
      end
    end
--- 305,314 ----
  
      def feature_qualifiers_key(q_id)
!       query = <<-END
!         select * from seqfeature_qualifier_value
!         join term using(term_id) where seqfeature_id = ?
!       END
        row = @dbh.execute(query, q_id).fetch
!       row ? row['name'] : ''
      end
    end




More information about the bioruby-cvs mailing list