youplot 0.4.4 → 0.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a924bdaf315e9b7b8afa65d0f02cdbb22c213fbf80908e2ae30d12d1bc3d9338
4
- data.tar.gz: ea42f957954e37d8d1f4eaf3c789e52188f96aff1afbf99dae6179be14ab06d5
3
+ metadata.gz: d73be033d215d1df04dfef6be988a55e669699a4a8e6c408ac38bb4ff0c680a6
4
+ data.tar.gz: 5f84877f99e1d5f52290caf33ed16e2ae67ff2465ac9acf50ae33630131f225e
5
5
  SHA512:
6
- metadata.gz: 602975a225b979ad6ca2a43ef038f18a23b48f034ddb2a06ffa3f4ca0d61cb805e6ef314afd00a897f8bc869fcce8b27fee895ac6e0f3f82bc7cbe8531369632
7
- data.tar.gz: 0d9f77815d3c2e7f338dfe42f0b501a51dd9dd3de06cc367a7ee3de52e049a6a7e55ee3afc4cc2a525a724b07412f5807feba3c9aea33966d407d38d96fb8601
6
+ metadata.gz: 2a593cd01599a76949ea17ca00f5b24b6a6f92c971b68281775c8a0ddb7d25d9c6269c64ee2a79ea482abadeb9c44f2b5d91cfe0298b81a6da3139405d8bf1c8
7
+ data.tar.gz: 4912f82e6e82c9533b13f8d16b0120a7e40adb8bc55d4026d7dc08bbc2efb4c186e9b7653b58baa7990661ffd299331e6a937032cee0c3623f6f0b2eaf420fc2
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  <div align="center">
2
2
  <img src="logo.svg">
3
3
  <hr>
4
- <img alt="Build Status" src="https://github.com/red-data-tools/YouPlot/workflows/test/badge.svg">
4
+ <a href="https://github.com/red-data-tools/YouPlot/actions/workflows/ci.yml"><img alt="Build Status" src="https://github.com/red-data-tools/YouPlot/workflows/test/badge.svg"></a>
5
5
  <a href="https://rubygems.org/gems/youplot/"><img alt="Gem Version" src="https://badge.fury.io/rb/youplot.svg"></a>
6
6
  <a href="https://zenodo.org/badge/latestdoi/283230219"><img alt="DOI" src="https://zenodo.org/badge/283230219.svg"></a>
7
7
  <a href="https://rubydoc.info/gems/youplot/"><img alt="Docs Stable" src="https://img.shields.io/badge/docs-stable-blue.svg"></a>
@@ -14,10 +14,28 @@
14
14
 
15
15
  ## Installation
16
16
 
17
+ ```
18
+ brew install youplot
19
+ ```
20
+
17
21
  ```
18
22
  gem install youplot
19
23
  ```
20
24
 
25
+ ```
26
+ nix shell nixpkgs#youplot
27
+ ```
28
+
29
+ ```
30
+ guix install youplot
31
+ ```
32
+
33
+ ```
34
+ conda install -c conda-forge ruby
35
+ conda install -c conda-forge compilers
36
+ gem install youplot
37
+ ```
38
+
21
39
  ## Quick Start
22
40
 
23
41
  <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>
@@ -37,13 +55,20 @@ curl -sL https://git.io/ISLANDScsv \
37
55
  <img alt="barplot" src="https://user-images.githubusercontent.com/5798442/101999903-d36a2d00-3d24-11eb-9361-b89116f44122.png">
38
56
  </p>
39
57
 
58
+
59
+
60
+ ```sh
61
+ # For offline user: Sorts files in a directory by size and shows a bar graph.
62
+ ls -l | awk '{print $9, $5}' | sort -nk 2 | uplot bar -d ' '
63
+ ```
64
+
40
65
  ### histogram
41
66
 
42
67
  ```sh
43
68
  echo -e "from numpy import random;" \
44
69
  "n = random.randn(10000);" \
45
70
  "print('\\\n'.join(str(i) for i in n))" \
46
- | python \
71
+ | python3 \
47
72
  | uplot hist --nbins 20
48
73
  ```
49
74
 
@@ -63,6 +88,14 @@ curl -sL https://git.io/AirPassengers \
63
88
  <img alt="lineplot" src="https://user-images.githubusercontent.com/5798442/101999825-24c5ec80-3d24-11eb-99f4-c642e8d221bc.png">
64
89
  </p>
65
90
 
91
+ ```sh
92
+ # For offline users: Calculates sin values (0-2*pi) and plots a sine wave.
93
+ python3 -c '
94
+ from math import sin, pi
95
+ data = "\n".join(f"{i*pi/50}\t{sin(i*pi/50)}" for i in range(101))
96
+ print(data)' | uplot line
97
+ ```
98
+
66
99
  ### scatter
