Skip to content

Commit

Permalink
Code style improvements
Browse files Browse the repository at this point in the history
[ci skip]

Signed-off-by: Anurag Priyam <anurag08priyam@gmail.com>
  • Loading branch information
yeban committed Aug 2, 2018
1 parent b54f068 commit b80bec2
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 56 deletions.
4 changes: 2 additions & 2 deletions lib/sequenceserver/blast/job.rb
Expand Up @@ -33,7 +33,7 @@ def command
# and using contents of stderr to provide context about the error.
def raise!
# Return true exit status is 0 and stdout is not empty.
return true if exitstatus == 0 && !File.zero?(stdout)
return true if exitstatus.zero? && !File.zero?(stdout)

# Handle error. See [1].
case exitstatus
Expand Down Expand Up @@ -71,7 +71,7 @@ def raise!

private

def parse_advanced param_line
def parse_advanced(param_line)
param_list = (param_line || '').split(' ')
res = {}

Expand Down
2 changes: 1 addition & 1 deletion lib/sequenceserver/database.rb
Expand Up @@ -38,7 +38,7 @@ def initialize(*args)

def include?(accession)
cmd = "blastdbcmd -entry '#{accession}' -db #{name}"
out, _ = sys(cmd, path: config[:bin])
out, = sys(cmd, path: config[:bin])
!out.empty?
end

Expand Down
4 changes: 2 additions & 2 deletions lib/sequenceserver/doctor.rb
Expand Up @@ -11,7 +11,7 @@ class Doctor
ERROR_NUMERIC_IDS = 2
ERROR_PROBLEMATIC_IDS = 3

AVOID_ID_REGEX = /^(?!gi|bbs)\w+\|\w*\|?/.freeze
AVOID_ID_REGEX = /^(?!gi|bbs)\w+\|\w*\|?/

class << self
extend Forwardable
Expand Down Expand Up @@ -92,7 +92,7 @@ def show_message(error, values)
MSG
end
end
# rubocop:disable Metrics/MethodLength
# rubocop:enable Metrics/MethodLength
end

def initialize
Expand Down
14 changes: 7 additions & 7 deletions lib/sequenceserver/job.rb
Expand Up @@ -24,7 +24,7 @@ class Job
class << self
# Creates and queues a job. Returns created job object.
def create(params)
job = BLAST::Job.new(params)# TODO: Dynamic dispatch.
job = BLAST::Job.new(params) # TODO: Dynamic dispatch.
SequenceServer.pool.queue { job.run }
job
end
Expand All @@ -43,8 +43,8 @@ def delete(id)

# Returns an Array of all jobs.
def all
Dir["#{DOTDIR}/**/job.yaml"].
map { |f| fetch File.basename File.dirname f }
Dir["#{DOTDIR}/**/job.yaml"]
.map { |f| fetch File.basename File.dirname f }
end
end

Expand All @@ -58,14 +58,14 @@ def all
# of job data will be held, yields (if block given) and saves the job.
#
# Subclasses should extend `initialize` as per requirement.
def initialize(*args)
def initialize(*)
@id = SecureRandom.uuid
@submitted_at = Time.now
mkdir_p dir
yield if block_given?
save
rescue Errno::ENOSPC
raise SystemError, "Not enough disk space to start a new job"
raise SystemError, 'Not enough disk space to start a new job'
rescue Errno::EACCES
raise SystemError, "Permission denied to write to #{DOTDIR}"
rescue => e
Expand All @@ -78,7 +78,7 @@ def initialize(*args)
# Returns shell command that will be executed. Subclass needs to provide a
# concrete implementation.
def command
raise 'Not implemented.'
fail 'Not implemented.'
end

# Shell out and execute the job.
Expand Down Expand Up @@ -145,7 +145,7 @@ def store(key, value)
# NOTE: Not used.
def fetch(key)
filename = File.join(dir, key)
raise if !File.exist? filename
fail unless File.exist? filename
filename
end

Expand Down
11 changes: 5 additions & 6 deletions lib/sequenceserver/links.rb
@@ -1,15 +1,14 @@
require 'erb'

module SequenceServer
# Module to contain methods for generating sequence retrieval links.
module Links
require 'erb'

# Provide a method to URL encode _query parameters_. See [1].
include ERB::Util
#
alias_method :encode, :url_encode
alias encode url_encode

NCBI_ID_PATTERN = /gi\|(\d+)\|/.freeze
UNIPROT_ID_PATTERN = /sp\|(\w+)\|/.freeze
NCBI_ID_PATTERN = /gi\|(\d+)\|/
UNIPROT_ID_PATTERN = /sp\|(\w+)\|/

# Link generators return a Hash like below.
#
Expand Down
2 changes: 0 additions & 2 deletions lib/sequenceserver/pool.rb
Expand Up @@ -18,8 +18,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

require 'thread'

# Simple thread pool [1].
class Pool
def initialize(size)
Expand Down
18 changes: 9 additions & 9 deletions lib/sequenceserver/routes.rb
Expand Up @@ -42,7 +42,7 @@ class Routes < Sinatra::Base
# 'ALLOW-FROM uri'.
set :protection, lambda {
frame_options = SequenceServer.config[:frame_options]
frame_options && { :frame_options => frame_options }
frame_options && { frame_options: frame_options }
}

# Serve compressed responses.
Expand Down Expand Up @@ -89,7 +89,7 @@ class Routes < Sinatra::Base

