rbfam 0.0.7 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/rbfam/modules/sequence.rb +38 -31
  2. metadata +2 -2
@@ -19,19 +19,23 @@ module Rbfam
19
19
  end
20
20
 
21
21
  def save!(options = {})
22
- Rbfam.script("sequences_in_mysql")
22
+ unless extended?
23
+ Rbfam.script("sequences_in_mysql")
23
24
 
24
- SequenceTable.create({
25
- family: family.family_name,
26
- accession: accession,
27
- sequence: sequence,
28
- sequence_length: sequence.length,
29
- from: from,
30
- to: to,
31
- seq_from: seq_from,
32
- seq_to: seq_to,
33
- seed: options[:seed]
34
- })
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
35
39
  end
36
40
 
37
41
  def up_coord
@@ -81,29 +85,32 @@ module Rbfam
81
85
  @fftbor ||= ViennaRna::Fftbor.run(seq: seq, str: mfe_structure)
82
86
  end
83
87
 
88
+ def extend!(coord_options = {})
89
+ tap do
90
+ @extended = true
91
+ @coord_options = coord_options
92
+ remove_instance_variable(:@raw_sequence)
93
+ sequence
94
+ end
95
+ end
96
+
97
+ def extended?
98
+ @extended
99
+ end
100
+
84
101
  def coord_window
85
- # Options from @coord_options ex: { length: 300, extend: 3 }
86
-
102
+ # Options from coord_options ex: { length: 300, extend: 3 }, or { length: 250, extend: :both }
87
103
  range = 0..(down_coord - up_coord)
88
104
 
89
- if @coord_options[:length] && @coord_options[:extend]
90
- if range.count < @coord_options[:length]
91
- length_difference = @coord_options[:length] - range.count
92
-
93
- case [@coord_options[:extend], strand]
94
- when [3, :plus], [5, :minus] then Range.new(range.min, range.max + length_difference)
95
- when [5, :plus], [3, :minus] then Range.new(range.min - length_difference, range.max)
96
- else puts "WARNING: value for :extend key in sequence retreival needs to be one of 5, 3 - found (%s)" % @coord_options[:extend]
97
- end
105
+ if coord_options[:length] && coord_options[:direction]
106
+ if coord_options[:direction] == :both
107
+ Range.new(range.min - coord_options[:length], range.max + coord_options[:length])
98
108
  else
99
- puts "WARNING: %s %d-%d (%s) is length %d, but only %d nt. have been requested. Providing the full sequence anyways." % [
100
- accession,
101
- from,
102
- to,
103
- strand,
104
- range.count,
105
- @coord_options[:length]
106
- ]
109
+ case [coord_options[:direction], strand]
110
+ when [3, :plus], [5, :minus] then Range.new(range.min, range.max + coord_options[:length])
111
+ when [5, :plus], [3, :minus] then Range.new(range.min - coord_options[:length], range.max)
112
+ else puts "WARNING: value for :direction key in sequence retreival needs to be one of 5, 3, :both - found (%s)" % coord_options[:direction].inspect
113
+ end
107
114
  end
108
115
  else
109
116
  range
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbfam
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-05 00:00:00.000000000 Z
12
+ date: 2012-09-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bio