sequence_logo 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ebd54ee5bf1c9fece6a4441f6c6e680c6a0af742
4
- data.tar.gz: 7db836f3a01d63b71200496227da726cb681698e
3
+ metadata.gz: 0c7bf6142b7da024066e931674fe7a2d95329725
4
+ data.tar.gz: 43a219e7e1816925b0e6a35ce46373157b06be34
5
5
  SHA512:
6
- metadata.gz: 03ff397f94506ebc41098bb1d897ed078496d70f516e5193ef5006a3db686cd95dcea45e42c410f87f8ecbc7c74eec0015f4d10a133bd1136058d39ed7dad05c
7
- data.tar.gz: 6bb47ee9237f020ea1de0d566642e813fc7de8e7eb87089bbac0259c26f8f5e22b192b3f2269ba0e8feba045e92bc6f5b965266547b5e2600ddb00d07655a350
6
+ metadata.gz: 93cb221175a8a7769f272ed0cdfca146ed838dbb4851a6717f06d73101e1cf9be5473f8e6a26dab53ac8ab61f44330ccd54b6e6b0191cf8b064ef7d46d942617
7
+ data.tar.gz: 5e979afbf8c4b1e6d47e49955318c38e8416e585e129440d9b8c313d94b1885233ec5233fcc37c702e236904cfc92a18e5739286565b1dd0e8862b3c6bac65f0
data/.gitignore CHANGED
@@ -1,17 +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
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 CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in sequence_logo.gemspec
4
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sequence_logo.gemspec
4
+ gemspec
data/LICENSE CHANGED
@@ -1,22 +1,22 @@
1
- Copyright (c) 2012 Ilya Vorontsov
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
1
+ Copyright (c) 2012 Ilya Vorontsov
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
22
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,66 +1,66 @@
1
- # SequenceLogo
2
-
3
- SequenceLogo is a tool for drawing sequence logos of motifs. It gets Positional Count Matrices(PCMs) at input and generates png-logos for motif. Also one can create logo for reverse complement or even generate logos for a whole collection of motifs.
4
- Sequence logos are a graphical representation of an amino acid or nucleic acid multiple sequence alignment developed by Tom Schneider and Mike Stephens. Each logo consists of stacks of symbols, one stack for each position in the sequence. The overall height of the stack indicates the sequence conservation at that position, while the height of symbols within the stack indicates the relative frequency of each amino or nucleic acid at that position. In general, a sequence logo provides a richer and more precise description of, for example, a binding site, than would a consensus sequence (see http://weblogo.berkeley.edu/)
5
-
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- gem 'sequence_logo'
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install sequence_logo
20
-
21
- ## Usage
22
-
23
- SequenceLogo consists of two tools:
24
-
25
- sequence_logo [options] <input files>...
26
-
27
- *input_file* can be either in PCM format (file extension should be .pat or .pcm), or in FASTA format (file extensions: .mfa, .fasta, .plain), or in SMall BiSMark format (.xml), or in IUPAC format (any other extension). In future releases formats except PCM and PPM will be removed in preference of Unix-like modular style.
28
-
29
- Optional parameters:
30
-
31
- * --x-unit SIZE - width of a single letter
32
- * --y-unit SIZE - base height of a letter
33
- * --words-count WEIGHT - float number that represents alignment weight. If words count not defined - it'd be obtained from input if input file is a PCM. If input file is a PPM words_count can't be obtained. In such a case discrete logo can't be drawn, and weblogo will be drawn instead.
34
- * --icd-mode <weblogo|discrete> - information content mode
35
- * --orientation <direct|revcomp|both> - create logo for a direct, reverse-complement or both orientations of motif
36
- * --scheme FOLDER - name of folder containing nucleotide images
37
- * --threshold-lines - draw lines on specific levels
38
-
39
- * Tool **glue_logos** generates a single image of aligned motifs.
40
-
41
- `glue_logos <output file> <file with alignment infos>`
42
-
43
- or
44
-
45
- `<alignment infos> | glue_logos <output file>`
46
-
47
- Input data comes either from file with alignments or from stdin. *glue_logos* is designated to work fine with macroape *align_motifs* tool and has input format the same as output format of *align_motifs* tool:
48
- pcm_file_1 shift_1 orientation_1
49
- pcm_file_2 shift_2 orientation_2
50
- pcm_file_3 shift_3 orientation_3
51
-
52
- So it's simple to run
53
-
54
- align_motifs --pcm leader.pcm other_motifs_1.pcm other_motifs_2.pcm | glue_logos cluster.png
55
-
56
- Don't forget to specify PCM files instead of PWM files and use `--pcm` key in align_motifs.
57
-
58
- ## Contributing
59
-
60
- 1. Fork it
61
- 2. Create your feature branch (`git checkout -b my-new-feature`)
62
- 3. Commit your changes (`git commit -am 'Added some feature'`)
63
- 4. Push to the branch (`git push origin my-new-feature`)
64
- 5. Create new Pull Request
65
-
1
+ # SequenceLogo
2
+
3
+ SequenceLogo is a tool for drawing sequence logos of motifs. It gets Positional Count Matrices(PCMs) at input and generates png-logos for motif. Also one can create logo for reverse complement or even generate logos for a whole collection of motifs.
4
+ Sequence logos are a graphical representation of an amino acid or nucleic acid multiple sequence alignment developed by Tom Schneider and Mike Stephens. Each logo consists of stacks of symbols, one stack for each position in the sequence. The overall height of the stack indicates the sequence conservation at that position, while the height of symbols within the stack indicates the relative frequency of each amino or nucleic acid at that position. In general, a sequence logo provides a richer and more precise description of, for example, a binding site, than would a consensus sequence (see http://weblogo.berkeley.edu/)
5
+
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'sequence_logo'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install sequence_logo
20
+
21
+ ## Usage
22
+
23
+ SequenceLogo consists of two tools:
24
+
25
+ sequence_logo [options] <input files>...
26
+
27
+ *input_file* can be either in PCM format (file extension should be .pat or .pcm), or in FASTA format (file extensions: .mfa, .fasta, .plain), or in SMall BiSMark format (.xml), or in IUPAC format (any other extension). In future releases formats except PCM and PPM will be removed in preference of Unix-like modular style.
28
+
29
+ Optional parameters:
30
+
31
+ * --x-unit SIZE - width of a single letter
32
+ * --y-unit SIZE - base height of a letter
33
+ * --words-count WEIGHT - float number that represents alignment weight. If words count not defined - it'd be obtained from input if input file is a PCM. If input file is a PPM words_count can't be obtained. In such a case discrete logo can't be drawn, and weblogo will be drawn instead.
34
+ * --icd-mode <weblogo|discrete> - information content mode
35
+ * --orientation <direct|revcomp|both> - create logo for a direct, reverse-complement or both orientations of motif
36
+ * --scheme FOLDER - name of folder containing nucleotide images
37
+ * --threshold-lines - draw lines on specific levels
38
+
39
+ * Tool **glue_logos** generates a single image of aligned motifs.
40
+
41
+ `glue_logos <output file> <file with alignment infos>`
42
+
43
+ or
44
+
45
+ `<alignment infos> | glue_logos <output file>`
46
+
47
+ Input data comes either from file with alignments or from stdin. *glue_logos* is designated to work fine with macroape *align_motifs* tool and has input format the same as output format of *align_motifs* tool:
48
+ pcm_file_1 shift_1 orientation_1
49
+ pcm_file_2 shift_2 orientation_2
50
+ pcm_file_3 shift_3 orientation_3
51
+
52
+ So it's simple to run
53
+
54
+ align_motifs --pcm leader.pcm other_motifs_1.pcm other_motifs_2.pcm | glue_logos cluster.png
55
+
56
+ Don't forget to specify PCM files instead of PWM files and use `--pcm` key in align_motifs.
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create new Pull Request
65
+
66
66
  Copyright (c) 2011-2012 Ivan Kulakovskiy(author), Ilya Vorontsov(refactoring and gemification)
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
- #!/usr/bin/env rake
2
- require 'bundler/gem_tasks'
3
-
4
- # require 'rspec/core/rake_task'
5
- # RSpec::Core::RakeTask.new
1
+ #!/usr/bin/env rake
2
+ require 'bundler/gem_tasks'
3
+
4
+ # require 'rspec/core/rake_task'
5
+ # RSpec::Core::RakeTask.new
data/TODO.txt CHANGED
@@ -1,8 +1,8 @@
1
- AssetsPath shouldn't be used at draw_logo level because it makes it impossible to change scheme on one folder that is outside the gem
2
- And how to make possible use schemes inside the assets path
3
-
4
- Make use of Tempfile in glue_logos.
5
-
6
- Make tests
7
-
1
+ AssetsPath shouldn't be used at draw_logo level because it makes it impossible to change scheme on one folder that is outside the gem
2
+ And how to make possible use schemes inside the assets path
3
+
4
+ Make use of Tempfile in glue_logos.
5
+
6
+ Make tests
7
+
8
8
  Wrap execs into methods
data/bin/glue_logos CHANGED
@@ -1,3 +1,3 @@
1
- #!/usr/bin/env ruby
2
-
1
+ #!/usr/bin/env ruby
2
+
3
3
  require_relative '../lib/sequence_logo/exec/glue_logos.rb'
data/bin/sequence_logo CHANGED
@@ -1,3 +1,3 @@
1
- #!/usr/bin/env ruby
2
-
1
+ #!/usr/bin/env ruby
2
+
3
3
  require_relative '../lib/sequence_logo/exec/sequence_logo.rb'
@@ -1,37 +1,37 @@
1
- require 'fileutils'
2
- require 'optparse'
3
- module SequenceLogo
4
- class CLI
5
- attr_reader :options
6
- def initialize(options = {})
7
- @options = options.dup
8
- end
9
- def parse_options!(argv)
10
- parser.parse!(argv)
11
- options
12
- end
13
- def parser
14
- @parser ||= OptionParser.new do |opts|
15
- opts.on('-x', '--x-unit X_UNIT', 'Single letter width') do |v|
16
- options[:x_unit] = v.to_i
17
- end
18
- opts.on('-y', '--y-unit Y_UNIT', 'Base letter height') do |v|
19
- options[:y_unit] = v.to_i
20
- end
21
- opts.on('--words-count WEIGHT', 'Define alignment weight') do |v|
22
- options[:words_count] = v.to_f
23
- end
24
- opts.on('--icd-mode MODE', 'Calculation mode: discrete or weblogo', 'Weblogo is assumed if word count not given') do |v|
25
- options[:icd_mode] = v.to_sym
26
- raise ArgumentError, 'icd-mode can be either discrete or weblogo' unless [:discrete, :weblogo].include?(options[:icd_mode])
27
- end
28
- opts.on('--[no-]threshold-lines', 'Draw threshold lines') do |v|
29
- options[:threshold_lines] = v
30
- end
31
- opts.on('--scheme SCHEME', 'Specify folder with nucleotide images') do |v|
32
- options[:scheme] = v
33
- end
34
- end
35
- end
36
- end
1
+ require 'fileutils'
2
+ require 'optparse'
3
+ module SequenceLogo
4
+ class CLI
5
+ attr_reader :options
6
+ def initialize(options = {})
7
+ @options = options.dup
8
+ end
9
+ def parse_options!(argv)
10
+ parser.parse!(argv)
11
+ options
12
+ end
13
+ def parser
14
+ @parser ||= OptionParser.new do |opts|
15
+ opts.on('-x', '--x-unit X_UNIT', 'Single letter width') do |v|
16
+ options[:x_unit] = v.to_i
17
+ end
18
+ opts.on('-y', '--y-unit Y_UNIT', 'Base letter height') do |v|
19
+ options[:y_unit] = v.to_i
20
+ end
21
+ opts.on('--words-count WEIGHT', 'Define alignment weight') do |v|
22
+ options[:words_count] = v.to_f
23
+ end
24
+ opts.on('--icd-mode MODE', 'Calculation mode: discrete or weblogo', 'Weblogo is assumed if word count not given') do |v|
25
+ options[:icd_mode] = v.to_sym
26
+ raise ArgumentError, 'icd-mode can be either discrete or weblogo' unless [:discrete, :weblogo].include?(options[:icd_mode])
27
+ end
28
+ opts.on('--[no-]threshold-lines', 'Draw threshold lines') do |v|
29
+ options[:threshold_lines] = v
30
+ end
31
+ opts.on('--scheme SCHEME', 'Specify folder with nucleotide images') do |v|
32
+ options[:scheme] = v
33
+ end
34
+ end
35
+ end
36
+ end
37
37
  end
@@ -1,67 +1,98 @@
1
- require_relative '../../sequence_logo'
2
- require 'fileutils'
3
-
4
- begin
5
- doc = <<-EOS
6
- Usage:
7
- glue_logos <output file> <alignment infos file>
8
- or
9
- <alignment infos file> | glue_logos <output file>
10
-
11
- Alignment infos has format:
12
- pcm_file_1 shift_1 orientation_1
13
- pcm_file_2 shift_2 orientation_2
14
- pcm_file_3 shift_3 orientation_3
15
- EOS
16
-
17
- argv = ARGV
18
- default_options = {x_unit: 30, y_unit: 60, words_count: nil, icd_mode: :discrete, threshold_lines: true, scheme: 'nucl_simpa', logo_shift: 300, text_size_pt: 24}
19
- cli = SequenceLogo::CLI.new(default_options)
20
- cli.instance_eval do
21
- parser.banner = doc
22
- parser.on_head('--logo-shift SHIFT', 'Width of region for labels') do |v|
23
- options[:logo_shift] = v.to_i
24
- end
25
- parser.on_head('--text-size SIZE', 'Text size in points') do |v|
26
- options[:text_size] = v.to_f
27
- end
28
- end
29
- options = cli.parse_options!(argv)
30
-
31
- output_file = argv.shift
32
- raise ArgumentError, 'Specify output file' unless output_file
33
-
34
- raise 'You can specify alignment infos either from file or from stdin. Don\'t use both sources simultaneously' if !ARGV.empty? && !$stdin.tty?
35
- if !ARGV.empty?
36
- alignment_infos = File.readlines(ARGV.shift)
37
- elsif !$stdin.tty?
38
- alignment_infos = $stdin.readlines
39
- else
40
- raise ArgumentError, 'Specify alignment infos'
41
- end
42
-
43
- logos = {}
44
- logo_filenames = []
45
- alignment_infos.each do |line|
46
- filename, shift, orientation = line.strip.split("\t")
47
- ppm = get_ppm_from_file(filename)
48
- checkerr("bad input file: #{filename}") { ppm == nil }
49
- shift = shift.to_i
50
- logo_filename = "#{filename}_temp.png"
51
- logo_filenames << logo_filename
52
- case orientation
53
- when 'direct'
54
- SequenceLogo.draw_logo(ppm, options).write(logo_filename)
55
- when 'revcomp'
56
- SequenceLogo.draw_logo(ppm.revcomp, options).write(logo_filename)
57
- else
58
- raise "Unknown orientation #{orientation} for #{filename}"
59
- end
60
- logos[logo_filename] = {shift: shift, length: ppm.length, name: File.basename(filename, File.extname(filename))}
61
- end
62
-
63
- SequenceLogo.glue_files(logos, output_file, options)
64
- logo_filenames.each{|filename| File.delete(filename) }
65
- rescue => err
66
- $stderr.puts "\n#{err}\n#{err.backtrace.first(5).join("\n")}\n\nUse --help option for help\n\n#{doc}"
1
+ require_relative '../../sequence_logo'
2
+ require 'fileutils'
3
+ require 'cgi'
4
+
5
+ def generate_glued_logo(alignment_infos, options, total_orientation, output_file)
6
+ logos = {}
7
+ logo_filenames = []
8
+ rightmost_side = alignment_infos.map do |line|
9
+ filename, shift, orientation = line.strip.split("\t")
10
+ shift = shift.to_i
11
+ shift + get_ppm_from_file(filename).length
12
+ end.max
13
+
14
+ alignment_infos.each do |line|
15
+ filename, shift, orientation = line.strip.split("\t")
16
+ ppm = get_ppm_from_file(filename)
17
+ shift = shift.to_i
18
+ raise 'Unknown orientation' unless %w[direct revcomp].include?(orientation.downcase)
19
+ if total_orientation == :revcomp
20
+ orientation = (orientation == 'direct') ? 'revcomp' : 'direct'
21
+ shift = rightmost_side - shift - ppm.length
22
+ end
23
+ checkerr("bad input file: #{filename}") { ppm == nil }
24
+ logo_filename = "#{filename}_temp.png"
25
+ logo_filenames << logo_filename
26
+ case orientation
27
+ when 'direct'
28
+ SequenceLogo.draw_logo(ppm, options).write(logo_filename)
29
+ when 'revcomp'
30
+ SequenceLogo.draw_logo(ppm.revcomp, options).write(logo_filename)
31
+ else
32
+ raise "Unknown orientation #{orientation} for #{filename}"
33
+ end
34
+ logos[logo_filename] = {shift: shift, length: ppm.length, name: CGI.unescape(File.basename(filename, File.extname(filename)))}
35
+ end
36
+
37
+ SequenceLogo.glue_files(logos, output_file, options)
38
+ logo_filenames.each{|filename| File.delete(filename) }
39
+ end
40
+
41
+ begin
42
+ doc = <<-EOS
43
+ Usage:
44
+ glue_logos <output file> <alignment infos file>
45
+ or
46
+ <alignment infos file> | glue_logos <output file>
47
+
48
+ Alignment infos has format:
49
+ pcm_file_1 shift_1 orientation_1
50
+ pcm_file_2 shift_2 orientation_2
51
+ pcm_file_3 shift_3 orientation_3
52
+ EOS
53
+
54
+ argv = ARGV
55
+ total_orientation = :direct
56
+ default_options = {x_unit: 30, y_unit: 60, words_count: nil, icd_mode: :discrete, threshold_lines: true, scheme: 'nucl_simpa', logo_shift: 300, text_size_pt: 24}
57
+ cli = SequenceLogo::CLI.new(default_options)
58
+ cli.instance_eval do
59
+ parser.banner = doc
60
+ parser.on_head('--logo-shift SHIFT', 'Width of region for labels') do |v|
61
+ options[:logo_shift] = v.to_i
62
+ end
63
+ parser.on_head('--text-size SIZE', 'Text size in points') do |v|
64
+ options[:text_size] = v.to_f
65
+ end
66
+ parser.on_head('--orientation ORIENTATION', 'Which logo to draw: direct/revcomp/both') do |v|
67
+ v = v.to_sym
68
+ raise ArgumentError, 'Orientation can be either direct or revcomp or both' unless [:direct, :revcomp, :both].include?(v)
69
+ total_orientation = v
70
+ end
71
+ end
72
+ options = cli.parse_options!(argv)
73
+
74
+ output_file = argv.shift
75
+ raise ArgumentError, 'Specify output file' unless output_file
76
+
77
+ raise 'You can specify alignment infos either from file or from stdin. Don\'t use both sources simultaneously' if !ARGV.empty? && !$stdin.tty?
78
+ if !ARGV.empty?
79
+ alignment_infos = File.readlines(ARGV.shift)
80
+ elsif !$stdin.tty?
81
+ alignment_infos = $stdin.readlines
82
+ else
83
+ raise ArgumentError, 'Specify alignment infos'
84
+ end
85
+
86
+ if total_orientation == :both
87
+ extname = File.extname(output_file)
88
+ basename = File.basename(output_file, extname)
89
+ dirname = File.dirname(output_file)
90
+ generate_glued_logo(alignment_infos, options, :direct, File.join(dirname, "#{basename}_direct.#{extname}"))
91
+ generate_glued_logo(alignment_infos, options, :revcomp, File.join(dirname, "#{basename}_revcomp.#{extname}"))
92
+ else
93
+ generate_glued_logo(alignment_infos, options, total_orientation, output_file)
94
+ end
95
+
96
+ rescue => err
97
+ $stderr.puts "\n#{err}\n#{err.backtrace.first(5).join("\n")}\n\nUse --help option for help\n\n#{doc}"
67
98
  end
@@ -1,52 +1,52 @@
1
- require_relative '../../sequence_logo'
2
- require 'shellwords'
3
-
4
- begin
5
- doc = <<-EOS
6
- sequence_logo is a tool for drawing motif logos. It is able to process PCM files either as a position matrix (*.pat or *.pcm), or in FASTA format (file extensions: .mfa, .fasta, .plain), or in SMall BiSMark format (.xml), or in IUPAC format (any other extension).
7
- Usage:
8
- sequence_logo [options] <pcm/ppm file>...
9
- or
10
- ls pcm_folder/*.pcm | sequence_logo [options]
11
- EOS
12
-
13
- argv = ARGV
14
- default_options = {x_unit: 30, y_unit: 60, words_count: nil, orientation: :both, logo_folder: '.', icd_mode: :discrete, threshold_lines: true, scheme: 'nucl_simpa'}
15
- cli = SequenceLogo::CLI.new(default_options)
16
- cli.instance_eval do
17
- parser.banner = doc
18
- parser.on_head('--logo-folder FOLDER', 'Folder to store generated logos') do |v|
19
- options[:logo_folder] = v
20
- end
21
- parser.on_head('--orientation ORIENTATION', 'Which logo to draw: direct/revcomp/both') do |v|
22
- v = v.to_sym
23
- raise ArgumentError, 'Orientation can be either direct or revcomp or both' unless [:direct, :revcomp, :both].include?(v)
24
- options[:orientation] = v
25
- end
26
- end
27
- options = cli.parse_options!(argv)
28
-
29
- logo_folder = options[:logo_folder]
30
- Dir.mkdir(logo_folder) unless Dir.exist?(logo_folder)
31
-
32
- filenames = argv
33
- filenames += $stdin.read.shellsplit unless $stdin.tty?
34
- raise ArgumentError, 'Specify at least one motif file' if filenames.empty?
35
-
36
- filenames.each do |filename|
37
- ppm = get_ppm_from_file(filename)
38
- checkerr("bad input file: #{filename}") { ppm == nil }
39
-
40
- filename_wo_ext = File.basename(filename, File.extname(filename))
41
- if [:direct, :both].include?(options[:orientation])
42
- direct_output = File.join(logo_folder, "#{filename_wo_ext}_direct.png")
43
- SequenceLogo.draw_logo(ppm, options).write(direct_output)
44
- end
45
- if [:revcomp, :both].include?(options[:orientation])
46
- revcomp_output = File.join(logo_folder, "#{filename_wo_ext}_revcomp.png")
47
- SequenceLogo.draw_logo(ppm.revcomp, options).write(revcomp_output)
48
- end
49
- end
50
- rescue => err
51
- $stderr.puts "\n#{err}\n#{err.backtrace.first(5).join("\n")}\n\nUse --help option for help\n\n#{doc}"
1
+ require_relative '../../sequence_logo'
2
+ require 'shellwords'
3
+
4
+ begin
5
+ doc = <<-EOS
6
+ sequence_logo is a tool for drawing motif logos. It is able to process PCM files either as a position matrix (*.pat or *.pcm), or in FASTA format (file extensions: .mfa, .fasta, .plain), or in SMall BiSMark format (.xml), or in IUPAC format (any other extension).
7
+ Usage:
8
+ sequence_logo [options] <pcm/ppm file>...
9
+ or
10
+ ls pcm_folder/*.pcm | sequence_logo [options]
11
+ EOS
12
+
13
+ argv = ARGV
14
+ default_options = {x_unit: 30, y_unit: 60, words_count: nil, orientation: :both, logo_folder: '.', icd_mode: :discrete, threshold_lines: true, scheme: 'nucl_simpa'}
15
+ cli = SequenceLogo::CLI.new(default_options)
16
+ cli.instance_eval do
17
+ parser.banner = doc
18
+ parser.on_head('--logo-folder FOLDER', 'Folder to store generated logos') do |v|
19
+ options[:logo_folder] = v
20
+ end
21
+ parser.on_head('--orientation ORIENTATION', 'Which logo to draw: direct/revcomp/both') do |v|
22
+ v = v.to_sym
23
+ raise ArgumentError, 'Orientation can be either direct or revcomp or both' unless [:direct, :revcomp, :both].include?(v)
24
+ options[:orientation] = v
25
+ end
26
+ end
27
+ options = cli.parse_options!(argv)
28
+
29
+ logo_folder = options[:logo_folder]
30
+ Dir.mkdir(logo_folder) unless Dir.exist?(logo_folder)
31
+
32
+ filenames = argv
33
+ filenames += $stdin.read.shellsplit unless $stdin.tty?
34
+ raise ArgumentError, 'Specify at least one motif file' if filenames.empty?
35
+
36
+ filenames.each do |filename|
37
+ ppm = get_ppm_from_file(filename)
38
+ checkerr("bad input file: #{filename}") { ppm == nil }
39
+
40
+ filename_wo_ext = File.basename(filename, File.extname(filename))
41
+ if [:direct, :both].include?(options[:orientation])
42
+ direct_output = File.join(logo_folder, "#{filename_wo_ext}_direct.png")
43
+ SequenceLogo.draw_logo(ppm, options).write(direct_output)
44
+ end
45
+ if [:revcomp, :both].include?(options[:orientation])
46
+ revcomp_output = File.join(logo_folder, "#{filename_wo_ext}_revcomp.png")
47
+ SequenceLogo.draw_logo(ppm.revcomp, options).write(revcomp_output)
48
+ end
49
+ end
50
+ rescue => err
51
+ $stderr.puts "\n#{err}\n#{err.backtrace.first(5).join("\n")}\n\nUse --help option for help\n\n#{doc}"
52
52
  end