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.
@@ -1,147 +1,147 @@
1
- module Ytilib
2
- def Ytilib.time
3
- return Time.now.strftime('%d %b %H:%M:%S')
4
- end
5
- end
6
-
7
- $program_name = nil
8
-
9
- def start(fullpath)
10
- report(fullpath + ARGV.inject("") { |out, v| out += " " + v})
11
- return if $NO_REPORT
12
- $program_name = "[#{File.name_wo_ext(fullpath)}]"
13
- end
14
-
15
- def report(message, program_name = nil)
16
- $program_name = "[#{program_name}]" if program_name != nil
17
- return if $NO_REPORT
18
- puts "LLIB #{Ytilib.time} #{$program_name}\t#{message}" if !block_given? || yield
19
- end
20
-
21
- def checkerr(message = "checkerr failed")
22
- if !block_given? || yield
23
- puts "LLIB #{Ytilib.time} [error]\t#{message}" unless $NO_REPORT
24
- raise "LLIB #{Ytilib.time} #{$program_name}\n\t#{message}\n"
25
- end
26
- end
27
-
28
- module Ytilib
29
-
30
- STRAND_DIRECT = "direct"
31
- STRAND_REVCOMP = "revcomp"
32
-
33
- def Ytilib.read_mfa2hash(path)
34
- input_fasta_f = File.new(path, "r")
35
- seqs, seq_name = {}, nil
36
- input_fasta_f.each_line { |line|
37
- if line[0,1] == ">"
38
- seq_name = line[1..-1].strip
39
- seq_name = yield seq_name if block_given?
40
- checkerr("multiple sequences with the same name=#{seq_name}") { seqs[seq_name] }
41
- seqs[seq_name] = ""
42
- elsif seq_name != nil
43
- seqs[seq_name] << line.strip
44
- end
45
- }
46
- input_fasta_f.close
47
- return seqs
48
- end
49
-
50
- def Ytilib.read_mfa2array(path)
51
- input_fasta_f = File.new(path, "r")
52
- seqs, seq_name = [], nil
53
- input_fasta_f.each_line { |line|
54
- if line[0,1] == ">"
55
- seq_name = line[1..-1].strip
56
- yield seq_name if block_given?
57
- seqs << ""
58
- elsif seq_name != nil
59
- seqs.last << line.strip
60
- end
61
- }
62
- input_fasta_f.close
63
- return seqs
64
- end
65
-
66
- def Ytilib.mfa2array(input)
67
- seqs, seq_name = [], nil
68
- input.each_line { |line|
69
- if line[0,1] == ">"
70
- seq_name = line[1..-1].strip
71
- seqs << ""
72
- elsif seq_name != nil
73
- seqs.last << line.strip
74
- end
75
- }
76
- return seqs
77
- end
78
-
79
- def Ytilib.read_plain2array(path)
80
- array = []
81
- File.open(path).each_line { |line|
82
- array << line.strip if !line.strip.empty?
83
- }
84
- return array
85
- end
86
-
87
- def Ytilib.read_seqs2array(path)
88
- type = File.ext_wo_name(path)
89
- case type
90
- when "mfa", "fasta", "fa"
91
- return Ytilib.read_mfa2array(path)
92
- when "plain","txt"
93
- return Ytilib.read_plain2array(path)
94
- else
95
- checkerr("unknown sequences-file, ext=#{type}")
96
- end
97
- end
98
-
99
- def Ytilib.write_mfa(seqs, path, prefix = " ")
100
- if seqs.is_a?(Hash)
101
- out_fasta_f = File.new(path, "w+")
102
- seqs.each_key { |name|
103
- out_fasta_f << ">#{prefix}#{name}" << $/ << seqs[name] << $/
104
- }
105
- out_fasta_f.close
106
- else
107
- out_fasta_f = File.new(path, "w+")
108
- seqs.each_with_index { |seq, i|
109
- out_fasta_f << ">#{prefix}#{i+1}" << $/ << seq << $/
110
- }
111
- out_fasta_f.close
112
- end
113
- end
114
-
115
- def get_consensus(seqs)
116
- report "consensus creating method should be checked, you are using unsafe code"
117
- return 'nil' if seqs.size == 0
118
- conslet = { 'A' => 'A', 'C' => 'C', 'G' => 'G', 'T' => 'T', 'U' => 'U',
119
- 'AG' => 'R', 'CT' => 'Y', 'GT' => 'K', 'AC' => 'M', 'CG' => 'S', 'AT' => 'W',
120
- 'CGT' => 'B', 'AGT' => 'D', 'ACT' => 'H', 'ACG' => 'V', 'ACGT' => 'N'
121
- }
122
- new_consensus, letters = '', []
123
- 0.upto(seqs[0].size-1) { |i|
124
- seqs.each do |word|
125
- letters << word[i] if !letters.include?(word[i])
126
- end
127
- letters.sort!
128
- letters_string = ''
129
- letters.each do |letter| letters_string << letter end
130
- checkerr("cannot find consensus letter for a given letter set :#{}") { conslet[letters_string] == nil }
131
- new_consensus << conslet[letters_string]
132
- letters.clear
133
- }
134
- return new_consensus
135
- end
136
-
137
- def Ytilib.new_mysql_conn(database)
138
- my = Mysql.new(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, database)
139
- checkerr("cannot connect to MySQL server") { my.query("select 1").fetch_row[0] != "1" }
140
- return my
141
- end
142
-
143
-
144
- end
145
-
146
- #report "ytilib required, working directory #{Dir.pwd}", "ytilib"
1
+ module Ytilib
2
+ def Ytilib.time
3
+ return Time.now.strftime('%d %b %H:%M:%S')
4
+ end
5
+ end
6
+
7
+ $program_name = nil
8
+
9
+ def start(fullpath)
10
+ report(fullpath + ARGV.inject("") { |out, v| out += " " + v})
11
+ return if $NO_REPORT
12
+ $program_name = "[#{File.name_wo_ext(fullpath)}]"
13
+ end
14
+
15
+ def report(message, program_name = nil)
16
+ $program_name = "[#{program_name}]" if program_name != nil
17
+ return if $NO_REPORT
18
+ puts "LLIB #{Ytilib.time} #{$program_name}\t#{message}" if !block_given? || yield
19
+ end
20
+
21
+ def checkerr(message = "checkerr failed")
22
+ if !block_given? || yield
23
+ puts "LLIB #{Ytilib.time} [error]\t#{message}" unless $NO_REPORT
24
+ raise "LLIB #{Ytilib.time} #{$program_name}\n\t#{message}\n"
25
+ end
26
+ end
27
+
28
+ module Ytilib
29
+
30
+ STRAND_DIRECT = "direct"
31
+ STRAND_REVCOMP = "revcomp"
32
+
33
+ def Ytilib.read_mfa2hash(path)
34
+ input_fasta_f = File.new(path, "r")
35
+ seqs, seq_name = {}, nil
36
+ input_fasta_f.each_line { |line|
37
+ if line[0,1] == ">"
38
+ seq_name = line[1..-1].strip
39
+ seq_name = yield seq_name if block_given?
40
+ checkerr("multiple sequences with the same name=#{seq_name}") { seqs[seq_name] }
41
+ seqs[seq_name] = ""
42
+ elsif seq_name != nil
43
+ seqs[seq_name] << line.strip
44
+ end
45
+ }
46
+ input_fasta_f.close
47
+ return seqs
48
+ end
49
+
50
+ def Ytilib.read_mfa2array(path)
51
+ input_fasta_f = File.new(path, "r")
52
+ seqs, seq_name = [], nil
53
+ input_fasta_f.each_line { |line|
54
+ if line[0,1] == ">"
55
+ seq_name = line[1..-1].strip
56
+ yield seq_name if block_given?
57
+ seqs << ""
58
+ elsif seq_name != nil
59
+ seqs.last << line.strip
60
+ end
61
+ }
62
+ input_fasta_f.close
63
+ return seqs
64
+ end
65
+
66
+ def Ytilib.mfa2array(input)
67
+ seqs, seq_name = [], nil
68
+ input.each_line { |line|
69
+ if line[0,1] == ">"
70
+ seq_name = line[1..-1].strip
71
+ seqs << ""
72
+ elsif seq_name != nil
73
+ seqs.last << line.strip
74
+ end
75
+ }
76
+ return seqs
77
+ end
78
+
79
+ def Ytilib.read_plain2array(path)
80
+ array = []
81
+ File.open(path).each_line { |line|
82
+ array << line.strip if !line.strip.empty?
83
+ }
84
+ return array
85
+ end
86
+
87
+ def Ytilib.read_seqs2array(path)
88
+ type = File.ext_wo_name(path)
89
+ case type
90
+ when "mfa", "fasta", "fa"
91
+ return Ytilib.read_mfa2array(path)
92
+ when "plain","txt"
93
+ return Ytilib.read_plain2array(path)
94
+ else
95
+ checkerr("unknown sequences-file, ext=#{type}")
96
+ end
97
+ end
98
+
99
+ def Ytilib.write_mfa(seqs, path, prefix = " ")
100
+ if seqs.is_a?(Hash)
101
+ out_fasta_f = File.new(path, "w+")
102
+ seqs.each_key { |name|
103
+ out_fasta_f << ">#{prefix}#{name}" << $/ << seqs[name] << $/
104
+ }
105
+ out_fasta_f.close
106
+ else
107
+ out_fasta_f = File.new(path, "w+")
108
+ seqs.each_with_index { |seq, i|
109
+ out_fasta_f << ">#{prefix}#{i+1}" << $/ << seq << $/
110
+ }
111
+ out_fasta_f.close
112
+ end
113
+ end
114
+
115
+ def get_consensus(seqs)
116
+ report "consensus creating method should be checked, you are using unsafe code"
117
+ return 'nil' if seqs.size == 0
118
+ conslet = { 'A' => 'A', 'C' => 'C', 'G' => 'G', 'T' => 'T', 'U' => 'U',
119
+ 'AG' => 'R', 'CT' => 'Y', 'GT' => 'K', 'AC' => 'M', 'CG' => 'S', 'AT' => 'W',
120
+ 'CGT' => 'B', 'AGT' => 'D', 'ACT' => 'H', 'ACG' => 'V', 'ACGT' => 'N'
121
+ }
122
+ new_consensus, letters = '', []
123
+ 0.upto(seqs[0].size-1) { |i|
124
+ seqs.each do |word|
125
+ letters << word[i] if !letters.include?(word[i])
126
+ end
127
+ letters.sort!
128
+ letters_string = ''
129
+ letters.each do |letter| letters_string << letter end
130
+ checkerr("cannot find consensus letter for a given letter set :#{}") { conslet[letters_string] == nil }
131
+ new_consensus << conslet[letters_string]
132
+ letters.clear
133
+ }
134
+ return new_consensus
135
+ end
136
+
137
+ def Ytilib.new_mysql_conn(database)
138
+ my = Mysql.new(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, database)
139
+ checkerr("cannot connect to MySQL server") { my.query("select 1").fetch_row[0] != "1" }
140
+ return my
141
+ end
142
+
143
+
144
+ end
145
+
146
+ #report "ytilib required, working directory #{Dir.pwd}", "ytilib"
147
147
  include Ytilib
