lib/bioinform/cli/pcm2pwm.rb in bioinform-0.1.17 vs lib/bioinform/cli/pcm2pwm.rb in bioinform-0.2.0
- old
+ new
@@ -1,47 +1,53 @@
require_relative '../../bioinform'
-require 'docopt'
+require 'optparse'
require 'shellwords'
module Bioinform
- module CLI
+ module CLI
module PCM2PWM
extend Bioinform::CLI::Helpers
def self.main(argv)
- doc = <<-DOCOPT
- PCM to PWM converter.
- It transforms files with PCMs into files with PWMs. Folder for resulting files to save files can be specified. Resulting PWM files have the same name as original file but have another extension (.pwm by default).
- When filelist is empty, it's obtained from STDIN. One can use it: `ls -b pcm_folder/*.pcm | pcm2pwm` (ls -b option escape spaces in filenames)
+ options = {folder: '.', extension: 'pwm'}
+ opt_parser = OptionParser.new do |opts|
+ opts.banner = "PCM to PWM converter.\n" +
+ "It transforms files with PCMs into files with PWMs.\n" +
+ "Folder for resulting files to save files can be specified.\n" +
+ "Resulting PWM files have the same name as original file but have another extension (.pwm by default).\n" +
+ "When filelist is empty, it's obtained from STDIN.\n" +
+ "One can use it: `ls -b pcm_folder/*.pcm | pcm2pwm` (ls -b option escape spaces in filenames)\n" +
+ "\n" +
+ "Usage:\n" +
+ " pcm2pwm [options] [<pcm-files>...]"
+ opts.version = ::Bioinform::VERSION
+ opts.on('-e', '--extension EXT', 'Extension of output files [default: pwm]') do |v|
+ options[:extension] = v
+ end
+ opts.on('-f', '--folder FOLDER', 'Where to save output files') do |v|
+ options[:folder] = v
+ end
+ end
- Usage:
- pcm2pwm [options] [<pcm-files>...]
+ opt_parser.parse!(argv)
+ pcm_files = argv
+ folder = options[:folder]
+ extension = options[:extension]
- Options:
- -h --help Show this screen.
- -e --extension EXT Extension of output files [default: pwm]
- -f --folder FOLDER Where to save output files [default: .]
- DOCOPT
-
- doc.gsub!(/^#{doc[/\A +/]}/,'')
- options = Docopt::docopt(doc, argv: argv)
-
- pcm_files = options['<pcm-files>']
- folder = options['--folder']
- extension = options['--extension']
-
Dir.mkdir(folder) unless Dir.exist?(folder)
filelist = (pcm_files.empty?) ? $stdin.read.shellsplit : pcm_files
+ converter = ConversionAlgorithms::PCM2PWMConverter.new()
+
filelist.each do |filename|
- pwm = Bioinform::PCM.new( File.read(filename) ).to_pwm
+ input = File.read(filename)
+ motif_data = MatrixParser.new.parse(input)
+ pcm = MotifModel::PCM.new(motif_data[:matrix]).named(motif_data[:name])
+ pwm = converter.convert(pcm)
File.open(change_folder_and_extension(filename, extension, folder), 'w') do |f|
f.puts pwm
end
end
-
- rescue Docopt::Exit => e
- puts e.message
end
end
end
-end
\ No newline at end of file
+end