67
100
 
68
101
  ```sh
@@ -75,6 +108,12 @@ curl -sL https://git.io/IRIStsv \
75
108
  <img alt="scatter" src="https://user-images.githubusercontent.com/5798442/101999827-27284680-3d24-11eb-9903-551857eaa69c.png">
76
109
  </p>
77
110
 
111
+
112
+ ```sh
113
+ # For offline users
114
+ cat test/fixtures/iris.csv | cut -f1-4 -d, | uplot scatter -H -d, -t IRIS
115
+ ```
116
+
78
117
  ### density
79
118
 
80
119
  ```sh
@@ -87,6 +126,11 @@ curl -sL https://git.io/IRIStsv \
87
126
  <img alt="density" src="https://user-images.githubusercontent.com/5798442/101999828-2abbcd80-3d24-11eb-902c-2f44266fa6ae.png">
88
127
  </p>
89
128
 
129
+ ```sh
130
+ # For offline users
131
+ cat test/fixtures/iris.csv | cut -f1-4 -d, | uplot density -H -d, -t IRIS
132
+ ```
133
+
90
134
  ### boxplot
91
135
 
92
136
  ```sh
@@ -99,8 +143,21 @@ curl -sL https://git.io/IRIStsv \
99
143
  <img alt="boxplot" src="https://user-images.githubusercontent.com/5798442/101999830-2e4f5480-3d24-11eb-8891-728c18bf5b35.png">
100
144
  </p>
101
145
 
146
+ ```sh
147
+ # For offline users
148
+ cat test/fixtures/iris.csv | cut -f1-4 -d, | uplot boxplot -H -d, -t IRIS
149
+ ```
150
+
102
151
  ### count
103
152
 
153
+ Count processes by user ID.
154
+
155
+ ```sh
156
+ ps aux | awk '{print $1}' | uplot count
157
+ ```
158
+
159
+ Count the number of chromosomes where genes are located.
160
+
104
161
  ```sh
105
162
  cat gencode.v35.annotation.gff3 \
106
163
  | grep -v '#' | grep 'gene' | cut -f1 \
@@ -111,7 +168,6 @@ cat gencode.v35.annotation.gff3 \
111
168
  <img alt="count" src="https://user-images.githubusercontent.com/5798442/101999832-30b1ae80-3d24-11eb-96fe-e5000bed1f5c.png">
112
169
  </p>
113
170
 