# Returns base HTML. Rest happens client-side: polling for and rendering
# the results.
get '/:jid' do |jid|
get '/:jid' do
erb :report, layout: true
end

Expand Down Expand Up @@ -155,13 +155,13 @@ class Routes < Sinatra::Base
# All errors will have a message.
error_data = { message: error.message }

# If error object has a title method, use that, or use error class for
# title.
if error.respond_to? :title
error_data[:title] = error.title
else
error_data[:title] = error.class.to_s
end
# If error object has a title method, use that, or use name of the
# error class as title.
error_data[:title] = if error.respond_to? :title
error.title
else
error.class.name
end

# If error object has a more_info method, use that. If the error does
# not have more_info and the error is not APIError, use backtrace as
Expand Down
21 changes: 11 additions & 10 deletions lib/sequenceserver/sequence.rb
Expand Up @@ -67,7 +67,7 @@ def to_s
end

def info
{ :value => value, :id => id, :title => title }
{ value: value, id: id, title: title }
end

# Returns FASTA formatted sequence.
Expand Down Expand Up @@ -97,7 +97,7 @@ def guess_type(sequence)
na_count = 0
composition = composition(cleaned_sequence)
composition.each do |character, count|
na_count += count if character.match(/[ACGTU]/i)
na_count += count if character =~ /[ACGTU]/i
end

na_count > (0.9 * cleaned_sequence.length) ? :nucleotide : :protein
Expand Down Expand Up @@ -200,7 +200,7 @@ def run
" -db '#{database_names.join(' ')}'" \
" -entry '#{sequence_ids.join(',')}'"

out, _ = sys(command, path: config[:bin])
out, = sys(command, path: config[:bin])

@sequences = out.each_line.map do |line|
# Stop codons in amino acid sequence databases show up as invalid
Expand Down Expand Up @@ -234,20 +234,21 @@ def error_msgs
[
['ERROR: incorrect number of sequences found.',
<<~MSG
You requested #{sequence_ids.length} sequence(s) with the following identifiers:
#{sequence_ids.join(', ')}
You requested #{sequence_ids.length} sequence(s) with the following
identifiers:
#{sequence_ids.join(', ')}
from the following databases:
#{database_titles.join(', ')}
but we found #{sequences.length} sequence(s).
This is likley due to a problem with how databases are formatted.
Please share this text with the person managing this website.
If you are the admin and are confident that your databases are
correctly formatted, you have likely encountered a weird bug.
Please share this text with the person managing this website.
If you are the admin and are confident that your databases are
correctly formatted, you have likely encountered a weird bug.
In this case, please raise an issue at:
https://github.com/wurmlab/sequenceserver/issues
If any sequences were retrieved, you can find them below
(but some may be incorrect, so be careful!)
MSG
Expand Down
35 changes: 18 additions & 17 deletions sequenceserver.gemspec
Expand Up @@ -11,45 +11,46 @@ Gem::Specification.new do |s|
s.license = 'AGPL-3.0'

s.summary = 'BLAST search made easy!'
s.description = <<DESC
SequenceServer lets you rapidly set up a BLAST+ server with an intuitive user
interface for use locally or over the web.
DESC
s.description = <<~DESC
SequenceServer lets you rapidly set up a BLAST+ server with an intuitive
user interface for use locally or over the web.
DESC

# dependencies
s.required_ruby_version = '>= 2.3.0'

s.add_dependency('sinatra', '~> 2.0', '>= 2.0.0')
s.add_dependency('json_pure', '~> 1.8', '>= 1.8.2')
s.add_dependency('ox', '~> 2.1', '>= 2.1.1')
s.add_dependency('sinatra', '~> 2.0', '>= 2.0.0')
s.add_dependency('slop', '~> 3.6', '>= 3.6.0')

s.add_development_dependency('capybara', '~> 2.18', '>= 2.18.0')
s.add_development_dependency('codeclimate-test-reporter',
'~> 1.0', '>= 1.0.8')
s.add_development_dependency('rack-test', '~> 1.0', '>= 1.0.0')
s.add_development_dependency('rake', '~> 10.3', '>= 10.3.2')
s.add_development_dependency('rspec', '~> 3.7', '>= 3.7.0')
s.add_development_dependency('capybara', '~> 2.18', '>= 2.18.0')
s.add_development_dependency('rack-test', '~> 1.0', '>= 1.0.0')
s.add_development_dependency('rspec', '~> 3.7', '>= 3.7.0')
s.add_development_dependency('sauce_whisk', '~> 0.0', '>= 0.0.19')
s.add_development_dependency('selenium-webdriver', '~> 3.11', '>= 3.11.0')
s.add_development_dependency('codeclimate-test-reporter', '~> 1.0', '>= 1.0.8')

# gem
s.files = `git ls-files`.split("\n") - ['Gemfile', 'Gemfile.lock']
s.executables = ['sequenceserver']
s.require_paths = ['lib']

# post install information
s.post_install_message = <<INFO
s.post_install_message = <<~INFO
------------------------------------------------------------------------
Thank you for installing SequenceServer :)!
------------------------------------------------------------------------
Thank you for installing SequenceServer :)
To launch SequenceServer execute 'sequenceserver' from command line.
To launch SequenceServer execute 'sequenceserver' from command line.
$ sequenceserver
$ sequenceserver
Visit http://sequenceserver.com for more.
------------------------------------------------------------------------
Visit http://sequenceserver.com for more.
------------------------------------------------------------------------
INFO
INFO
end

0 comments on commit b80bec2

Please sign in to comment.