@@ -1,10 +1,10 @@
1
- require_relative 'ytilib/ytilib'
2
- require_relative 'ytilib/addon'
3
- require_relative 'ytilib/iupac'
4
- require_relative 'ytilib/pm'
5
- require_relative 'ytilib/pmsd'
6
- require_relative 'ytilib/randoom'
7
- require_relative 'ytilib/bismark'
8
- require_relative 'ytilib/hack1'
9
- require_relative 'ytilib/infocod'
1
+ require_relative 'ytilib/ytilib'
2
+ require_relative 'ytilib/addon'
3
+ require_relative 'ytilib/iupac'
4
+ require_relative 'ytilib/pm'
5
+ require_relative 'ytilib/pmsd'
6
+ require_relative 'ytilib/randoom'
7
+ require_relative 'ytilib/bismark'
8
+ require_relative 'ytilib/hack1'
9
+ require_relative 'ytilib/infocod'
10
10
  require_relative 'ytilib/ppm_support'
data/lib/sequence_logo.rb CHANGED
@@ -1,7 +1,7 @@
1
- require_relative 'sequence_logo/version'
2
- require_relative 'sequence_logo/pmflogo_lib'
3
- require_relative 'sequence_logo/cli'
4
-
5
- module SequenceLogo
6
- AssetsPath = File.join(File.dirname(__FILE__), 'sequence_logo', 'assets')
7
- end
1
+ require_relative 'sequence_logo/version'
2
+ require_relative 'sequence_logo/pmflogo_lib'
3
+ require_relative 'sequence_logo/cli'
4
+
5
+ module SequenceLogo
6
+ AssetsPath = File.join(File.dirname(__FILE__), 'sequence_logo', 'assets')
7
+ end
@@ -1,21 +1,21 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/sequence_logo/version', __FILE__)
3
-
4
- Gem::Specification.new do |gem|
5
- gem.authors = ["Ilya Vorontsov"]
6
- gem.email = ["prijutme4ty@gmail.com"]
7
- gem.description = %q{SequenceLogo is a tool for drawing sequence logos of motifs. It gets Positional Count Matrices(PCMs) or IUPAC sequences as input and generates png-logos for a motif. Also one can create logo for reverse complement or even generate logos for a whole collection of motifs.
8
- 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/)
9
- }
10
- gem.summary = %q{Tool for drawing sequence logos of motifs}
11
- gem.homepage = ""
12
-
13
- gem.files = `git ls-files`.split($/)
14
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
- gem.name = "sequence_logo"
17
- gem.require_paths = ["lib"]
18
- gem.version = SequenceLogo::VERSION
19
-
20
- gem.add_dependency('rmagick', '~> 2.13.1')
21
- end
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/sequence_logo/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Ilya Vorontsov"]
6
+ gem.email = ["prijutme4ty@gmail.com"]
7
+ gem.description = %q{SequenceLogo is a tool for drawing sequence logos of motifs. It gets Positional Count Matrices(PCMs) or IUPAC sequences as input and generates png-logos for a motif. Also one can create logo for reverse complement or even generate logos for a whole collection of motifs.
8
+ 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/)
9
+ }
10
+ gem.summary = %q{Tool for drawing sequence logos of motifs}
11
+ gem.homepage = ""
12
+
13
+ gem.files = `git ls-files`.split($/)
14
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
15
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
16
+ gem.name = "sequence_logo"
17
+ gem.require_paths = ["lib"]
18
+ gem.version = SequenceLogo::VERSION
19
+
20
+ gem.add_dependency('rmagick', '~> 2.13.1')
21
+ end
@@ -1,10 +1,10 @@
1
- AHR_si
2
- 40.51343240527031 18.259112547756697 56.41253757072521 38.77363485291994
3
- 10.877470982533044 11.870876719950774 34.66312982331297 96.54723985087516
4
- 21.7165707818416 43.883079837598544 20.706746561638717 67.6523201955933
5
- 2.5465132509466635 1.3171620263517245 145.8637051322628 4.231336967110781
6
- 0.0 150.35847450464382 1.4927836298652875 2.1074592421627525
7
- 3.441039751299748 0.7902972158110341 149.37613720253387 0.3512432070271259
8
- 0.0 3.441039751299748 0.7024864140542533 149.81519121131782
9
- 0.0 0.0 153.95871737667187 0.0
10
- 43.07922333291745 66.87558226865211 16.159862546986584 27.844049228115868
1
+ AHR_si
2
+ 40.51343240527031 18.259112547756697 56.41253757072521 38.77363485291994
3
+ 10.877470982533044 11.870876719950774 34.66312982331297 96.54723985087516
4
+ 21.7165707818416 43.883079837598544 20.706746561638717 67.6523201955933
5
+ 2.5465132509466635 1.3171620263517245 145.8637051322628 4.231336967110781
6
+ 0.0 150.35847450464382 1.4927836298652875 2.1074592421627525
7
+ 3.441039751299748 0.7902972158110341 149.37613720253387 0.3512432070271259
8
+ 0.0 3.441039751299748 0.7024864140542533 149.81519121131782
9
+ 0.0 0.0 153.95871737667187 0.0
10
+ 43.07922333291745 66.87558226865211 16.159862546986584 27.844049228115868
@@ -1,19 +1,19 @@
1
- AIRE_f2
2
- 16.428571428571484 10.795918367346953 5.1632653061224625 8.918367346938803
3
- 7.51020408163268 7.51020408163268 5.632653061224489 20.65306122448985
4
- 5.632653061224489 5.632653061224489 8.448979591836776 21.591836734693906
5
- 1.877551020408166 0.0 36.612244897959265 2.8163265306122534
6
- 0.0 0.0 33.79591836734698 7.51020408163268
7
- 13.14285714285717 1.877551020408166 0.938775510204083 25.346938775510242
8
- 15.959183673469415 3.755102040816336 0.938775510204083 20.65306122448985
9
- 15.02040816326536 5.632653061224489 5.632653061224489 15.02040816326536
10
- 14.081632653061265 2.8163265306122534 5.632653061224489 18.775510204081698
11
- 21.591836734693945 3.755102040816336 5.632653061224489 10.326530612244925
12
- 15.959183673469415 1.877551020408166 2.8163265306122534 20.65306122448985
13
- 9.38775510204083 5.632653061224489 2.8163265306122534 23.469387755102094
14
- 0.0 0.938775510204083 36.612244897959265 3.755102040816336
15
- 0.0 0.0 40.36734693877556 0.938775510204083
16
- 9.38775510204083 3.755102040816336 10.326530612244925 17.836734693877606
17
- 2.8163265306122534 7.51020408163268 7.51020408163268 23.469387755102094
18
- 18.77551020408166 0.938775510204083 6.571428571428585 15.02040816326536
19
- 16.663265306122497 11.030612244898006 4.45918367346938 9.153061224489816
1
+ AIRE_f2
2
+ 16.428571428571484 10.795918367346953 5.1632653061224625 8.918367346938803
3
+ 7.51020408163268 7.51020408163268 5.632653061224489 20.65306122448985
4
+ 5.632653061224489 5.632653061224489 8.448979591836776 21.591836734693906
5
+ 1.877551020408166 0.0 36.612244897959265 2.8163265306122534
6
+ 0.0 0.0 33.79591836734698 7.51020408163268
7
+ 13.14285714285717 1.877551020408166 0.938775510204083 25.346938775510242
8
+ 15.959183673469415 3.755102040816336 0.938775510204083 20.65306122448985
9
+ 15.02040816326536 5.632653061224489 5.632653061224489 15.02040816326536
10
+ 14.081632653061265 2.8163265306122534 5.632653061224489 18.775510204081698
11
+ 21.591836734693945 3.755102040816336 5.632653061224489 10.326530612244925
12
+ 15.959183673469415 1.877551020408166 2.8163265306122534 20.65306122448985
13
+ 9.38775510204083 5.632653061224489 2.8163265306122534 23.469387755102094
14
+ 0.0 0.938775510204083 36.612244897959265 3.755102040816336
15
+ 0.0 0.0 40.36734693877556 0.938775510204083
16
+ 9.38775510204083 3.755102040816336 10.326530612244925 17.836734693877606
17
+ 2.8163265306122534 7.51020408163268 7.51020408163268 23.469387755102094
18
+ 18.77551020408166 0.938775510204083 6.571428571428585 15.02040816326536
19
+ 16.663265306122497 11.030612244898006 4.45918367346938 9.153061224489816
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequence_logo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Vorontsov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-30 00:00:00.000000000 Z
11
+ date: 2014-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rmagick
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
90
  version: '0'
91
91
  requirements: []
92
92
  rubyforge_project:
93
- rubygems_version: 2.0.3
93
+ rubygems_version: 2.2.1
94
94
  signing_key:
95
95
  specification_version: 4
96
96
  summary: Tool for drawing sequence logos of motifs
@@ -101,4 +101,3 @@ test_files:
101
101
  - test/data/logo/AIRE_f2_revcomp.png
102
102
  - test/data/pcm/AHR_si.pcm
103
103
  - test/data/pcm/AIRE_f2.pcm
104
- has_rdoc: