rbfam 0.2.2 → 12.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db1fe9d517d0eb5e3648d3d2dd966d97901bac6c
4
- data.tar.gz: 5397ae4f4d371e7218ecfab08c86de6eda735c4c
3
+ metadata.gz: 73c4a2c6bb2e20a1eeddd818c01199c6aceca461
4
+ data.tar.gz: 7ba0aa6f44ba94fbbf35cc234b7ad257c9dcdf00
5
5
  SHA512:
6
- metadata.gz: 0522f496a7a88c9fe02ec5ab26a6b19a423094f0b08a9d27c9a47d6321cbd07805e76977182009764d48cce81f859bb4c52867b40836b8402bdbb5373d5f60e3
7
- data.tar.gz: 84de980e4ec86fd94aaa7ff6c305e758ecae1600d02dcc6c1319c05295a0980b41a124f7b7cdaae09efca0c411064201c06b6c37497f0be5f611e982a2ed5bf3
6
+ metadata.gz: bef8054a40a26e2f58d2f2e869f3bc8741d469db958066cfd8812117a768c47e7c2b6a1eefe17d125984262f6be47351ef4299848126583328c540bc432e2c8a
7
+ data.tar.gz: 8c32403f117ed54c391c456b6125aa08949fab7ee6dd9f6de25a51028e829300010110135d7393709e2d0e206bbc9ad42827a37a6ba697ee3fdb831c3916719f
@@ -1,93 +1,107 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbfam (0.2.2)
5
- activerecord
6
- activesupport
4
+ rbfam (12.0.0)
5
+ active_record_migrations (~> 4.2, >= 4.2.0.1)
6
+ activerecord (~> 4.2, >= 4.2.0)
7
+ activerecord-import (~> 0.7, >= 0.7.0)
8
+ activesupport (~> 4.2, >= 4.2.0)
7
9
  bio (~> 1.4, >= 1.4.2)
8
10
  bio-stockholm (~> 0.0, >= 0.0.1)
9
- entrez (~> 0.5, >= 0.5.8.1)
10
- httparty (~> 0.8, >= 0.8.3)
11
11
  mysql2 (~> 0.3, >= 0.3.14)
12
- nokogiri (~> 1.6, >= 1.6.1)
13
12
  parallel (~> 1.3, >= 1.3.2)
13
+ ruby-progressbar (~> 1.7, >= 1.7.0)
14
+ virtus (~> 1.0, >= 1.0.3)
14
15
 
15
16
  GEM
16
17
  remote: https://rubygems.org/
17
18
  specs:
18
- actionpack (3.2.21)
19
- activemodel (= 3.2.21)
20
- activesupport (= 3.2.21)
21
- builder (~> 3.0.0)
19
+ actionpack (4.2.0)
20
+ actionview (= 4.2.0)
21
+ activesupport (= 4.2.0)
22
+ rack (~> 1.6.0)
23
+ rack-test (~> 0.6.2)
24
+ rails-dom-testing (~> 1.0, >= 1.0.5)
25
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
26
+ actionview (4.2.0)
27
+ activesupport (= 4.2.0)
28
+ builder (~> 3.1)
22
29
  erubis (~> 2.7.0)
23
- journey (~> 1.0.4)
24
- rack (~> 1.4.5)
25
- rack-cache (~> 1.2)
26
- rack-test (~> 0.6.1)
27
- sprockets (~> 2.2.1)
28
- activemodel (3.2.21)
29
- activesupport (= 3.2.21)
30
- builder (~> 3.0.0)
31
- activerecord (3.2.21)
32
- activemodel (= 3.2.21)
33
- activesupport (= 3.2.21)
34
- arel (~> 3.0.2)
35
- tzinfo (~> 0.3.29)
36
- activesupport (3.2.21)
37
- i18n (~> 0.6, >= 0.6.4)
38
- multi_json (~> 1.0)
39
- arel (3.0.3)
30
+ rails-dom-testing (~> 1.0, >= 1.0.5)
31
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
32
+ active_record_migrations (4.2.0.1)
33
+ activerecord (= 4.2.0)
34
+ railties (= 4.2.0)
35
+ rake
36
+ activemodel (4.2.0)
37
+ activesupport (= 4.2.0)
38
+ builder (~> 3.1)
39
+ activerecord (4.2.0)
40
+ activemodel (= 4.2.0)
41
+ activesupport (= 4.2.0)
42
+ arel (~> 6.0)
43
+ activerecord-import (0.7.0)
44
+ activerecord (>= 3.0)
45
+ activesupport (4.2.0)
46
+ i18n (~> 0.7)
47
+ json (~> 1.7, >= 1.7.7)
48
+ minitest (~> 5.1)
49
+ thread_safe (~> 0.3, >= 0.3.4)
50
+ tzinfo (~> 1.1)
51
+ arel (6.0.0)
40
52
  awesome_print (1.2.0)
53
+ axiom-types (0.1.1)
54
+ descendants_tracker (~> 0.0.4)
55
+ ice_nine (~> 0.11.0)
56
+ thread_safe (~> 0.3, >= 0.3.1)
41
57
  bio (1.4.3.0001)
42
58
  bio-stockholm (0.0.1)
43
- builder (3.0.4)
44
- entrez (0.5.8.1)
45
- httparty
59
+ builder (3.2.2)
60
+ coercible (1.0.0)
61
+ descendants_tracker (~> 0.0.1)
62
+ descendants_tracker (0.0.4)
63
+ thread_safe (~> 0.3, >= 0.3.1)
64
+ equalizer (0.0.9)
46
65
  erubis (2.7.0)
47
66
  gem-release (0.7.3)
48
- hike (1.2.3)
49
- httparty (0.13.3)
50
- json (~> 1.8)
51
- multi_xml (>= 0.5.2)
52
- i18n (0.6.11)
53
- journey (1.0.4)
67
+ i18n (0.7.0)
68
+ ice_nine (0.11.1)
54
69
  json (1.8.1)