114
- In this example, YouPlot counts the number of chromosomes where genes are located.
115
171
  * [GENCODE - Human Release](https://www.gencodegenes.org/human/)
116
172
 
117
173
  Note: `count` is not very fast because it runs in a Ruby script.
@@ -157,7 +213,7 @@ The following sub-commands are available.
157
213
 
158
214
  * `-o`
159
215
  * 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 | `.
216
+ * If you want to output to standard output, Use hyphen ` -o -` or no argument `uplot s -o | `.
161
217
 
162
218
  ### Output the input data
163
219
 
@@ -211,6 +267,14 @@ The following sub-commands are available.
211
267
 
212
268
  * Not yet supported.
213
269
 
270
+ ### YouPlot Configuration (youplotrc)
271
+
272
+ You can specify default options in a configuration file in YAML format. For more information, enter the following command.
273
+
274
+ ```
275
+ uplot --config
276
+ ```
277
+
214
278
  ## Tools that are useful to use with YouPlot
215
279
 
216
280
  * [csvtk](https://github.com/shenwei356/csvtk)
@@ -40,24 +40,6 @@ module YouPlot
40
40
  return
41
41
  end
42
42
 
43
- # config command
44
- if @command == :config
45
- if ENV['MYYOUPLOTRC']
46
- puts "config file : #{ENV['MYYOUPLOTRC']}"
47
- puts parser.config.inspect
48
- else
49
- puts <<~EOS
50
- You don't have a config file. The default config file paths are:
51
- ./.youplot.yml, ./.youplotrc, ~/.youplot.yml, ~/.youplotrc
52
- You can specify a config file with the environment variable MYYOUPLOTRC.
53
- File format is YAML. For example:
54
- width : 40
55
- height : 20
56
- EOS
57
- end
58
- return
59
- end
60
-
61
43
  # progressive mode
62
44
  if options[:progressive]
63
45
  stop = false
@@ -178,9 +160,9 @@ module YouPlot
178
160
  @backend.barplot(data, params, count: true, reverse: options[:reverse])
179
161
  when :hist, :histogram
180
162
  @backend.histogram(data, params)
181
- when :line, :lineplot
163
+ when :line, :lineplot, :l
182
164
  @backend.line(data, params, options[:fmt])
183
- when :lines, :lineplots
165
+ when :lines, :lineplots, :ls
184
166
  @backend.lines(data, params, options[:fmt])
185
167
  when :scatter, :s
186
168
  @backend.scatter(data, params, options[:fmt])
@@ -29,53 +29,59 @@ module YouPlot
29
29
  )
30
30
 
31
31
  @params = Parameters.new
32
+ end
32
33
 
33
- if @config_file = find_config_file
34
- ENV['MYYOUPLOTRC'] = @config_file
35
- @config = read_config_file(config_file)
36
- configure(config)
37
- end
34
+ def apply_config_file
35
+ return if !config_file && find_config_file.nil?
36
+
37
+ read_config_file
38
+ configure
38
39
  end
39
40
 
40
- def candidate_paths
41
+ def config_file_candidate_paths
42
+ # keep the order of the paths
41
43
  paths = []
42
44
  paths << ENV['MYYOUPLOTRC'] if ENV['MYYOUPLOTRC']
43
45
  paths << '.youplot.yml'
44
46
  paths << '.youplotrc'
45
- paths << File.join(ENV['HOME'], '.youplotrc') if ENV['HOME']
46
- paths << File.join(ENV['HOME'], '.youplot.yml') if ENV['HOME']
47
+ if ENV['HOME']
48
+ paths << File.join(ENV['HOME'], '.youplotrc')
49
+ paths << File.join(ENV['HOME'], '.youplot.yml')
50
+ paths << File.join(ENV['HOME'], '.config', 'youplot', 'youplotrc')
51
+ paths << File.join(ENV['HOME'], '.config', 'youplot', 'youplot.yml')
52
+ end
47
53
  paths
48
54
  end
49
55
 
50
56
  def find_config_file
51
- config_file_path = nil
52
- candidate_paths.each do |file|
57
+ config_file_candidate_paths.each do |file|
53
58
  path = File.expand_path(file)
54
- if File.exist?(path)
55
- config_file_path = path
56
- break
57
- end
59
+ next unless File.exist?(path)
60
+
61
+ @config_file = path
62
+ ENV['MYYOUPLOTRC'] = path
63
+ return @config_file
58
64
  end
59
- config_file_path
65
+ nil
60
66
  end
61
67
 
62
- def read_config_file(path)
68
+ def read_config_file
63
69
  require 'yaml'
64
- YAML.load_file(path)
70
+ @config = YAML.load_file(config_file)
65
71
  end
66
72
 
67
- def configure(config)
73
+ def configure
68
74
  option_members = @options.members
69
75
  param_members = @params.members
70
76
  # It would be more useful to be able to configure by plot type
71
77
  config.each do |k, v|
72
78
  k = k.to_sym
73
79
  if option_members.include?(k)
74
- @options[k] = v
80
+ @options[k] ||= v
75
81
  elsif param_members.include?(k)
76
- @params[k] = v
82
+ @params[k] ||= v
77
83
  else
78
- raise Error, "Unknown option/param: #{k}"
84
+ raise Error, "Unknown option/param in config file: #{k}"
79
85
  end
80
86
  end
81
87
  end
@@ -154,6 +160,9 @@ module YouPlot
154
160
  puts parser.help
155
161
  exit if YouPlot.run_as_executable?
156
162
  end
163
+ parser.on('--config FILE', 'specify a config file') do |v|
164
+ @config_file = v
165
+ end
157
166
  parser.on('--debug', TrueClass, 'print preprocessed data') do |v|
158
167
  options[:debug] = v
159
168
  end
@@ -180,11 +189,12 @@ module YouPlot
180
189
  scatter s draw a scatter plot
181
190
  density d draw a density plot
182
191
  boxplot box draw a horizontal boxplot
183
- count c draw a baplot based on the number of
192
+ count c draw a barplot based on the number of
184
193
  occurrences (slow)
185
194
  colors color show the list of available colors
186
195
 
187
196
  General options:
197
+ --config print config file info
188
198
  --help print command specific help menu
189
199
  --version print the version of YouPlot
190
200
  MSG
@@ -192,10 +202,36 @@ module YouPlot
192
202
  # Help for the main parser is simple.
193
203
  # Simply show the banner above.
194
204
  main_parser.on('--help', 'print sub-command help menu') do
195
- puts main_parser.banner
196
- puts
197
- exit if YouPlot.run_as_executable?
205
+ show_main_help
198
206
  end
207
+
208
+ main_parser.on('--config', 'show config file info') do
209
+ show_config_info
210
+ end
211
+ end
212
+
213
+ def show_main_help(out = $stdout)
214
+ out.puts main_parser.banner
215
+ out.puts
216
+ exit if YouPlot.run_as_executable?
217
+ end
218
+
219
+ def show_config_info
220
+ if ENV['MYYOUPLOTRC']
221
+ puts "config file : #{ENV['MYYOUPLOTRC']}"
222
+ puts config.inspect
223
+ else
224
+ puts <<~EOS
225
+ Configuration file not found.
226
+ It should be a YAML file, like this example:
227
+ width : 40
228
+ height : 20
229
+ By default, YouPlot will look for the configuration file in these locations:
230
+ #{config_file_candidate_paths.map { |s| ' ' + s }.join("\n")}
231
+ If you have the file elsewhere, you can specify its location with the `MYYOUPLOTRC` environment variable.
232
+ EOS
233
+ end
234
+ exit if YouPlot.run_as_executable?
199
235
  end
200
236
 
201
237
  def sub_parser_add_symbol
@@ -265,10 +301,13 @@ module YouPlot
265
301
  case command
266
302
 
267
303
  # If you type only `uplot` in the terminal.
304
+ # Output help to standard error output.
268
305
  when nil
269
- warn main_parser.banner
270
- warn "\n"
271
- exit 1 if YouPlot.run_as_executable?
306
+ show_main_help($stderr)
307
+
308
+ # Output help to standard output.
309
+ when :help
310
+ show_main_help
272
311
 
273
312
  when :barplot, :bar
274
313
  sub_parser_add_symbol
@@ -291,14 +330,14 @@ module YouPlot
291
330
  params.nbins = v
292
331
  end
293
332
 
294
- when :lineplot, :line
333
+ when :lineplot, :line, :l
295
334
  sub_parser_add_canvas
296
335
  sub_parser_add_grid
297
336
  sub_parser_add_fmt_yx
298
337
  sub_parser_add_ylim
299
338
  sub_parser_add_xlim
300
339
 
301
- when :lineplots, :lines
340
+ when :lineplots, :lines, :ls
302
341
  sub_parser_add_canvas
303
342
  sub_parser_add_grid
304
343
  sub_parser_add_fmt_xyxy
@@ -327,16 +366,19 @@ module YouPlot
327
366
  options[:color_names] = v
328
367
  end
329
368
 
369
+ # Currently it simply displays the configuration file,
370
+ # but in the future this may be changed to open a text editor like Vim
371
+ # to edit the configuration file.
330
372
  when :config
373
+ show_config_info
331
374
 
332
375
  else
333
- error_message = "uplot: unrecognized command '#{command}'"
334
- if YouPlot.run_as_executable?
335
- warn error_message
336
- exit 1
337
- else
338
- raise Error, error_message
339
- end
376
+ error_message = "YouPlot: unrecognized command '#{command}'"
377
+ raise Error, error_message unless YouPlot.run_as_executable?
378
+
379
+ warn error_message
380
+ exit 1
381
+
340
382
  end
341
383
  end
342
384
 
@@ -344,7 +386,7 @@ module YouPlot
344
386
  begin
345
387
  create_main_parser.order!(argv)
346
388
  rescue OptionParser::ParseError => e
347
- warn "uplot: #{e.message}"
389
+ warn "YouPlot: #{e.message}"
348
390
  exit 1 if YouPlot.run_as_executable?
349
391
  end
350
392
 
@@ -353,7 +395,14 @@ module YouPlot
353
395
  begin
354
396
  create_sub_parser&.parse!(argv)
355
397
  rescue OptionParser::ParseError => e
356
- warn "uplot: #{e.message}"
398
+ warn "YouPlot: #{e.message}"
399
+ exit 1 if YouPlot.run_as_executable?
400
+ end
401
+
402
+ begin
403
+ apply_config_file
404
+ rescue StandardError => e
405
+ warn "YouPlot: #{e.message}"
357
406
  exit 1 if YouPlot.run_as_executable?
358
407
  end
359
408
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module YouPlot
4
- VERSION = '0.4.4'
4
+ VERSION = '0.4.6'
5
5
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: youplot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-02 00:00:00.000000000 Z
11
+ date: 2024-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: csv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: unicode_plot
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -50,7 +64,7 @@ homepage: https://github.com/red-data-tools/YouPlot
50
64
  licenses:
51
65
  - MIT
52
66
  metadata: {}
53
- post_install_message:
67
+ post_install_message:
54
68
  rdoc_options: []
55
69
  require_paths:
56
70
  - lib
@@ -58,15 +72,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - ">="
60
74
  - !ruby/object:Gem::Version
61
- version: 2.4.0
75
+ version: 2.5.0
62
76
  required_rubygems_version: !ruby/object:Gem::Requirement
63
77
  requirements:
64
78
  - - ">="
65
79
  - !ruby/object:Gem::Version
66
80
  version: '0'
67
81
  requirements: []
68
- rubygems_version: 3.3.7
69
- signing_key:
82
+ rubygems_version: 3.5.11
83
+ signing_key:
70
84
  specification_version: 4
71
85
  summary: A command line tool for Unicode Plotting
72
86
  test_files: []