qu-utils 1.0.1
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 +7 -0
- data/.gitignore +18 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +1 -0
- data/lib/qu/utils.rb +181 -0
- data/lib/qu/utils/version.rb +5 -0
- data/qu-utils.gemspec +23 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2ac15091607b410ac38f941ec8557a6c8746b483
|
4
|
+
data.tar.gz: ffed46d5e8e9b2c6107581f67f12696d8e72605c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 24826357fadfdc24f0c3e8303069bb03ae92cd42d81b6864d26df2a966c6bf476b807930ca9fc2f4bd85e3b64af123ee6e26678566d6c74e070db5d33c99d109
|
7
|
+
data.tar.gz: 97db644cb4361ff0288408b53e94344b571410570d21dc856ec785bfd9fdb2ed58099006fcecdcf8ef5eb95914f56bc5f62ca1252ac1afa46d01a7d88e481b0b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -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.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Qu::Utils
|
2
|
+
|
3
|
+
Utils: useful class or methods used in qu-* projects.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'qu-utils'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install qu-utils
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```
|
22
|
+
require 'qu/utils'
|
23
|
+
|
24
|
+
Qu::Utils::long_seq_wrap(long_seq)
|
25
|
+
```
|
26
|
+
|
27
|
+
## Contributing
|
28
|
+
|
29
|
+
1. Fork it
|
30
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
31
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
32
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
33
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/qu/utils.rb
ADDED
@@ -0,0 +1,181 @@
|
|
1
|
+
require 'bio'
|
2
|
+
require 'optparse'
|
3
|
+
require "qu/utils/version"
|
4
|
+
|
5
|
+
module Qu
|
6
|
+
module Utils
|
7
|
+
IUPAC = {
|
8
|
+
A: ['A'],
|
9
|
+
T: ['T'],
|
10
|
+
C: ['C'],
|
11
|
+
G: ['G'],
|
12
|
+
R: ['G', 'A'],
|
13
|
+
Y: ['T', 'C'],
|
14
|
+
S: ['G', 'C'],
|
15
|
+
W: ['T', 'A'],
|
16
|
+
K: ['G', 'T'],
|
17
|
+
M: ['A', 'C'],
|
18
|
+
D: ['G', 'T', 'A'],
|
19
|
+
H: ['T', 'A', 'C'],
|
20
|
+
B: ['G', 'T', 'C'],
|
21
|
+
V: ['G', 'A', 'C'],
|
22
|
+
N: ['G', 'A', 'T', 'C'],
|
23
|
+
I: ['G', 'A', 'T', 'C'],
|
24
|
+
}
|
25
|
+
module_function
|
26
|
+
|
27
|
+
def iupac2normal(seq, prefixes = [''])
|
28
|
+
return prefixes if seq.size == 0
|
29
|
+
|
30
|
+
first = seq[0].to_sym
|
31
|
+
last_seq = seq[1..-1]
|
32
|
+
new_prefixes = []
|
33
|
+
prefixes.each do |prefix|
|
34
|
+
if IUPAC.include?(first)
|
35
|
+
IUPAC[first].each {|base| new_prefixes << "#{prefix}#{base}"}
|
36
|
+
else
|
37
|
+
$stderr.puts "Error: unrecognized base: #{first}"
|
38
|
+
exit
|
39
|
+
end
|
40
|
+
end
|
41
|
+
return iupac2normal(last_seq, prefixes = new_prefixes)
|
42
|
+
end
|
43
|
+
|
44
|
+
def convert_degenerate_primer(primer_file)
|
45
|
+
primer_records = Bio::FlatFile.new(Bio::FastaFormat, File.open(primer_file))
|
46
|
+
|
47
|
+
primer_list = []
|
48
|
+
primer_records.each do |primer|
|
49
|
+
if primer.naseq.to_s =~ /[^atcgATCG]+/
|
50
|
+
normal_seq_list = iupac2normal(primer.naseq.upcase)
|
51
|
+
fasta_io = StringIO.new
|
52
|
+
normal_seq_list.each_with_index do |normal_seq, index|
|
53
|
+
fasta_io << ">#{primer.entry_name}_#{index+1} #{primer.description}\n#{normal_seq}\n"
|
54
|
+
end
|
55
|
+
fasta_io.rewind
|
56
|
+
primer_list += Bio::FlatFile.new(Bio::FastaFormat, fasta_io).to_a
|
57
|
+
fasta_io.close
|
58
|
+
else
|
59
|
+
primer_list << primer
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
return primer_list
|
64
|
+
end
|
65
|
+
|
66
|
+
# File actionpack/lib/action_view/helpers/text_helper.rb, line 215
|
67
|
+
def word_wrap(text, line_width = 80)
|
68
|
+
text.split("\n").collect do |line|
|
69
|
+
line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line
|
70
|
+
end * "\n"
|
71
|
+
end
|
72
|
+
|
73
|
+
def long_seq_wrap(word, length=80, separator="\n")
|
74
|
+
# Wrap a long sentence with may words into multiple lines
|
75
|
+
(word.length < length) ?
|
76
|
+
word :
|
77
|
+
word.scan(/.{1,#{length}}/).join(separator)
|
78
|
+
end
|
79
|
+
|
80
|
+
def seconds_to_units(seconds)
|
81
|
+
return "#{seconds.round(2)} second" if seconds < 1
|
82
|
+
return "#{seconds.round(2)} seconds" if seconds < 60
|
83
|
+
'%d minutes, %d seconds' %
|
84
|
+
#'%d days, %d hours, %d minutes, %d seconds' %
|
85
|
+
# the .reverse lets us put the larger units first for readability
|
86
|
+
|
87
|
+
#[24,60,60].reverse.inject([seconds]) {|result, unitsize|
|
88
|
+
|
89
|
+
[60].reverse.inject([seconds]) {|result, unitsize|
|
90
|
+
result[0,0] = result.shift.divmod(unitsize)
|
91
|
+
result
|
92
|
+
}
|
93
|
+
end
|
94
|
+
|
95
|
+
def plural_word(word, count)
|
96
|
+
count > 1 ? word + 's' : word
|
97
|
+
end
|
98
|
+
|
99
|
+
def platform_os
|
100
|
+
case RUBY_PLATFORM
|
101
|
+
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
|
102
|
+
return 'windows'
|
103
|
+
when /darwin|mac/
|
104
|
+
return 'mac'
|
105
|
+
when /linux/
|
106
|
+
return 'linux'
|
107
|
+
when /solaris|bsd/
|
108
|
+
return 'unix'
|
109
|
+
else
|
110
|
+
raise Error::WebDriverError, "Unknown os: #{RUBY_PLATFORM.inspect}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def platform_bit
|
115
|
+
case RUBY_PLATFORM
|
116
|
+
when /64/
|
117
|
+
return 64
|
118
|
+
when /32/
|
119
|
+
return 32
|
120
|
+
else
|
121
|
+
raise Error::WebDriverError, "Unknown os bit: #{RUBY_PLATFORM.inspect}"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
module Bio
|
128
|
+
# A patch for BioRuby FastaFormat class
|
129
|
+
class FastaFormat
|
130
|
+
def entry_name
|
131
|
+
@definition.split.first.chomp(',').gsub(/,/, '.')
|
132
|
+
end
|
133
|
+
|
134
|
+
def description
|
135
|
+
@definition.split[1..-1].join(' ')
|
136
|
+
end
|
137
|
+
|
138
|
+
alias desc description
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
# Add the ability to specify switches as required to OptionParser
|
143
|
+
class OptionParser
|
144
|
+
|
145
|
+
# An array of messages describing any missing required switches
|
146
|
+
attr_reader :missing_switches
|
147
|
+
|
148
|
+
# Convenience method to test if we're missing any required switches
|
149
|
+
def missing_switches?
|
150
|
+
!@missing_switches.nil?
|
151
|
+
end
|
152
|
+
|
153
|
+
# Alias the OptionParser::make_switch function
|
154
|
+
# (instead of directly modifying it like I did in 0.1.0)
|
155
|
+
alias :pickled_make_switch :make_switch
|
156
|
+
|
157
|
+
# Wrapper for OptionParser::make_switch to allow for required switches
|
158
|
+
def make_switch(opts, block = nil)
|
159
|
+
|
160
|
+
# Test if a switch is required
|
161
|
+
required = opts.delete(:required)
|
162
|
+
|
163
|
+
return_values = pickled_make_switch(opts, block)
|
164
|
+
|
165
|
+
# Make sure required switches are given
|
166
|
+
if required
|
167
|
+
short = return_values[1][0].nil? ? nil : "-#{return_values[1][0]}"
|
168
|
+
long = return_values[2][0].nil? ? nil : "--#{return_values[2][0]}"
|
169
|
+
|
170
|
+
if !(default_argv.include?(short) || default_argv.include?(long))
|
171
|
+
@missing_switches ||= [] # Should be placed in initialize if incorporated into Ruby proper
|
172
|
+
|
173
|
+
# Ugly and hard to read, should figure out a prettier way of doing this
|
174
|
+
@missing_switches << "Missing switch: #{short if !short.nil?}#{" or " if !short.nil? && !long.nil?}#{long if !long.nil?}"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
return return_values
|
179
|
+
end
|
180
|
+
|
181
|
+
end
|
data/qu-utils.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'qu/utils/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "qu-utils"
|
8
|
+
spec.version = Qu::Utils::VERSION
|
9
|
+
spec.authors = ["Wubin Qu"]
|
10
|
+
spec.email = ["quwubin@gmail.com"]
|
11
|
+
spec.description = %q{Some useful class or methods}
|
12
|
+
spec.summary = %q{Utils by Wubin Qu}
|
13
|
+
spec.homepage = "https://github.com/quwubin/qu-utils"
|
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_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: qu-utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wubin Qu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Some useful class or methods
|
42
|
+
email:
|
43
|
+
- quwubin@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/qu/utils.rb
|
54
|
+
- lib/qu/utils/version.rb
|
55
|
+
- qu-utils.gemspec
|
56
|
+
homepage: https://github.com/quwubin/qu-utils
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.2.0
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: Utils by Wubin Qu
|
80
|
+
test_files: []
|