55
- mini_portile (0.6.1)
56
- multi_json (1.10.1)
57
- multi_xml (0.5.5)
70
+ loofah (2.0.1)
71
+ nokogiri (>= 1.5.9)
72
+ mini_portile (0.6.2)
73
+ minitest (5.5.0)
58
74
  mysql2 (0.3.17)
59
75
  nokogiri (1.6.5)
60
76
  mini_portile (~> 0.6.0)
61
77
  parallel (1.3.3)
62
- rack (1.4.5)
63
- rack-cache (1.2)
64
- rack (>= 0.4)
65
- rack-ssl (1.3.4)
66
- rack
78
+ rack (1.6.0)
67
79
  rack-test (0.6.2)
68
80
  rack (>= 1.0)
69
- railties (3.2.21)
70
- actionpack (= 3.2.21)
71
- activesupport (= 3.2.21)
72
- rack-ssl (~> 1.3.2)
81
+ rails-deprecated_sanitizer (1.0.3)
82
+ activesupport (>= 4.2.0.alpha)
83
+ rails-dom-testing (1.0.5)
84
+ activesupport (>= 4.2.0.beta, < 5.0)
85
+ nokogiri (~> 1.6.0)
86
+ rails-deprecated_sanitizer (>= 1.0.1)
87
+ rails-html-sanitizer (1.0.1)
88
+ loofah (~> 2.0)
89
+ railties (4.2.0)
90
+ actionpack (= 4.2.0)
91
+ activesupport (= 4.2.0)
73
92
  rake (>= 0.8.7)
74
- rdoc (~> 3.4)
75
- thor (>= 0.14.6, < 2.0)
93
+ thor (>= 0.18.1, < 2.0)
76
94
  rake (10.4.2)
77
- rdoc (3.12.2)
78
- json (~> 1.4)
79
- sprockets (2.2.3)
80
- hike (~> 1.2)
81
- multi_json (~> 1.0)
82
- rack (~> 1.0)
83
- tilt (~> 1.1, != 1.3.0)
84
- standalone_migrations (2.1.5)
85
- activerecord (~> 3.2)
86
- railties (~> 3.2)
87
- rake (~> 10.0)
95
+ ruby-progressbar (1.7.1)
88
96
  thor (0.19.1)
89
- tilt (1.4.1)
90
- tzinfo (0.3.42)
97
+ thread_safe (0.3.4)
98
+ tzinfo (1.2.2)
99
+ thread_safe (~> 0.1)
100
+ virtus (1.0.3)
101
+ axiom-types (~> 0.1)
102
+ coercible (~> 1.0)
103
+ descendants_tracker (~> 0.0, >= 0.0.3)
104
+ equalizer (~> 0.0, >= 0.0.9)
91
105
 
92
106
  PLATFORMS
93
107
  ruby
@@ -98,4 +112,3 @@ DEPENDENCIES
98
112
  gem-release (~> 0.7, >= 0.7.3)
99
113
  rake (~> 10.0)
100
114
  rbfam!
101
- standalone_migrations (~> 2.1, >= 2.1.5)
data/Rakefile CHANGED
@@ -1,3 +1,8 @@
1
1
  require "bundler/gem_tasks"
2
- require "standalone_migrations"
3
- StandaloneMigrations::Tasks.load_tasks
2
+ require "active_record_migrations"
3
+ require "rbfam"
4
+
5
+ ActiveRecordMigrations.load_tasks
6
+
7
+ ActiveRecord::Base.configurations = ActiveRecord::Tasks::DatabaseTasks.database_configuration = Rbfam.db.config
8
+ ActiveRecord::Tasks::DatabaseTasks.env = Rbfam.db.env
@@ -1,4 +1,4 @@
1
- development:
1
+ rbfam:
2
2
  adapter: mysql2
3
3
  database: rbfam
4
4
  username: root
@@ -1,7 +1,7 @@
1
1
  class AddAlignmentTable < ActiveRecord::Migration
2
2
  def up
3
3
  create_table :alignments do |table|
4
- table.timestamps
4
+ table.timestamps null: false
5
5
  table.belongs_to :family
6
6
  table.text :stockholm, limit: 4294967295
7
7
  table.text :consensus_structure
@@ -1,7 +1,7 @@
1
1
  class AddSequenceTable < ActiveRecord::Migration
2
2
  def up
3
3
  create_table :sequences do |table|
4
- table.timestamps
4
+ table.timestamps null: false
5
5
  table.belongs_to :alignment
6
6
  table.string :accession
7
7
  table.text :stripped_sequence
@@ -1,7 +1,7 @@
1
1
  class AddFamilyTable < ActiveRecord::Migration
2
2
  def up
3
3
  create_table :families do |table|
4
- table.timestamps
4
+ table.timestamps null: false
5
5
  table.string :name
6
6
  table.string :description
7
7
  end
@@ -0,0 +1,6 @@
1
+ class DropAlignments < ActiveRecord::Migration
2
+ def change
3
+ drop_table :alignments
4
+ rename_column :sequences, :alignment_id, :family_id
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class AddConsensusStructureToFamilies < ActiveRecord::Migration
2
+ def change
3
+ add_column :families, :consensus_structure, :text
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ class RenameTableAndColumnsForSequence < ActiveRecord::Migration
2
+ def change
3
+ rename_table :sequences, :rnas
4
+ rename_column :rnas, :stripped_sequence, :sequence
5
+ rename_column :rnas, :alignment_sequence, :gapped_sequence
6
+ end
7
+ end
@@ -9,36 +9,29 @@
9
9
  # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10
10
  # you'll amass, the slower it'll run and the greater likelihood for issues).
11
11
  #
