youplot 0.4.2 → 0.4.3

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
  SHA256:
3
- metadata.gz: 04d898a5d15b1a38a92bf3823b6c1a971d17acf6000740867c09f35fa78a2a06
4
- data.tar.gz: 9c5353687b33c75e953458fc824b1fa7386f980fbd9b11994f94bb8f06e6a387
3
+ metadata.gz: 5b3b1cbdabc0a74b4010d13fa59fe9724ac9c07783414a7a7584f8cab27b49ec
4
+ data.tar.gz: f5cf98b592a248c4d74e06078d97050e85c892e94c0dd78ec17e92f6bdc856d0
5
5
  SHA512:
6
- metadata.gz: 5677d91bdd78e7de332557434fe377d316e302abb7476ee99fef0fab3dee03a40c702c10d7e1b70cc1cb22e8c5049236408849cc3f208c8372c70ce2dcb251d6
7
- data.tar.gz: a5948c77d03ec831357c9774e8ef3346b7684944b606b5598620e4723fd233160af6a32377436d1ef4271655cbd3078572cb5f88c14de4ddd63043778dc99c00
6
+ metadata.gz: aebe50c600b66e9cb8e3a64da3ddafff70472f495d51b812987cc835017ca19fd1347fbe2ee88fac66e111837ffef59bf6c271f2f6515ae7e60a526050ded5b3
7
+ data.tar.gz: b37e2a5a2d8eb33700690d28b6e6f5851fbefb0e88ae10bcb6d9f65f06f966c31b81c7587135c6d296bde0caefbc81239046ec06535cefa9329f2ac6d8a8788f
data/README.md CHANGED
@@ -1,18 +1,15 @@
1
1
  <div align="center">
2
- <img src="logo.svg" width="66%" height="66%" />
3
-
2
+ <img src="logo.svg">
4
3
  <hr>
4
+ <img alt="Build Status" src="https://github.com/red-data-tools/YouPlot/workflows/test/badge.svg">
5
+ <a href="https://rubygems.org/gems/youplot/"><img alt="Gem Version" src="https://badge.fury.io/rb/youplot.svg"></a>
6
+ <a href="https://zenodo.org/badge/latestdoi/283230219"><img alt="DOI" src="https://zenodo.org/badge/283230219.svg"></a>
7
+ <a href="https://rubydoc.info/gems/youplot/"><img alt="Docs Stable" src="https://img.shields.io/badge/docs-stable-blue.svg"></a>
8
+ <a href="LICENSE.txt"><img alt="The MIT License" src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
5
9
 
