qu-pcr 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d79948924f1faf4f40f3adc19249a7c848aca707
4
+ data.tar.gz: 2d14089102d1bfc60de4efc5f3c6dc1113621f2a
5
+ SHA512:
6
+ metadata.gz: 1418a4f81f721d1ed5145f70e030c019f8c6d37be36668f51f4fc8346a87d1b52222ca9efd05126960976b8381cc97d3cd67a115767e36e71caa50048c9b0ead
7
+ data.tar.gz: 1de67df5c43b23fc4bdb370fc30787b4b32dde56e1e59a2344aa18e3dddf52afb465d8bcac0f6054e058e9ffafb13dba36880352ebfe2c4578ee233d94400f53
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in qu-pcr.gemspec
4
+ gemspec
5
+ gem 'qu/utils'
6
+ gem 'qu/cmdwrapper'
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Wubin Qu
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,29 @@
1
+ # Qu::Pcr
2
+
3
+ A package for PCR, including primers, products, primer3 parser, virtual electrophoresis, etc.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'qu-pcr'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install qu-pcr
18
+
19
+ ## Usage
20
+
21
+ mobility = Qu::Pcr::VirtualGel.cal_mobility(size)
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,98 @@
1
+ require 'qu/utils'
2
+ require 'qu/cmdwrapper'
3
+
4
+ require_relative "pcr/version"
5
+ require_relative "pcr/primer3"
6
+ require_relative "pcr/primer3_parameters"
7
+
8
+ module Qu
9
+ module Pcr
10
+ class Primer
11
+ attr_reader :type, :tm, :penalty, :pos, :seq, :gc
12
+ def initialize(seq = nil,
13
+ type = nil,
14
+ gc = nil,
15
+ tm = nil,
16
+ penalty = nil,
17
+ pos = nil)
18
+
19
+
20
+ # type should be "forward" or "reverse"
21
+ @type = type
22
+
23
+ @gc = gc.to_f
24
+ @tm = tm.to_f
25
+ @penalty = penalty.to_f
26
+ # position of primer's 5' end
27
+ @pos = pos.to_i
28
+ @seq = Bio::Sequence::NA.new(seq)
29
+ end
30
+ end
31
+
32
+ class Product
33
+ attr_reader :tm, :opt_a, :seq, :size, :id, :penalty
34
+ def initialize(seq = nil,
35
+ tm = nil,
36
+ opt_a = nil,
37
+ size = nil,
38
+ id = nil,
39
+ penalty = nil)
40
+ @tm = tm.to_f
41
+ @size = size.to_i
42
+ @opt_a = opt_a.to_f
43
+ @seq = Bio::Sequence::NA.new(seq)
44
+ @id = id.to_s
45
+ @penalty = penalty.to_f
46
+ end
47
+
48
+ end
49
+
50
+ class VirtualGel
51
+ PARA = {
52
+ 0.5 => {
53
+ 'a' => 2.7094,
54
+ 'b' => 0.2691,
55
+ 'k' => 464.4412
56
+ },
57
+ 1.0 => {
58
+ 'a' => 2.3977,
59
+ 'b' => 0.2700,
60
+ 'k' => 73.9788
61
+ },
62
+ 1.5 => {
63
+ 'a' => 2.3221,
64
+ 'b' => 0.2634,
65
+ 'k' => 48.0873
66
+ },
67
+ 2.0 => {
68
+ 'a' => 2.1333,
69
+ 'b' => 0.2561,
70
+ 'k' => 18.5417
71
+ }}
72
+
73
+ def self.get_para(gel_conc)
74
+ a = PARA[gel_conc]['a']
75
+ b = PARA[gel_conc]['b']
76
+ k = PARA[gel_conc]['k']
77
+ return a, b, k
78
+ end
79
+
80
+ def self.cal_mobility(size, gel_conc=1.0, ref_mobility=50)
81
+ a, b, k = get_para(gel_conc)
82
+ return ((a - b * Math.log(size + k)) * ref_mobility.to_f).round(2)
83
+ end
84
+
85
+ def self.cal_size(mobility, gel_conc=1.0, ref_mobility=50)
86
+ a, b, k = get_para(gel_conc)
87
+ return (Math.exp((a - mobility / ref_mobility.to_f) / b) - k).round
88
+ end
89
+
90
+ def self.cal_size_range(size, offset=2, gel_conc=1.0, ref_mobility=50)
91
+ y = cal_mobility(size, gel_conc, ref_mobility)
92
+ x_min = cal_size(y + offset, gel_conc, ref_mobility)
93
+ x_max = cal_size(y - offset, gel_conc, ref_mobility)
94
+ return x_min, x_max
95
+ end
96
+ end # VirtualGel
97
+ end
98
+ end
@@ -0,0 +1,157 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'csv'
4
+
5
+ module Qu
6
+ module Pcr
7
+ class Primer3
8
+ attr_accessor :para
9
+
10
+ def initialize(custom_para=nil)
11
+ @para = {}
12
+
13
+ # set default values
14
+ PRIMER3_OPTIONS.each_pair do |opt, value|
15
+ @para[opt] = value
16
+ end
17
+
18
+ # set custom value
19
+ unless custom_para.nil?
20
+ custom_para.each_pair do |opt, value|
21
+ @para[opt] = value
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ def out
28
+ p3_string = create_p3_input()
29
+ p3_input_file = Tempfile.new('p3_input')
30
+ p3_input_file.write(p3_string)
31
+ p3_input_file.close
32
+
33
+ p3_out = Cmdwrapper::primer3_core(p3_input_file)
34
+
35
+ p3_input_file.unlink
36
+
37
+ return Primer3Parser.new(p3_out).records
38
+ end
39
+
40
+ private
41
+ def create_p3_input()
42
+ lines = []
43
+ @para.each_pair do |key, value|
44
+ next if value.to_s.empty?
45
+ lines << "#{key}=#{value}"
46
+ end
47
+ lines << "="
48
+ return lines.join("\n")
49
+ end
50
+ end # End Primer3 class
51
+
52
+ class Amplicon
53
+ attr_reader :fp, :rp, :product
54
+ def initialize(record, i, type='primer3')
55
+ if type == 'primer3'
56
+ (fp_5_pos, fp_size) = record["PRIMER_LEFT_%s" %[i]].split(',')
57
+ (rp_5_pos, rp_size) = record["PRIMER_RIGHT_%s" %[i]].split(',')
58
+ fp_seq = record["PRIMER_LEFT_%s_SEQUENCE" % [i]]
59
+ rp_seq = record["PRIMER_RIGHT_%s_SEQUENCE" % [i]]
60
+ fp_gc = record["PRIMER_LEFT_%s_GC_PERCENT" % [i]].to_f
61
+ rp_gc = record["PRIMER_RIGHT_%s_GC_PERCENT" % [i]].to_f
62
+ fp_tm = record["PRIMER_LEFT_%s_TM" % [i]].to_f
63
+ rp_tm = record["PRIMER_RIGHT_%s_TM" % [i]].to_f
64
+ product_opt_a = record["PRIMER_PAIR_%s_T_OPT_A" % [i]].to_f
65
+ product_size = record["PRIMER_PAIR_%s_PRODUCT_SIZE" % [i]].to_i
66
+ product_tm = record["PRIMER_PAIR_%s_PRODUCT_TM" % [i]].to_f
67
+ penalty = record["PRIMER_PAIR_%s_PENALTY" % [i]].to_f
68
+ fp_penalty = record["PRIMER_LEFT_%s_PENALTY" % [i]].to_f
69
+ rp_penalty = record["PRIMER_RIGHT_%s_PENALTY" % [i]].to_f
70
+ id = record["SEQUENCE_ID"].to_s
71
+ product_seq = record["SEQUENCE_TEMPLATE"].to_s[fp_5_pos.to_i..rp_5_pos.to_i]
72
+
73
+ @fp = Primer.new(seq = fp_seq,
74
+ type = 'forward',
75
+ gc = fp_gc,
76
+ tm = fp_tm,
77
+ penalty = fp_penalty,
78
+ pos = fp_5_pos,
79
+ )
80
+
81
+ @rp = Primer.new(seq = rp_seq,
82
+ type = 'reverse',
83
+ gc = rp_gc,
84
+ tm = rp_tm,
85
+ penalty = rp_penalty,
86
+ pos = rp_5_pos,
87
+ )
88
+
89
+ @product = Product.new(seq = product_seq,
90
+ tm = product_tm,
91
+ opt_a = product_opt_a,
92
+ size = product_size,
93
+ id = id,
94
+ penalty = penalty,
95
+ )
96
+ end
97
+ end
98
+ end # Amplicon
99
+
100
+ class Primer3Parser
101
+ def initialize(p3_out)
102
+ if p3_out.class != String
103
+ $stderr.puts "Need primer3 output file content (not file name) for parsing."
104
+ end
105
+ @p3_out = p3_out
106
+ end
107
+
108
+ private
109
+ def parse
110
+ result = []
111
+ if @p3_out.empty?
112
+ return result
113
+ end
114
+ @p3_out.split(/\n=\n/).each do |record|
115
+ record_result = {}
116
+ record.each_line do |line|
117
+ line.strip!
118
+ items = line.split('=')
119
+ record_result[items[0]] = items[1]
120
+ end
121
+ result << record_result
122
+ end
123
+
124
+ return result
125
+ end
126
+
127
+ public
128
+ def records
129
+ p3_hash = {}
130
+ p3_record = parse
131
+ p3_record.each do |record|
132
+ seq_id = record['SEQUENCE_ID']
133
+ if record.has_key?('PRIMER_ERROR')
134
+ $stderr.puts "#{record['PRIMER_ERROR']}"
135
+ return p3_hash
136
+ end
137
+ pp_num = record['PRIMER_PAIR_NUM_RETURNED'].to_i
138
+ if pp_num < 1
139
+ $stderr.puts "Failed design for %s" % [seq_id]
140
+ $stderr.puts "Left: #{record['PRIMER_LEFT_EXPLAIN']}"
141
+ $stderr.puts "Right: #{record['PRIMER_RIGHT_EXPLAIN']}"
142
+ $stderr.puts "Pair: #{record['PRIMER_PAIR_EXPLAIN']}"
143
+ #exit
144
+ end
145
+ p3_hash[seq_id] = []
146
+ (0...pp_num).each do |i|
147
+ p3_hash[seq_id] << Amplicon.new(record, i, type='primer3')
148
+ end
149
+ end
150
+
151
+ return p3_hash
152
+ end
153
+ end # Primer3Parser
154
+
155
+ end # end Pcr module
156
+
157
+ end # end Qu module
@@ -0,0 +1,80 @@
1
+ # Primer3 Parameters
2
+
3
+ module Qu
4
+ module Pcr
5
+ PRIMER3_OPTIONS = {
6
+ SEQUENCE_ID: "",
7
+ SEQUENCE_TARGET: "",
8
+ SEQUENCE_EXCLUDED_REGION: "",
9
+ SEQUENCE_FORCE_LEFT_START: -1000000,
10
+ SEQUENCE_FORCE_LEFT_END: -1000000,
11
+ SEQUENCE_FORCE_RIGHT_START: -1000000,
12
+ SEQUENCE_FORCE_RIGHT_END: -1000000,
13
+ SEQUENCE_PRIMER: '',
14
+ SEQUENCE_PRIMER_REVCOMP: '',
15
+ PRIMER_PRODUCT_SIZE_RANGE: '100-200 200-300 300-400 400-500',
16
+ PRIMER_MIN_SIZE: 18,
17
+ PRIMER_OPT_SIZE: 22,
18
+ PRIMER_MAX_SIZE: 28,
19
+ PRIMER_MIN_TM: 55,
20
+ PRIMER_OPT_TM: 60,
21
+ PRIMER_MAX_TM: 65,
22
+ PRIMER_MIN_GC: 40,
23
+ PRIMER_OPT_GC: 50,
24
+ PRIMER_MAX_GC: 60,
25
+ PRIMER_MAX_POLY_X: 4,
26
+ PRIMER_MAX_HAIRPIN_TH: 47,
27
+ PRIMER_MAX_SELF_ANY_TH: 47,
28
+ PRIMER_MAX_SELF_END_TH: 47,
29
+ SEQUENCE_TEMPLATE: "",
30
+ PRIMER_THERMODYNAMIC_PARAMETERS_PATH: Cmdwrapper::THERMO_PATH,
31
+ PRIMER_PICK_LEFT_PRIMER: 1,
32
+ PRIMER_PICK_INTERNAL_OLIGO: 0,
33
+ PRIMER_PICK_RIGHT_PRIMER: 1,
34
+ PRIMER_NUM_RETURN: 10,
35
+ PRIMER_MAX_NS_ACCEPTED: 0,
36
+ PRIMER_THERMODYNAMIC_ALIGNMENT: 1,
37
+ PRIMER_TM_FORMULA: 1,
38
+ PRIMER_SALT_CORRECTIONS: 1,
39
+ PRIMER_SALT_MONOVALENT: 50.0,
40
+ PRIMER_SALT_DIVALENT: 1.5,
41
+ PRIMER_DNTP_CONC: 0.25,
42
+ PRIMER_DNA_CONC: 50.0,
43
+ P3_FILE_FLAG: 0,
44
+ PRIMER_EXPLAIN_FLAG: 1,
45
+ PRIMER_PRODUCT_MAX_TM: 100000,
46
+ PRIMER_PICK_ANYWAY: 0,
47
+ PRIMER_TASK: "generic",
48
+ SEQUENCE_PRIMER_PAIR_OK_REGION_LIST: "",
49
+ PRIMER_MIN_LEFT_THREE_PRIME_DISTANCE: 2,
50
+ PRIMER_LOWERCASE_MASKING: 1,
51
+ }
52
+
53
+ # Parameters not shown to users for editing
54
+ USER_SPECIFIC_OPTIONS = [
55
+ :SEQUENCE_ID,
56
+ :SEQUENCE_TARGET,
57
+ :SEQUENCE_EXCLUDED_REGION,
58
+ :SEQUENCE_FORCE_LEFT_START,
59
+ :SEQUENCE_FORCE_LEFT_END,
60
+ :SEQUENCE_FORCE_RIGHT_START,
61
+ :SEQUENCE_FORCE_RIGHT_END,
62
+ :SEQUENCE_PRIMER,
63
+ :SEQUENCE_PRIMER_REVCOMP,
64
+ :PRIMER_PRODUCT_SIZE_RANGE,
65
+ :PRIMER_MIN_SIZE,
66
+ :PRIMER_OPT_SIZE,
67
+ :PRIMER_MAX_SIZE,
68
+ :PRIMER_MIN_TM,
69
+ :PRIMER_OPT_TM,
70
+ :PRIMER_MAX_TM,
71
+ :PRIMER_MIN_GC,
72
+ :PRIMER_OPT_GC,
73
+ :PRIMER_MAX_GC,
74
+ :PRIMER_MAX_POLY_X,
75
+ :PRIMER_MAX_HAIRPIN_TH,
76
+ :PRIMER_MAX_SELF_ANY_TH,
77
+ :PRIMER_MAX_SELF_END_TH,
78
+ ]
79
+ end
80
+ end
@@ -0,0 +1,5 @@
1
+ module Qu
2
+ module Pcr
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'qu/pcr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "qu-pcr"
8
+ spec.version = Qu::Pcr::VERSION
9
+ spec.authors = ["Wubin Qu"]
10
+ spec.email = ["quwubin@gmail.com"]
11
+ spec.description = %q{A package for PCR, including primers, products, primer3 parser, virtual electrophoresis, etc.}
12
+ spec.summary = %q{A ruby library for PCR}
13
+ spec.homepage = "https://github.com/quwubin/qu-pcr"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'qu-utils', '~> 1.0'
22
+ spec.add_runtime_dependency 'qu-cmdwrapper', '~> 1.0'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qu-pcr
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Wubin Qu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: qu-utils
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: qu-cmdwrapper
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: A package for PCR, including primers, products, primer3 parser, virtual
70
+ electrophoresis, etc.
71
+ email:
72
+ - quwubin@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/qu/pcr.rb
83
+ - lib/qu/pcr/primer3.rb
84
+ - lib/qu/pcr/primer3_parameters.rb
85
+ - lib/qu/pcr/version.rb
86
+ - qu-pcr.gemspec
87
+ homepage: https://github.com/quwubin/qu-pcr
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.0
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: A ruby library for PCR
111
+ test_files: []