12
- # It's strongly recommended to check this file into your version control system.
12
+ # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(:version => 20140114232810) do
14
+ ActiveRecord::Schema.define(version: 20150102192407) do
15
15
 
16
- create_table "alignments", :force => true do |t|
17
- t.datetime "created_at", :null => false
18
- t.datetime "updated_at", :null => false
19
- t.integer "family_id"
20
- t.text "stockholm", :limit => 2147483647
21
- t.text "consensus_structure"
16
+ create_table "families", force: :cascade do |t|
17
+ t.datetime "created_at", null: false
18
+ t.datetime "updated_at", null: false
19
+ t.string "name", limit: 255
20
+ t.string "description", limit: 255
21
+ t.text "consensus_structure", limit: 65535
22
22
  end
23
23
 
24
- create_table "families", :force => true do |t|
25
- t.datetime "created_at", :null => false
26
- t.datetime "updated_at", :null => false
27
- t.string "name"
28
- t.string "description"
29
- end
30
-
31
- add_index "families", ["name"], :name => "index_families_on_name", :unique => true
24
+ add_index "families", ["name"], name: "index_families_on_name", unique: true, using: :btree
32
25
 
33
- create_table "sequences", :force => true do |t|
34
- t.datetime "created_at", :null => false
35
- t.datetime "updated_at", :null => false
36
- t.integer "alignment_id"
37
- t.string "accession"
38
- t.text "stripped_sequence"
39
- t.text "alignment_sequence"
40
- t.integer "from"
41
- t.integer "to"
26
+ create_table "rnas", force: :cascade do |t|
27
+ t.datetime "created_at", null: false
28
+ t.datetime "updated_at", null: false
29
+ t.integer "family_id", limit: 4
30
+ t.string "accession", limit: 255
31
+ t.text "sequence", limit: 65535
32
+ t.text "gapped_sequence", limit: 65535
33
+ t.integer "from", limit: 4
34
+ t.integer "to", limit: 4
42
35
  end
43
36
 
44
37
  end