6
- ![Build Status](https://github.com/red-data-tools/YouPlot/workflows/test/badge.svg)
7
- [![Gem Version](https://badge.fury.io/rb/youplot.svg)](https://badge.fury.io/rb/youplot)
8
- [![Docs Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://rubydoc.info/gems/youplot)
9
- [![The MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE.txt)
10
- [![DOI](https://zenodo.org/badge/283230219.svg)](https://zenodo.org/badge/latestdoi/283230219)
11
-
12
- YouPlot is a command line tool that draws plots in a terminal.
10
+ YouPlot is a command line tool that draws plots on the terminal.
13
11
 
14
12
  :bar_chart: Powered by [UnicodePlot](https://github.com/red-data-tools/unicode_plot.rb)
15
-
16
13
  </div>
17
14
 
18
15
  ## Installation
@@ -23,8 +20,9 @@ gem install youplot
23
20
 
24
21
  ## Quick Start
25
22
 
26
- * `cat data.tsv | uplot <command> [options]` or
27
- * `uplot <command> [options] <data.tsv>`
23
+ <img alt="barplot" src="https://user-images.githubusercontent.com/5798442/101999903-d36a2d00-3d24-11eb-9361-b89116f44122.png" width=160> <img alt="histogram" src="https://user-images.githubusercontent.com/5798442/101999820-21cafc00-3d24-11eb-86db-e410d19b07df.png" width=160> <img alt="scatter" src="https://user-images.githubusercontent.com/5798442/101999827-27284680-3d24-11eb-9903-551857eaa69c.png" width=160> <img alt="density" src="https://user-images.githubusercontent.com/5798442/101999828-2abbcd80-3d24-11eb-902c-2f44266fa6ae.png" width=160> <img alt="boxplot" src="https://user-images.githubusercontent.com/5798442/101999830-2e4f5480-3d24-11eb-8891-728c18bf5b35.png" width=160>
24
+
25
+ `uplot <command> [options] <data.tsv>`
28
26
 
29
27
  ### barplot
30
28
 
@@ -36,7 +34,7 @@ curl -sL https://git.io/ISLANDScsv \
36
34
  ```
37
35
 
38
36
  <p align="center">
39
- <img alt="barplot" src="https://user-images.githubusercontent.com/5798442/101999903-d36a2d00-3d24-11eb-9361-b89116f44122.png">
37
+ <img alt="barplot" src="https://user-images.githubusercontent.com/5798442/101999903-d36a2d00-3d24-11eb-9361-b89116f44122.png">
40
38
  </p>
41
39
 
42
40
  ### histogram
@@ -103,10 +101,6 @@ curl -sL https://git.io/IRIStsv \
103
101
 
104
102
  ### count
105
103
 
106
- In this example, YouPlot counts the number of chromosomes where the gene is located from the human gene annotation file and it creates a bar chart. The human gene annotation file can be downloaded from the following website.
107
-
108
- * https://www.gencodegenes.org/human/
109
-
110
104
  ```sh
111
105
  cat gencode.v35.annotation.gff3 \
112
106
  | grep -v '#' | grep 'gene' | cut -f1 \
@@ -117,23 +111,21 @@ cat gencode.v35.annotation.gff3 \
117
111
  <img alt="count" src="https://user-images.githubusercontent.com/5798442/101999832-30b1ae80-3d24-11eb-96fe-e5000bed1f5c.png">
118
112
  </p>
119
113
 
114
+ In this example, YouPlot counts the number of chromosomes where genes are located.
115
+ * [GENCODE - Human Release](https://www.gencodegenes.org/human/)
116
+
120
117
  Note: `count` is not very fast because it runs in a Ruby script.
121
118
  This is fine in most cases, as long as the data size is small. If you want to visualize huge data, it is faster to use a combination of common Unix commands as shown below.
122
119
 
123
120
  ```sh
124
121
  cat gencode.v35.annotation.gff3 | grep -v '#' | grep 'gene' | cut -f1 \
125
- | sort | uniq -c | sort -nrk2 | awk '{print $2,$1}' \
126
- | uplot bar -d ' ' -t "The number of human gene annotations per chromosome" -c blue
122
+ | sort | uniq -c | sort -nrk1 \
123
+ | uplot bar --fmt yx -d ' ' -t "The number of human gene annotations per chromosome" -c blue
127
124
  ```
128
125
 
129
126
  ## Usage
130
127
 
131
- ### Why YouPlot?
132
-
133
- Wouldn't it be a pain to have to run R, Python, Julia, gnuplot or whatever REPL just to check your data?
134
- YouPlot is a command line tool for this purpose. With YouPlot, you can continue working without leaving your terminal and shell.
135
-
136
- ### How to use YouPlot?
128
+ ### Commands
137
129
 
138
130
  `uplot` is the shortened form of `youplot`. You can use either.
139
131
 
@@ -143,18 +135,7 @@ YouPlot is a command line tool for this purpose. With YouPlot, you can continue
143
135
  | `uplot <command> [options] data.tsv ...` | Take input from files |
144
136
  | `pipeline1 \| uplot <command> -O \| pipeline2` | Outputs data from stdin to stdout |
145
137
 
146
- ### Where to output the plot?
147
-
148
- By default, the plot is output to *standard error output*.
149
- The output file or stream for the plot can be specified with the `-o` option.
150
-
151
- ### Where to output the input data?
152
-
153
- By default, the input data is not shown anywhere.
154
- The `-O` option, with no arguments, outputs the input data directly to the standard output.
155
- This is useful when passing data to a subsequent pipeline.
156
-
157
- ### What types of plots are available?
138
+ ### Subcommands
158
139
 
159
140
  The following sub-commands are available.
160
141
 
@@ -167,66 +148,75 @@ The following sub-commands are available.
167
148
  | scatter | s | draw a scatter plot |
168
149
  | density | d | draw a density plot |
169
150
  | boxplot | box | draw a horizontal boxplot |
151
+ | | | |
152
+ | count | c | draw a barplot based on the number of occurrences (slow) |
153
+ | | | |
154
+ | colors | color | show the list of available colors |
170
155
 
171
- See Quick Start for `count`.
156
+ ### Output the plot
172
157
 
173
- | command | short | how it works |
174
- |-----------|-------|----------------------------------------------------------|
175
- | count | c | draw a barplot based on the number of occurrences (slow) |
158
+ * `-o`
159
+ * By default, the plot is output to **standard error output**.
160
+ * If you want to output to standard input, Use hyphen ` -o -` or no argument `uplot s -o | `.
176
161
 
177
- ### What if the header line is included?
162
+ ### Output the input data
178
163
 
179
- If your input data contains a header line, you need to specify the `-H` option.
164
+ * `-O`
165
+ * By default, the input data is not shown anywhere.
166
+ * If you want to pass the input data directly to the standard output, Use hyphen `-O -` or no argument `uplot s -O |`.
167
+ * This is useful when passing data to a subsequent pipeline.
180
168
 
181
- ### How to specify the delimiter?
169
+ ### Header
182
170
 
183
- Use the `-d` option. To specify a blank space, you can use `uplot bar -d ' ' data.txt`.
184
- You do not need to use `-d` option for tab-delimited text since the default value is tab.
171
+ * `-H`
172
+ * If input data contains a header line, you need to specify the `-H` option.
185
173
 
186
- ### Is there a way to specify a column as the x-axis or y-axis?
174
+ ### Delimiter
187
175
 
188
- Not yet.
189
- YouPlot treats the first column as the X axis and the second column as the Y axis.
190
- When working with multiple series, the first column is the X axis, the second column is series Y1, the third column is series Y2, and so on.
191
- If you pass only one column of data for `line` and `bar`, YouPlot will automatically use a sequential number starting from 1 as the X-axis.
176
+ * `-d`
177
+ * You do not need to use `-d` option for tab-delimited text since the default value is tab.
178
+ * To specify a blank space, you can use `uplot bar -d ' ' data.txt`.
192
179
 
193
- * `--fmt xyy` `--fmt xyxy` `--fmt yx` options give you a few more choices.
194
- See `youplot <command> --help` for more details.
180
+ ### Real-time data
195
181
 
196
- * Use `awk '{print $2, $1}'` to swap lines.
197
- * Use `paste` to concatenate series.
182
+ * `-p` `--progress`
183
+ * Experimental progressive mode is currently under development.
184
+ * `ruby -e 'loop{puts rand(100)}' | uplot line --progress`
198
185
 
199
- ### How to plot real-time data?
186
+ ### Show detailed options for subcommands
200
187
 
201
- Experimental progressive mode is currently under development.
188
+ * `--help`
189
+ * The `--help` option will show more detailed options for each subcommand.
190
+ * `uplot hist --help`
202
191
 
203
- ```sh
204
- ruby -e 'loop{puts rand(100)}' | uplot line --progress
205
- ```
192
+ ### Set columns as x-axis or y-axis
206
193
 
207
- ### How to view detailed command line options?
194
+ * YouPlot treats the first column as the X axis and the second column as the Y axis. When working with multiple series, the first column is the X axis, the second column is series Y1, the third column is series Y2, and so on.
195
+ * If you pass only one column of data for `line` and `bar`, YouPlot will automatically use a sequential number starting from 1 as the X-axis.
208
196
 
209
- Use `--help` to print command-specific options.
197
+ * `--fmt`
198
+ * `--fmt xyy` `--fmt xyxy` `--fmt yx` options give you a few more choices. See `youplot <command> --help` for more details.
199
+ * The fmt option may be renamed in the future.
200
+ * The `-x` and `-y` options might be used to specify columns in the future.
210
201
 
211
- `uplot hist --help`
202
+ * Use `awk '{print $2, $1}'` to swap columns. Use `paste` to concatenate series.
212
203
 
213
- ```
214
- Usage: uplot histogram [options] <in.tsv>
204
+ ### Categorical data
215
205
 
216
- Options for histogram:
217
- --symbol VAL character to be used to plot the bars
218
- --closed VAL side of the intervals to be closed [left]
219
- -n, --nbins VAL approximate number of bins
206
+ * With GNU datamash, you can manage to handle categorized data.
207
+ * `cat test/fixtures/iris.csv | sed '/^$/d' | datamash --header-in --output-delimiter=: -t, -g5 collapse 3,4 | cut -f2-3 -d: | sed 's/:/\n/g' | uplot s -d, -T --fmt xyxy`
208
+ * This is not so easy...
220
209
 
221
- Options:
222
- ...
223
- ```
210
+ ### Time series
224
211
 
225
- ### How to view the list of available colors?
212
+ * Not yet supported.
226
213
 
227
- ```sh
228
- uplot colors
229
- ```
214
+ ## Tools that are useful to use with YouPlot
215
+
216
+ * [csvtk](https://github.com/shenwei356/csvtk)
217
+ * [GNU datamash](https://www.gnu.org/software/datamash/)
218
+ * [awk](https://www.gnu.org/software/gawk/)
219
+ * [xsv](https://github.com/BurntSushi/xsv)
230
220
 
231
221
  ## Contributing
232
222
 
@@ -248,6 +238,7 @@ git clone https://github.com/your_name/YouPlot
248
238
  bundle install # Install the gem dependencies
249
239
  bundle exec rake test # Run the test
250
240
  bundle exec rake install # Installation from source code
241
+ bundle exec exe/uplot # Run youplot (Try out the edited code)
251
242
  ```
252
243
 
253
244
  ### Acknowledgements
@@ -6,6 +6,27 @@
6
6
  require_relative 'processing'
7
7
  require 'unicode_plot'
8
8
 
9
+ # If the line color is specified as a number, the program will display an error
10
+ # message to the user and exit. Remove this patch when UnicodePlot is improved.
11
+
12
+ module UnicodePlot
13
+ class << self
14
+ alias lineplot_original lineplot
15
+ def lineplot(*args, **kw)
16
+ if kw[:color].is_a? Numeric
17
+ warn <<~EOS
18
+ YouPlot: Line colors cannot be specified by numerical values.
19
+
20
+ For more information, please see the following issue.
21
+ https://github.com/red-data-tools/unicode_plot.rb/issues/34
22
+ EOS
23
+ YouPlot.run_as_executable ? exit(1) : raise(Error)
24
+ end
25
+ lineplot_original(*args, **kw)
26
+ end
27
+ end
28
+ end
29
+
9
30
  module YouPlot
10
31
  # plotting functions.
11
32
  module Backends
@@ -106,11 +127,10 @@ module YouPlot
106
127
 
107
128
  def plot_xyxy(data, method1, params)
108
129
  headers = data.headers
109
- series = data.series
130
+ series2 = data.series
131
+ .map { |s| s.map(&:to_f) }
132
+ .each_slice(2).to_a
110
133
  method2 = get_method2(method1)
111
- series.map! { |s| s.map(&:to_f) }
112
- series2 = series.each_slice(2).to_a
113
- series = nil
114
134
  params.name ||= headers[0] if headers
115
135
  params.xlim ||= series2.map(&:first).flatten.minmax # why need?
116
136
  params.ylim ||= series2.map(&:last).flatten.minmax # why need?
@@ -182,7 +202,7 @@ module YouPlot
182
202
  series = data.series
183
203
  if series.size == 1
184
204
  warn <<~EOS
185
- youplot: There is only one series of input data. Please check the delimiter.
205
+ YouPlot: There is only one series of input data. Please check the delimiter.
186
206
 
187
207
  Headers: \e[35m#{data.headers.inspect}\e[0m
188
208
  The first item is: \e[35m\"#{series[0][0]}\"\e[0m
@@ -169,7 +169,7 @@ module YouPlot
169
169
  def output_data(input)
170
170
  # Pass the input to subsequent pipelines
171
171
  case options[:pass]
172
- when IO
172
+ when IO, StringIO
173
173
  options[:pass].print(input)
174
174
  else
175
175
  if options[:pass]
@@ -58,10 +58,10 @@ module YouPlot
58
58
  parser.on('-t', '--title STR', String, 'print string on the top of plot') do |v|
59
59
  params.title = v
60
60
  end
61
- parser.on('-x', '--xlabel STR', String, 'print string on the bottom of the plot') do |v|
61
+ parser.on('--xlabel STR', String, 'print string on the bottom of the plot') do |v|
62
62
  params.xlabel = v
63
63
  end
64
- parser.on('-y', '--ylabel STR', String, 'print string on the far left of the plot') do |v|
64
+ parser.on('--ylabel STR', String, 'print string on the far left of the plot') do |v|
65
65
  params.ylabel = v
66
66
  end
67
67
  parser.on('-w', '--width INT', Numeric, 'number of characters per row') do |v|
@@ -95,7 +95,7 @@ module YouPlot
95
95
  parser.on('-M', '--monochrome', TrueClass, 'no colouring even if writing to a tty') do |_v|
96
96
  UnicodePlot::IOContext.define_method(:color?) { false } # FIXME
97
97
  end
98
- parser.on('--encoding STR', String, 'Specify the input encoding') do |v|
98
+ parser.on('--encoding STR', String, 'specify the input encoding') do |v|
99
99
  options[:encoding] = v
100
100
  end
101
101
  # Optparse adds the help option, but it doesn't show up in usage.
@@ -130,10 +130,9 @@ module YouPlot
130
130
  scatter s draw a scatter plot
131
131
  density d draw a density plot
132
132
  boxplot box draw a horizontal boxplot
133
- colors color show the list of available colors
134
-
135
133
  count c draw a baplot based on the number of
136
134
  occurrences (slow)
135
+ colors color show the list of available colors
137
136
 
138
137
  General options:
139
138
  --help print command specific help menu
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module YouPlot
4
- VERSION = '0.4.2'
4
+ VERSION = '0.4.3'
5
5
  end
data/lib/youplot.rb CHANGED
@@ -6,6 +6,12 @@ require_relative 'youplot/parameters'
6
6
  require_relative 'youplot/command'
7
7
 
8
8
  module YouPlot
9
+ # @run_as_executable = true / false
10
+ # YouPlot behaves slightly differently when run as a command line tool
11
+ # and when run as a script (e.g. for testing). In the event of an error,
12
+ # when run as a command line tool, YouPlot will display a short error message
13
+ # and exit abnormally. When run as a script, it will just raise an error.
14
+ @run_as_executable = false
9
15
  class << self
10
16
  attr_accessor :run_as_executable
11
17
 
@@ -13,5 +19,4 @@ module YouPlot
13
19
  @run_as_executable
14
20
  end
15
21
  end
16
- @run_as_executable = false
17
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: youplot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-10 00:00:00.000000000 Z
11
+ date: 2021-11-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: unicode_plot
@@ -16,84 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.0.5
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
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
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rubocop
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: simplecov
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: test-unit
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
26
+ version: 0.0.5
97
27
  description: A command line tool for Unicode Plotting
98
28
  email:
99
29
  - 2xijok@gmail.com
@@ -135,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
65
  - !ruby/object:Gem::Version
136
66
  version: '0'
137
67
  requirements: []
138
- rubygems_version: 3.2.15
68
+ rubygems_version: 3.2.26
139
69
  signing_key:
140
70
  specification_version: 4
141
71
  summary: A command line tool for Unicode Plotting