@@ -0,0 +1,22 @@
1
+ require "rbfam"
2
+ require "activerecord-import/base"
3
+
4
+ puts "Parsing %s to load in DB." % Rbfam.db.rfam_file
5
+ entries = Bio::Stockholm::Reader.parse_from_file(Rbfam.db.rfam_file) and nil
6
+ puts "Loading up %d RFam families." % entries.size
7
+
8
+ Parallel.each(entries, progress: "Populating MySQL") do |stockholm|
9
+ family = Rbfam::Family.find_or_create_by(name: stockholm.gf_features["AC"], description: stockholm.gf_features["DE"], consensus_structure: stockholm.gc_features["SS_cons"])
10
+
11
+ existing_sequences = family.rnas.map { |sequence| sequence.instance_eval { "%s/%d-%d" % [accession, from, to] } }.to_set
12
+ sequences = stockholm.records.reject { |key, _| key == ?# || existing_sequences.include?(key) }.map do |identifier, record|
13
+ accession, from, to = identifier.split(/[\/-]/)
14
+
15
+ Rbfam::Rna.find_or_initialize_by(family: family, accession: accession, from: from, to: to) do |sequence|
16
+ sequence.gapped_sequence = record.sequence.upcase
17
+ sequence.sequence = sequence.gapped_sequence.gsub(/[^AUGC]/, "")
18
+ end
19
+ end
20
+
21
+ Rbfam::Rna.import(sequences.select(&:new_record?))
22
+ end and nil
@@ -2,24 +2,19 @@ require "active_record"
2
2
  require "active_support/inflector"
3
3
  require "bio"
4
4
  require "bio-stockholm"
5
- require "entrez"
6
- require "httparty"
7
- require "json"
8
5
  require "mysql2"
9
6
  require "parallel"
7
+ require "rake"
8
+ require "ruby-progressbar"
9
+ require "singleton"
10
+ require "virtus"
10
11
 
11
- %W|helpers modules|.each do |folder|
12
- Dir[File.join(File.dirname(__FILE__), "rbfam", folder, "*.rb")].each { |name| require "rbfam/#{folder}/#{File.basename(name, '.rb')}" }
13
- end
12
+ require "rbfam/db_config"
13
+ require "rbfam/family"
14
+ require "rbfam/rna"
14
15
 
15
16
  module Rbfam
16
- def self.connect(config: nil)
17
- ActiveRecord::Base.establish_connection(config || YAML.load_file(File.join(File.dirname(__FILE__), "..", "db", "config.yml"))["development"])
18
- end
19
-
20
- def self.script(name)
21
- require "rbfam/scripts/#{File.basename(name, '.rb')}"
17
+ def self.db
18
+ DbConfig.instance
22
19
  end
23
20
  end
24
-
25
- Rbfam::Family.const_set(:READABLE, JSON.parse(File.read(File.join(File.dirname(__FILE__), "rbfam", "helpers", "simple_names.json"))))
@@ -0,0 +1,41 @@
1
+ module Rbfam
2
+ class DbConfig
3
+ include Singleton, Virtus.model
4
+
5
+ attribute :rfam_file, String, default: ->(_, _) { File.join(File.dirname(__FILE__), "..", "..", "rfam_12.seed.utf8") }
6
+ attribute :env, String, default: "rbfam"
7
+ attribute :config, Hash[String => String], default: ->(_, _) { YAML.load_file(File.join(File.dirname(__FILE__), "..", "..", "db", "config.yml")) }
8
+
9
+ def scoped_config
10
+ config[env]
11
+ end
12
+
13
+ def bootstrap!
14
+ load_rakefile
15
+ Rake::Task["db:reset"].invoke
16
+ true
17
+ end
18
+
19
+ def seed!
20
+ load_rakefile
21
+ Rake::Task["db:seed"].invoke
22
+ true
23
+ end
24
+
25
+ def clear!
26
+ load_rakefile
27
+ Rake::Task["db:drop"].invoke
28
+ true
29
+ end
30
+
31
+ def connect
32
+ ActiveRecord::Base.establish_connection(scoped_config)
33
+ end
34
+
35
+ private
36
+
37
+ def load_rakefile
38
+ Rake.load_rakefile(File.join(File.dirname(__FILE__), "..", "..", "Rakefile"))
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,17 @@
1
+ module Rbfam
2
+ class Family < ActiveRecord::Base
3
+ has_many :rnas
4
+
5
+ validates :name, :description, :consensus_structure, presence: true
6
+ validates :name, uniqueness: true
7
+
8
+ def self.rf(id)
9
+ int_id = id.to_i
10
+ find_by_name("RF%s%d" % [?0 * (5 - Math.log10(int_id).ceil), int_id])
11
+ end
12
+
13
+ def self.named(string)
14
+ where(arel_table[:description].matches("%#{string}%"))
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,47 @@
1
+ module Rbfam
2
+ class Rna < ActiveRecord::Base
3
+ belongs_to :family
4
+
5
+ validates :accession, :from, :to, :sequence, :gapped_sequence, presence: true
6
+ validates :from, :to, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
7
+ validates :accession, uniqueness: { scope: [:sequence, :from, :to] }
8
+
9
+ def strand
10
+ plus_strand? ? :plus : :minus
11
+ end
12
+
13
+ def plus_strand?
14
+ to > from
15
+ end
16
+
17
+ def minus_strand?
18
+ !plus_strand?
19
+ end
20
+
21
+ def seq_from
22
+ [from, to].min
23
+ end
24
+
25
+ def seq_to
26
+ [from, to].max
27
+ end
28
+
29
+ alias_method :seq, def sequence
30
+ as_bioseq(read_attribute(:sequence))
31
+ end
32
+
33
+ def gapped_sequence
34
+ as_bioseq(read_attribute(:gapped_sequence))
35
+ end
36
+
37
+ def _id
38
+ ("%s %s %s" % [accession, from, to]).gsub(/\W+/, "_")
39
+ end
40
+
41
+ private
42
+
43
+ def as_bioseq(string)
44
+ Bio::Sequence::NA.new(string).upcase
45
+ end
46
+ end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module Rbfam
2
- VERSION = "0.2.2"
2
+ VERSION = "12.0.0"
3
3
  end
@@ -20,19 +20,19 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.required_ruby_version = ">= 2.0"
22
22
 
23
- spec.add_development_dependency "awesome_print", "~> 1.2.0"
24
- spec.add_development_dependency "bundler", "~> 1.7"
25
- spec.add_development_dependency "gem-release", "~> 0.7", ">= 0.7.3"
26
- spec.add_development_dependency "rake", "~> 10.0"
27
- spec.add_development_dependency "standalone_migrations", "~> 2.1", ">= 2.1.5"
23
+ spec.add_development_dependency "awesome_print", "~> 1.2.0"
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "gem-release", "~> 0.7", ">= 0.7.3"
26
+ spec.add_development_dependency "rake", "~> 10.0"
28
27
 
29
- spec.add_runtime_dependency "activerecord"
30
- spec.add_runtime_dependency "activesupport"
31
- spec.add_runtime_dependency "bio", "~> 1.4", ">= 1.4.2"
32
- spec.add_runtime_dependency "bio-stockholm", "~> 0.0", ">= 0.0.1"
33
- spec.add_runtime_dependency "entrez", "~> 0.5", ">= 0.5.8.1"
34
- spec.add_runtime_dependency "httparty", "~> 0.8", ">= 0.8.3"
35
- spec.add_runtime_dependency "mysql2", "~> 0.3", ">= 0.3.14"
36
- spec.add_runtime_dependency "nokogiri", "~> 1.6", ">= 1.6.1"
37
- spec.add_runtime_dependency "parallel", "~> 1.3", ">= 1.3.2"
28
+ spec.add_runtime_dependency "activerecord", "~> 4.2", ">= 4.2.0"
29
+ spec.add_runtime_dependency "activerecord-import", "~> 0.7", ">= 0.7.0"
30
+ spec.add_runtime_dependency "active_record_migrations", "~> 4.2", ">= 4.2.0.1"
31
+ spec.add_runtime_dependency "activesupport", "~> 4.2", ">= 4.2.0"
32
+ spec.add_runtime_dependency "bio", "~> 1.4", ">= 1.4.2"
33
+ spec.add_runtime_dependency "bio-stockholm", "~> 0.0", ">= 0.0.1"
34
+ spec.add_runtime_dependency "mysql2", "~> 0.3", ">= 0.3.14"
35
+ spec.add_runtime_dependency "parallel", "~> 1.3", ">= 1.3.2"
36
+ spec.add_runtime_dependency "ruby-progressbar", "~> 1.7", ">= 1.7.0"
37
+ spec.add_runtime_dependency "virtus", "~> 1.0", ">= 1.0.3"
38
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbfam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 12.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Senter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-12 00:00:00.000000000 Z
11
+ date: 2015-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -73,193 +73,205 @@ dependencies:
73
73
  - !ruby/object:Gem::Version
74
74
  version: '10.0'
75
75
  - !ruby/object:Gem::Dependency
76
- name: standalone_migrations
76
+ name: activerecord
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '2.1'
81
+ version: '4.2'
82
82
  - - ">="
83
83
  - !ruby/object:Gem::Version
84
- version: 2.1.5
85
- type: :development
84
+ version: 4.2.0
85
+ type: :runtime
86
86
  prerelease: false
87
87
  version_requirements: !ruby/object:Gem::Requirement
88
88
  requirements:
89
89
  - - "~>"
90
90
  - !ruby/object:Gem::Version
91
- version: '2.1'
91
+ version: '4.2'
92
92
  - - ">="
93
93
  - !ruby/object:Gem::Version
94
- version: 2.1.5
94
+ version: 4.2.0
95
95
  - !ruby/object:Gem::Dependency
96
- name: activerecord
96
+ name: activerecord-import
97
97
  requirement: !ruby/object:Gem::Requirement
98
98
  requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '0.7'
99
102
  - - ">="
100
103
  - !ruby/object:Gem::Version
101
- version: '0'
104
+ version: 0.7.0
102
105
  type: :runtime
103
106
  prerelease: false
104
107
  version_requirements: !ruby/object:Gem::Requirement
105
108
  requirements:
109
+ - - "~>"
110
+ - !ruby/object:Gem::Version
111
+ version: '0.7'
106
112
  - - ">="
107
113
  - !ruby/object:Gem::Version
108
- version: '0'
114
+ version: 0.7.0
109
115
  - !ruby/object:Gem::Dependency
110
- name: activesupport
116
+ name: active_record_migrations
111
117
  requirement: !ruby/object:Gem::Requirement
112
118
  requirements:
119
+ - - "~>"
120
+ - !ruby/object:Gem::Version
121
+ version: '4.2'
113
122
  - - ">="
114
123
  - !ruby/object:Gem::Version
115
- version: '0'
124
+ version: 4.2.0.1
116
125
  type: :runtime
117
126
  prerelease: false
118
127
  version_requirements: !ruby/object:Gem::Requirement
119
128
  requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '4.2'
120
132
  - - ">="
121
133
  - !ruby/object:Gem::Version
122
- version: '0'
134
+ version: 4.2.0.1
123
135
  - !ruby/object:Gem::Dependency
124
- name: bio
136
+ name: activesupport
125
137
  requirement: !ruby/object:Gem::Requirement
126
138
  requirements:
127
139
  - - "~>"
128
140
  - !ruby/object:Gem::Version
129
- version: '1.4'
141
+ version: '4.2'
130
142
  - - ">="
131
143
  - !ruby/object:Gem::Version
132
- version: 1.4.2
144
+ version: 4.2.0
133
145
  type: :runtime
134
146
  prerelease: false
135
147
  version_requirements: !ruby/object:Gem::Requirement
136
148
  requirements:
137
149
  - - "~>"
138
150
  - !ruby/object:Gem::Version
139
- version: '1.4'
151
+ version: '4.2'
140
152
  - - ">="
141
153
  - !ruby/object:Gem::Version
142
- version: 1.4.2
154
+ version: 4.2.0
143
155
  - !ruby/object:Gem::Dependency
144
- name: bio-stockholm
156
+ name: bio
145
157
  requirement: !ruby/object:Gem::Requirement
146
158
  requirements:
147
159
  - - "~>"
148
160
  - !ruby/object:Gem::Version
149
- version: '0.0'
161
+ version: '1.4'
150
162
  - - ">="
151
163
  - !ruby/object:Gem::Version
152
- version: 0.0.1
164
+ version: 1.4.2
153
165
  type: :runtime
154
166
  prerelease: false
155
167
  version_requirements: !ruby/object:Gem::Requirement
156
168
  requirements:
157
169
  - - "~>"
158
170
  - !ruby/object:Gem::Version
159
- version: '0.0'
171
+ version: '1.4'
160
172
  - - ">="
161
173
  - !ruby/object:Gem::Version
162
- version: 0.0.1
174
+ version: 1.4.2
163
175
  - !ruby/object:Gem::Dependency
164
- name: entrez
176
+ name: bio-stockholm
165
177
  requirement: !ruby/object:Gem::Requirement
166
178
  requirements:
167
179
  - - "~>"
168
180
  - !ruby/object:Gem::Version
169
- version: '0.5'
181
+ version: '0.0'
170
182
  - - ">="
171
183
  - !ruby/object:Gem::Version
172
- version: 0.5.8.1
184
+ version: 0.0.1
173
185
  type: :runtime
174
186
  prerelease: false
175
187
  version_requirements: !ruby/object:Gem::Requirement
176
188
  requirements:
177
189
  - - "~>"
178
190
  - !ruby/object:Gem::Version
179
- version: '0.5'
191
+ version: '0.0'
180
192
  - - ">="
181
193
  - !ruby/object:Gem::Version
182
- version: 0.5.8.1
194
+ version: 0.0.1
183
195
  - !ruby/object:Gem::Dependency
184
- name: httparty
196
+ name: mysql2
185
197
  requirement: !ruby/object:Gem::Requirement
186
198
  requirements:
187
199
  - - "~>"
188
200
  - !ruby/object:Gem::Version
189
- version: '0.8'
201
+ version: '0.3'
190
202
  - - ">="
191
203
  - !ruby/object:Gem::Version
192
- version: 0.8.3
204
+ version: 0.3.14
193
205
  type: :runtime
194
206
  prerelease: false
195
207
  version_requirements: !ruby/object:Gem::Requirement
196
208
  requirements:
197
209
  - - "~>"
198
210
  - !ruby/object:Gem::Version
199
- version: '0.8'
211
+ version: '0.3'
200
212
  - - ">="
201
213
  - !ruby/object:Gem::Version
202
- version: 0.8.3
214
+ version: 0.3.14
203
215
  - !ruby/object:Gem::Dependency
204
- name: mysql2
216
+ name: parallel
205
217
  requirement: !ruby/object:Gem::Requirement
206
218
  requirements:
207
219
  - - "~>"
208
220
  - !ruby/object:Gem::Version
209
- version: '0.3'
221
+ version: '1.3'
210
222
  - - ">="
211
223
  - !ruby/object:Gem::Version
212
- version: 0.3.14
224
+ version: 1.3.2
213
225
  type: :runtime
214
226
  prerelease: false
215
227
  version_requirements: !ruby/object:Gem::Requirement
216
228
  requirements:
217
229
  - - "~>"
218
230
  - !ruby/object:Gem::Version
219
- version: '0.3'
231
+ version: '1.3'
220
232
  - - ">="
221
233
  - !ruby/object:Gem::Version
222
- version: 0.3.14
234
+ version: 1.3.2
223
235
  - !ruby/object:Gem::Dependency
224
- name: nokogiri
236
+ name: ruby-progressbar
225
237
  requirement: !ruby/object:Gem::Requirement
226
238
  requirements:
227
239
  - - "~>"
228
240
  - !ruby/object:Gem::Version
229
- version: '1.6'
241
+ version: '1.7'
230
242
  - - ">="
231
243
  - !ruby/object:Gem::Version
232
- version: 1.6.1
244
+ version: 1.7.0
233
245
  type: :runtime
234
246
  prerelease: false
235
247
  version_requirements: !ruby/object:Gem::Requirement
236
248
  requirements:
237
249
  - - "~>"
238
250
  - !ruby/object:Gem::Version
239
- version: '1.6'
251
+ version: '1.7'
240
252
  - - ">="
241
253
  - !ruby/object:Gem::Version
242
- version: 1.6.1
254
+ version: 1.7.0
243
255
  - !ruby/object:Gem::Dependency
244
- name: parallel
256
+ name: virtus
245
257
  requirement: !ruby/object:Gem::Requirement
246
258
  requirements:
247
259
  - - "~>"
248
260
  - !ruby/object:Gem::Version
249
- version: '1.3'
261
+ version: '1.0'
250
262
  - - ">="
251
263
  - !ruby/object:Gem::Version
252
- version: 1.3.2
264
+ version: 1.0.3
253
265
  type: :runtime
254
266
  prerelease: false
255
267
  version_requirements: !ruby/object:Gem::Requirement
256
268
  requirements:
257
269
  - - "~>"
258
270
  - !ruby/object:Gem::Version
259
- version: '1.3'
271
+ version: '1.0'
260
272
  - - ">="
261
273
  - !ruby/object:Gem::Version
262
- version: 1.3.2
274
+ version: 1.0.3
263
275
  description: Light wrapper for RFam data in Ruby.
264
276
  email:
265
277
  - evansenter@gmail.com
@@ -276,17 +288,16 @@ files:
276
288
  - db/migrate/20140114232757_add_alignment_table.rb
277
289
  - db/migrate/20140114232805_add_sequence_table.rb
278
290
  - db/migrate/20140114232810_add_family_table.rb
291
+ - db/migrate/20150102185134_drop_alignments.rb
292
+ - db/migrate/20150102185348_add_consensus_structure_to_families.rb
293
+ - db/migrate/20150102192407_rename_table_and_columns_for_sequence.rb
279
294
  - db/schema.rb
295
+ - db/seeds.rb
280
296
  - lib/rbfam.rb
281
- - lib/rbfam/helpers/common.rb
282
- - lib/rbfam/helpers/simple_names.json
283
- - lib/rbfam/modules/alignment.rb
284
- - lib/rbfam/modules/family.rb
285
- - lib/rbfam/modules/sequence.rb
286
- - lib/rbfam/modules/utils.rb
287
- - lib/rbfam/scripts/sequences_in_mysql.rb
297
+ - lib/rbfam/db_config.rb
298
+ - lib/rbfam/family.rb
299
+ - lib/rbfam/rna.rb
288
300
  - lib/rbfam/version.rb
289
- - load_rbfam_seed.rb
290
301
  - rbfam.gemspec
291
302
  - rfam_12.seed.utf8
292
303
  homepage: ''
@@ -1,18 +0,0 @@
1
- module Rbfam
2
- module CommonHelpers
3
- def self.included(base)
4
- base.send(:include, InstanceMethods)
5
- end
6
-
7
- module InstanceMethods
8
- def bootstrap!(options = {})
9
- tap { load_entries!(options) }
10
- end
11
-
12
- def entries!(options = {})
13
- remove_instance_variable(:@parsed_entries)
14
- entries(options)
15
- end
16
- end
17
- end
18
- end
@@ -1,11 +0,0 @@
1
- {
2
- "purine": "RF00167",
3
- "tpp": "RF00059",
4
- "secis_1": "RF00031",
5
- "trna": "RF00005",
6
- "let_7": "RF00027",
7
- "snora71": "RF00056",
8
- "u7": "RF00066",
9
- "rose": "RF00435",
10
- "hammerhead_3": "RF00008"
11
- }
@@ -1,60 +0,0 @@
1
- module Rbfam
2
- class Alignment
3
- include Rbfam::CommonHelpers
4
-
5
- LINE_REGEXP = /^([\w\.]+)\/(\d+)\-(\d+)\s+([AUGC\.]+)$/
6
-
7
- attr_reader :family, :seed
8
-
9
- def initialize(family)
10
- @family = family
11
- end
12
-
13
- def entries(options = {})
14
- options = { alignment: :seed, limit: false }.merge(options)
15
-
16
- @parsed_entries ||= (pull_from_server(options[:alignment]) || "").split(/\n/).reject do |line|
17
- line =~ /^#/
18
- end.select do |line|
19
- line =~ LINE_REGEXP
20
- end[options[:limit] ? 0...options[:limit] : 0..-1].map(&method(:parse_line)).tap do
21
- @seed = options[:alignment] == :seed
22
- end
23
- end
24
-
25
- def save_entries!
26
- entries.each { |sequence| sequence.save!(seed: seed) }
27
- end
28
-
29
- def load_entries!(options = {})
30
- @parsed_entries = family.load_entries!(options)
31
- end
32
-
33
- private
34
-
35
- def pull_from_server(alignment)
36
- url = "http://rfam.sanger.ac.uk/family/alignment/download/format?acc=%s&alnType=%s&nseLabels=1&format=pfam&download=0" % [
37
- family.family_name,
38
- alignment
39
- ]
40
- puts "GET: %s" % url unless @reponse
41
-
42
- @response ||= if (party = HTTParty.get(url)).response.code == "200"
43
- puts "RESPONSE: 200 OK"
44
- party.parsed_response
45
- else
46
- raise RuntimeError.new("HTTParty raised the following error when retrieving alignment %s: %s %s" % [
47
- family_name,
48
- party.response.code,
49
- party.response.message
50
- ])
51
- end
52
- end
53
-
54
- def parse_line(line)
55
- line_match = line.match(LINE_REGEXP)
56
-
57
- Rbfam::Sequence.new(family, line_match[1], line_match[2].to_i, line_match[3].to_i, autoload: true)
58
- end
59
- end
60
- end
@@ -1,70 +0,0 @@
1
- module Rbfam
2
- class Family
3
- include Rbfam::CommonHelpers
4
-
5
- attr_reader :family_name, :description
6
-
7
- class << self
8
- def method_missing(name, *args, &block)
9
- READABLE[name.to_s] ? new(READABLE[name.to_s]) : super
10
- end
11
- end
12
-
13
- def initialize(family_name, description = "")
14
- @family_name = family_name
15
- @description = description
16
- end
17
-
18
- def id
19
- ("%s %s" % [family_name, description.downcase]).strip.gsub(/\W+/, "_")
20
- end
21
-
22
- def alignment
23
- Rbfam::Alignment.new(self)
24
- end
25
-
26
- def entries(options = {})
27
- options = { limit: false }.merge(options)
28
-
29
- @parsed_entries ||= pull_from_server.split(/\n/).reject { |line| line =~ /^#/ }[options[:limit] ? 0...options[:limit] : 0..-1].map(&method(:parse_line))
30
- end
31
-
32
- def load_entries!(options = {})
33
- Rbfam.script("sequences_in_mysql")
34
-
35
- Rbfam::DB::Sequence.joins(alignment: :family).where(families: { name: family_name }.merge(options)).map do |entry|
36
- entry.to_rbfam(self)
37
- end
38
- end
39
-
40
- def save_entries!
41
- entries.each(&:save!)
42
- end
43
-
44
- private
45
-
46
- def pull_from_server
47
- # It isn't the greatest design pattern to memoize a block where a branch has unmanaged exception raising, but for my uses that should never
48
- # happen and needs to blow up hard if it does.
49
- url = "http://rfam.sanger.ac.uk/family/regions?entry=%s" % family_name
50
- puts "GET: %s" % url unless @reponse
51
-
52
- @reponse ||= if (party = HTTParty.get(url)).response.code == "200"
53
- puts "RESPONSE: 200 OK"
54
- party.parsed_response
55
- else
56
- raise RuntimeError.new("HTTParty raised the following error when retrieving family %s: %s %s" % [
57
- family_name,
58
- party.response.code,
59
- party.response.message
60
- ])
61
- end
62
- end
63
-
64
- def parse_line(line)
65
- split_line = line.split(/\t/)
66
-
67
- Rbfam::Sequence.new(self, split_line[0], split_line[2].to_i, split_line[3].to_i, autoload: true)
68
- end
69
- end
70
- end
@@ -1,114 +0,0 @@
1
- module Rbfam
2
- class Sequence < ActiveRecord::Base
3
- attr_reader :family, :accession, :from, :to, :coord_options
4
-
5
- def initialize(family, accession, from, to, options = {})
6
- @family = family
7
- @accession = accession
8
- @from = from
9
- @to = to
10
- @coord_options = options[:autoload].is_a?(Hash) ? options[:autoload] : {}
11
-
12
- if options[:sequence]
13
- @raw_sequence = (options[:sequence].is_a?(String) ? Bio::Sequence::NA.new(options[:sequence]) : options[:sequence]).upcase
14
- end
15
-
16
- if options[:autoload]
17
- sequence
18
- end
19
- end
20
-
21
- def save!(options = {})
22
- unless extended?
23
- Rbfam.script("sequences_in_mysql")
24
-
25
- SequenceTable.create({
26
- family: family.family_name,
27
- accession: accession,
28
- sequence: sequence,
29
- sequence_length: sequence.length,
30
- from: from,
31
- to: to,
32
- seq_from: seq_from,
33
- seq_to: seq_to,
34
- seed: options[:seed]
35
- })
36
- else
37
- tap { puts "ERROR: at this time you can not save #{self.class.name}#extend! objects to protect against DB redundancy (and I'm lazy)." }
38
- end
39
- end
40
-
41
- def up_coord
42
- [from, to].min
43
- end
44
-
45
- def down_coord
46
- [from, to].max
47
- end
48
-
49
- def seq_from
50
- up_coord + coord_window.min
51
- end
52
-
53
- def seq_to
54
- up_coord + coord_window.max
55
- end
56
-
57
- def strand
58
- plus_strand? ? :plus : :minus
59
- end
60
-
61
- def plus_strand?
62
- to > from
63
- end
64
-
65
- def minus_strand?
66
- !plus_strand?
67
- end
68
-
69
- alias_method :seq, def sequence
70
- @raw_sequence ||= Rbfam::Utils.rna_sequence_from_entrez(accession, up_coord, coord_window)
71
- @raw_sequence = minus_strand? ? @raw_sequence.complement : @raw_sequence
72
- end
73
-
74
- def description
75
- ("%s %s %s" % [accession, from, to]).gsub(/\W+/, "_")
76
- end
77
-
78
- def extend!(coord_options = {})
79
- tap do
80
- @extended = true
81
- @coord_options = coord_options
82
- remove_instance_variable(:@raw_sequence)
83
- sequence
84
- end
85
- end
86
-
87
- def extended?
88
- @extended
89
- end
90
-
91
- def coord_window
92
- # Options from coord_options ex: { length: 300, extend: 3 }, or { length: 250, extend: :both }
93
- range = 0..(down_coord - up_coord)
94
-
95
- if coord_options[:length] && coord_options[:direction]
96
- if coord_options[:direction] == :both
97
- Range.new(range.min - coord_options[:length], range.max + coord_options[:length])
98
- else
99
- case [coord_options[:direction], strand]
100
- when [3, :plus], [5, :minus] then Range.new(range.min, range.max + coord_options[:length])
101
- when [5, :plus], [3, :minus] then Range.new(range.min - coord_options[:length], range.max)
102
- else puts "WARNING: value for :direction key in sequence retrieval needs to be one of 5, 3, :both - found (%s)" % coord_options[:direction].inspect
103
- end
104
- end
105
- else
106
- range
107
- end
108
- end
109
-
110
- def inspect
111
- "#<Rbfam::Sequence #{description} #{seq[0, 20] + ('...' if seq.length > 20)}>"
112
- end
113
- end
114
- end
@@ -1,38 +0,0 @@
1
- module Rbfam
2
- module Utils
3
- class << self
4
- def simple_rna_sequence(id, from, to)
5
- sequence = rna_sequence_from_entrez(id, [from, to].min, 0..((to - from).abs))
6
-
7
- to < from ? sequence.complement : sequence
8
- end
9
-
10
- def rna_sequence_from_entrez(id, position, window, buffer_size = 0)
11
- na_sequence_from_entrez(id, position, window, buffer_size).rna
12
- end
13
-
14
- def na_sequence_from_entrez(id, position, window, buffer_size = 0)
15
- Bio::Sequence::NA.new(sequence_from_entrez(id, position, Range.new(window.min - buffer_size, window.max + buffer_size)).seq)
16
- end
17
-
18
- def aa_sequence_from_entrez(id, position, window)
19
- Bio::Sequence::AA.new(sequence_from_entrez(id, position, window).seq)
20
- end
21
-
22
- def sequence_from_entrez(id, position, window)
23
- puts "Retrieving sequence from Entrez: using nuccore DB (id: #{id}, seq_start: #{position + window.min}, seq_stop: #{position + window.max})"
24
- puts "> True starting position: #{position} with window #{window.min} to #{window.max}"
25
-
26
- fasta = Entrez.EFetch("nuccore", {
27
- id: id,
28
- seq_start: position + window.min,
29
- seq_stop: position + window.max,
30
- retmode: :fasta,
31
- rettype: :text
32
- }).response.body
33
-
34
- Bio::FastaFormat.new(fasta)
35
- end
36
- end
37
- end
38
- end
@@ -1,46 +0,0 @@
1
- require "mysql2"
2
- require "active_record"
3
-
4
- module Rbfam
5
- module DB
6
- class Sequence < ActiveRecord::Base
7
- belongs_to :alignment
8
-
9
- validates_uniqueness_of :accession, scope: [:stripped_sequence, :from, :to]
10
-
11
- def self.connect
12
- ActiveRecord::Base.establish_connection(config = { adapter: "mysql2", username: "root", reconnect: true })
13
-
14
- unless ActiveRecord::Base.connection.execute("show databases").to_a.inject(&:+).include?("rbfam")
15
- ActiveRecord::Base.connection.create_database("rbfam")
16
- end
17
-
18
- ActiveRecord::Base.establish_connection(config.merge(database: "rbfam"))
19
-
20
- inline_rails if defined?(inline_rails)
21
- end
22
-
23
- def to_rbfam(family = nil)
24
- # Should use a singleton pattern here to look up the family.
25
- ::Rbfam::Sequence.new(family || Rbfam::Family.new(family), accession, from, to, { sequence: stripped_sequence })
26
- end
27
- end
28
-
29
- class Alignment < ActiveRecord::Base
30
- belongs_to :family
31
- has_many :sequences
32
-
33
- self.table_name = "alignments"
34
- end
35
-
36
- class Family < ActiveRecord::Base
37
- has_many :alignments
38
- has_many :sequences, through: :alignment
39
-
40
- self.table_name = "families"
41
- end
42
-
43
- end
44
- end
45
-
46
- Rbfam::DB::Sequence.connect
@@ -1,28 +0,0 @@
1
- require "rbfam"
2
-
3
- entries = Bio::Stockholm::Reader.parse_from_file("rfam_12.seed.utf8") and nil
4
-
5
- Rbfam.connect(config: { adapter: "mysql2", database: "rbfam", username: "root", password: "" })
6
-
7
- class Family < ActiveRecord::Base; has_one :alignment; end
8
- class Alignment < ActiveRecord::Base; belongs_to :family; end
9
- class Sequence < ActiveRecord::Base; belongs_to :alignment; end
10
-
11
- Parallel.each(entries, progress: "Populating MySQL") do |stockholm|
12
- family = Family.find_or_create_by(name: stockholm.gf_features["AC"], description: stockholm.gf_features["DE"])
13
-
14
- alignment = Alignment.find_or_create_by(family: family) do |alignment|
15
- alignment.stockholm = stockholm.to_yaml
16
- alignment.consensus_structure = stockholm.gc_features["SS_cons"].gsub(?<, ?().gsub(?>, ?))
17
- end
18
-
19
- stockholm.records.reject { |key, _| key == ?# }.each do |identifier, record|
20
- accession, from, to = identifier.split(/[\/-]/)
21
-
22
- Sequence.find_or_create_by(alignment: alignment, accession: accession, from: from, to: to) do |sequence|
23
- raw_sequence = record.sequence.upcase
24
- sequence.stripped_sequence = raw_sequence.gsub(/[^AUGC]/, "")
25
- sequence.alignment_sequence = raw_sequence
26
- end
27
- end
28
- end and nil