youplot 0.3.2 → 0.3.3
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 +4 -4
- data/README.md +57 -18
- data/lib/youplot.rb +1 -1
- data/lib/youplot/command.rb +56 -2
- data/lib/youplot/command/{cmd_options.rb → options.rb} +2 -1
- data/lib/youplot/command/parser.rb +3 -3
- data/lib/youplot/{dsv_reader.rb → dsv.rb} +15 -9
- data/lib/youplot/version.rb +1 -1
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f74b6c3834757ab941924f8455f0b933af654796740e80b85da400e764e14ae
|
4
|
+
data.tar.gz: 6c77e305eb5e7361be28beca3cce569458832099f47a38efa61dbfd143e6a04b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31f0a7ef9942ab7d6017ce60669ff1ca3f4ddc5b9a61ca0dd83e5c35093d8aaed725ef945bea0c9f2390fe97b2519319fc32894247d6caa136734b192e6a2287
|
7
|
+
data.tar.gz: 854f725384dfb6eb27c86ced3bb53321a850a015c343fdaf7e1639de96b01e8199557fd7beedf765126f74475c2506c938d2f26aa753c1f3abd5aca148dc48c7
|
data/README.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
<p align="center">
|
2
|
+
<img src="https://user-images.githubusercontent.com/5798442/103439598-9e952a00-4c81-11eb-881f-67c593bb7861.png" width="75%" height="75%" />
|
3
|
+
</p>
|
2
4
|
|
3
5
|

|
4
6
|
[](https://badge.fury.io/rb/youplot)
|
@@ -18,7 +20,8 @@ gem install youplot
|
|
18
20
|
|
19
21
|
## Quick Start
|
20
22
|
|
21
|
-
`cat data.tsv | uplot <command> [options]`
|
23
|
+
* `cat data.tsv | uplot <command> [options]` or
|
24
|
+
* `uplot <command> [options] <data.tsv>`
|
22
25
|
|
23
26
|
### barplot
|
24
27
|
|
@@ -29,7 +32,9 @@ curl -sL https://git.io/ISLANDScsv \
|
|
29
32
|
| uplot bar -d, -t "Areas of the World's Major Landmasses"
|
30
33
|
```
|
31
34
|
|
32
|
-
|
35
|
+
<p align="center">
|
36
|
+
<img alt="barplot" src="https://user-images.githubusercontent.com/5798442/101999903-d36a2d00-3d24-11eb-9361-b89116f44122.png">
|
37
|
+
</p>
|
33
38
|
|
34
39
|
### histogram
|
35
40
|
|
@@ -40,7 +45,10 @@ echo -e "from numpy import random;" \
|
|
40
45
|
| python \
|
41
46
|
| uplot hist --nbins 20
|
42
47
|
```
|
43
|
-
|
48
|
+
|
49
|
+
<p align="center">
|
50
|
+
<img alt="histogram" src="https://user-images.githubusercontent.com/5798442/101999820-21cafc00-3d24-11eb-86db-e410d19b07df.png">
|
51
|
+
</p>
|
44
52
|
|
45
53
|
### lineplot
|
46
54
|
|
@@ -50,7 +58,9 @@ curl -sL https://git.io/AirPassengers \
|
|
50
58
|
| uplot line -d, -w 50 -h 15 -t AirPassengers --xlim 1950,1960 --ylim 0,600
|
51
59
|
```
|
52
60
|
|
53
|
-
|
61
|
+
<p align="center">
|
62
|
+
<img alt="lineplot" src="https://user-images.githubusercontent.com/5798442/101999825-24c5ec80-3d24-11eb-99f4-c642e8d221bc.png">
|
63
|
+
</p>
|
54
64
|
|
55
65
|
### scatter
|
56
66
|
|
@@ -60,7 +70,9 @@ curl -sL https://git.io/IRIStsv \
|
|
60
70
|
| uplot scatter -H -t IRIS
|
61
71
|
```
|
62
72
|
|
63
|
-
|
73
|
+
<p align="center">
|
74
|
+
<img alt="scatter" src="https://user-images.githubusercontent.com/5798442/101999827-27284680-3d24-11eb-9903-551857eaa69c.png">
|
75
|
+
</p>
|
64
76
|
|
65
77
|
### density
|
66
78
|
|
@@ -70,7 +82,9 @@ curl -sL https://git.io/IRIStsv \
|
|
70
82
|
| uplot density -H -t IRIS
|
71
83
|
```
|
72
84
|
|
73
|
-
|
85
|
+
<p align="center">
|
86
|
+
<img alt="density" src="https://user-images.githubusercontent.com/5798442/101999828-2abbcd80-3d24-11eb-902c-2f44266fa6ae.png">
|
87
|
+
</p>
|
74
88
|
|
75
89
|
### boxplot
|
76
90
|
|
@@ -80,11 +94,13 @@ curl -sL https://git.io/IRIStsv \
|
|
80
94
|
| uplot boxplot -H -t IRIS
|
81
95
|
```
|
82
96
|
|
83
|
-
|
97
|
+
<p align="center">
|
98
|
+
<img alt="boxplot" src="https://user-images.githubusercontent.com/5798442/101999830-2e4f5480-3d24-11eb-8891-728c18bf5b35.png">
|
99
|
+
</p>
|
84
100
|
|
85
101
|
### count
|
86
102
|
|
87
|
-
In this example, YouPlot counts the number of chromosomes where the gene is located from the human gene annotation file and
|
103
|
+
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.
|
88
104
|
|
89
105
|
* https://www.gencodegenes.org/human/
|
90
106
|
|
@@ -94,10 +110,12 @@ cat gencode.v35.annotation.gff3 \
|
|
94
110
|
uplot count -t "The number of human gene annotations per chromosome" -c blue
|
95
111
|
```
|
96
112
|
|
97
|
-
|
113
|
+
<p align="center">
|
114
|
+
<img alt="count" src="https://user-images.githubusercontent.com/5798442/101999832-30b1ae80-3d24-11eb-96fe-e5000bed1f5c.png">
|
115
|
+
</p>
|
98
116
|
|
99
117
|
Note: `count` is not very fast because it runs in a Ruby script.
|
100
|
-
This is fine
|
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.
|
101
119
|
|
102
120
|
```sh
|
103
121
|
cat gencode.v35.annotation.gff3 | grep -v '#' | grep 'gene' | cut -f1 \
|
@@ -109,8 +127,8 @@ cat gencode.v35.annotation.gff3 | grep -v '#' | grep 'gene' | cut -f1 \
|
|
109
127
|
|
110
128
|
### Why YouPlot?
|
111
129
|
|
112
|
-
Wouldn't it be a
|
113
|
-
YouPlot is a command line tool for this purpose. With YouPlot, you can continue working without leaving your terminal and shell.
|
130
|
+
Wouldn't it be a pain to have to run R, Python, Julia, gnuplot or whatever REPL just to check your data?
|
131
|
+
YouPlot is a command line tool for this purpose. With YouPlot, you can continue working without leaving your terminal and shell.
|
114
132
|
|
115
133
|
### how to use YouPlot?
|
116
134
|
|
@@ -124,17 +142,17 @@ YouPlot is a command line tool for this purpose. With YouPlot, you can continue
|
|
124
142
|
|
125
143
|
### Where to output the plot?
|
126
144
|
|
127
|
-
By default, the plot is output to *standard error output*.
|
145
|
+
By default, the plot is output to *standard error output*.
|
128
146
|
The output file or stream for the plot can be specified with the `-o` option.
|
129
147
|
|
130
148
|
### Where to output the input data?
|
131
149
|
|
132
|
-
By default, the input data is not
|
150
|
+
By default, the input data is not shown anywhere.
|
133
151
|
The `-O` option, with no arguments, outputs the input data directly to the standard output. This is useful when passing data to a subsequent pipeline.
|
134
152
|
|
135
153
|
### What types of plots are available?
|
136
154
|
|
137
|
-
The following sub-commands are available
|
155
|
+
The following sub-commands are available.
|
138
156
|
|
139
157
|
| command | short | how it works |
|
140
158
|
|-----------|-------|----------------------------------------|
|
@@ -150,9 +168,29 @@ See Quick Start for `count`.
|
|
150
168
|
|
151
169
|
| command | short | how it works |
|
152
170
|
|-----------|-------|----------------------------------------------------------|
|
153
|
-
| count | c | draw a
|
171
|
+
| count | c | draw a barplot based on the number of occurrences (slow) |
|
172
|
+
|
173
|
+
### What if the header line is included?
|
174
|
+
|
175
|
+
If your input data contains a header line, you need to specify the `-H` option.
|
176
|
+
|
177
|
+
### How to specify the delimiter?
|
178
|
+
|
179
|
+
Use the `-d` option. To specify a blank space, you can use `uplot bar -d ' ' data.txt`. You do not need to use `-d` option for tab-delimited text since the default value is tab.
|
180
|
+
|
181
|
+
### Is there a way to specify a column as the x-axis or y-axis?
|
182
|
+
|
183
|
+
Not yet. In principle, YouPlot treats the first column as the X axis and the second column as the Y axis. When working with multiple series, the first row is the X axis, the second row is series 1, the third row is series 2, and so on. 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. The `--fmt xyy`, `--fmt xyxy` and `--fmt yx` options give you a few more choices. See `youplot <command> --help` for more details. YouPlot has limited functionalities, but you can use shell scripts such as `awk '{print $2, $1}'` to swap lines.
|
184
|
+
|
185
|
+
### How to plot real-time data?
|
186
|
+
|
187
|
+
Experimental progressive mode is currently under development.
|
188
|
+
|
189
|
+
```sh
|
190
|
+
ruby -e 'loop{puts rand(100)}' | uplot line --progress
|
191
|
+
```
|
154
192
|
|
155
|
-
### How to view detailed command line options
|
193
|
+
### How to view detailed command line options?
|
156
194
|
|
157
195
|
Use `--help` to print command-specific options.
|
158
196
|
|
@@ -181,6 +219,7 @@ uplot colors
|
|
181
219
|
* [Report bugs](https://github.com/kojix2/youplot/issues)
|
182
220
|
* Fix bugs and [submit pull requests](https://github.com/kojix2/youplot/pulls)
|
183
221
|
* Write, clarify, or fix documentation
|
222
|
+
* English corrections by native speakers are welcome.
|
184
223
|
* Suggest or add new features
|
185
224
|
|
186
225
|
|
data/lib/youplot.rb
CHANGED
data/lib/youplot/command.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '
|
3
|
+
require_relative 'dsv'
|
4
4
|
require_relative 'command/parser'
|
5
5
|
|
6
6
|
# FIXME
|
@@ -31,6 +31,14 @@ module YouPlot
|
|
31
31
|
if %i[colors color colours colour].include? @command
|
32
32
|
plot = create_plot
|
33
33
|
output_plot(plot)
|
34
|
+
elsif options[:progressive]
|
35
|
+
stop = false
|
36
|
+
Signal.trap(:INT) { stop = true }
|
37
|
+
while (input = Kernel.gets)
|
38
|
+
main_progressive(input)
|
39
|
+
break if stop
|
40
|
+
end
|
41
|
+
options[:output].print "\e[0J"
|
34
42
|
else
|
35
43
|
# Sometimes the input file does not end with a newline code.
|
36
44
|
while (input = Kernel.gets(nil))
|
@@ -52,9 +60,31 @@ module YouPlot
|
|
52
60
|
output_plot(plot)
|
53
61
|
end
|
54
62
|
|
63
|
+
def main_progressive(input)
|
64
|
+
output_data(input)
|
65
|
+
|
66
|
+
# FIXME
|
67
|
+
# Worked around the problem of not being able to draw
|
68
|
+
# plots when there is only one header line.
|
69
|
+
if @raw_data.nil?
|
70
|
+
@raw_data = String.new
|
71
|
+
if options[:headers]
|
72
|
+
@raw_data << input
|
73
|
+
return
|
74
|
+
end
|
75
|
+
end
|
76
|
+
@raw_data << input
|
77
|
+
|
78
|
+
# FIXME
|
79
|
+
@data = read_dsv(@raw_data)
|
80
|
+
|
81
|
+
plot = create_plot
|
82
|
+
output_plot_progressive(plot)
|
83
|
+
end
|
84
|
+
|
55
85
|
def read_dsv(input)
|
56
86
|
input = input.dup.force_encoding(options[:encoding]).encode('utf-8') if options[:encoding]
|
57
|
-
|
87
|
+
DSV.parse(input, options[:delimiter], options[:headers], options[:transpose])
|
58
88
|
end
|
59
89
|
|
60
90
|
def create_plot
|
@@ -106,5 +136,29 @@ module YouPlot
|
|
106
136
|
end
|
107
137
|
end
|
108
138
|
end
|
139
|
+
|
140
|
+
def output_plot_progressive(plot)
|
141
|
+
case options[:output]
|
142
|
+
when IO
|
143
|
+
# RefactorMe
|
144
|
+
out = StringIO.new(String.new)
|
145
|
+
def out.tty?
|
146
|
+
true
|
147
|
+
end
|
148
|
+
plot.render(out)
|
149
|
+
lines = out.string.lines
|
150
|
+
lines.each do |line|
|
151
|
+
options[:output].print line.chomp
|
152
|
+
options[:output].print "\e[0K"
|
153
|
+
options[:output].puts
|
154
|
+
end
|
155
|
+
options[:output].print "\e[0J"
|
156
|
+
options[:output].flush
|
157
|
+
n = out.string.lines.size
|
158
|
+
options[:output].print "\e[#{n}F"
|
159
|
+
else
|
160
|
+
raise 'In progressive mode, output to a file is not possible.'
|
161
|
+
end
|
162
|
+
end
|
109
163
|
end
|
110
164
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'optparse'
|
4
|
-
require_relative '
|
4
|
+
require_relative 'options'
|
5
5
|
require_relative 'plot_params'
|
6
6
|
|
7
7
|
module YouPlot
|
@@ -12,7 +12,7 @@ module YouPlot
|
|
12
12
|
def initialize
|
13
13
|
@command = nil
|
14
14
|
|
15
|
-
@options =
|
15
|
+
@options = Options.new(
|
16
16
|
delimiter: "\t",
|
17
17
|
transpose: false,
|
18
18
|
headers: nil,
|
@@ -82,7 +82,7 @@ module YouPlot
|
|
82
82
|
opt.on('--[no-]labels', TrueClass, 'hide the labels') do |v|
|
83
83
|
params.labels = v
|
84
84
|
end
|
85
|
-
opt.on('--progress', TrueClass, 'progressive') do |v|
|
85
|
+
opt.on('--progress', TrueClass, 'progressive mode [experimental]') do |v|
|
86
86
|
@options[:progressive] = v
|
87
87
|
end
|
88
88
|
opt.on('--encoding VAL', String, 'Specify the input encoding') do |v|
|
@@ -4,10 +4,10 @@ require 'csv'
|
|
4
4
|
|
5
5
|
module YouPlot
|
6
6
|
# Read and interpret Delimiter-separated values format file or stream.
|
7
|
-
module
|
7
|
+
module DSV
|
8
8
|
module_function
|
9
9
|
|
10
|
-
def
|
10
|
+
def parse(input, delimiter, headers, transpose)
|
11
11
|
arr = parse_as_csv(input, delimiter)
|
12
12
|
headers = get_headers(arr, headers, transpose)
|
13
13
|
series = get_series(arr, headers, transpose)
|
@@ -57,16 +57,22 @@ module YouPlot
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def get_series(arr, headers, transpose)
|
60
|
-
if
|
61
|
-
if
|
62
|
-
|
60
|
+
if headers
|
61
|
+
if arr.size > 1
|
62
|
+
if transpose
|
63
|
+
arr.map { |row| row[1..-1] }
|
64
|
+
else
|
65
|
+
transpose2(arr[1..-1])
|
66
|
+
end
|
63
67
|
else
|
64
|
-
arr
|
68
|
+
Array.new(arr[0].size, [])
|
65
69
|
end
|
66
|
-
elsif headers
|
67
|
-
transpose2(arr[1..-1])
|
68
70
|
else
|
69
|
-
|
71
|
+
if transpose
|
72
|
+
arr
|
73
|
+
else
|
74
|
+
transpose2(arr)
|
75
|
+
end
|
70
76
|
end
|
71
77
|
end
|
72
78
|
end
|
data/lib/youplot/version.rb
CHANGED
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.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kojix2
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unicode_plot
|
@@ -94,8 +94,7 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description:
|
98
|
-
in the \npipeline. \n"
|
97
|
+
description: A command line tool for Unicode Plotting
|
99
98
|
email:
|
100
99
|
- 2xijok@gmail.com
|
101
100
|
executables:
|
@@ -112,10 +111,10 @@ files:
|
|
112
111
|
- lib/youplot/backends/processing.rb
|
113
112
|
- lib/youplot/backends/unicode_plot_backend.rb
|
114
113
|
- lib/youplot/command.rb
|
115
|
-
- lib/youplot/command/
|
114
|
+
- lib/youplot/command/options.rb
|
116
115
|
- lib/youplot/command/parser.rb
|
117
116
|
- lib/youplot/command/plot_params.rb
|
118
|
-
- lib/youplot/
|
117
|
+
- lib/youplot/dsv.rb
|
119
118
|
- lib/youplot/version.rb
|
120
119
|
homepage: https://github.com/kojix2/youplot
|
121
120
|
licenses:
|
@@ -136,8 +135,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
135
|
- !ruby/object:Gem::Version
|
137
136
|
version: '0'
|
138
137
|
requirements: []
|
139
|
-
rubygems_version: 3.
|
138
|
+
rubygems_version: 3.2.3
|
140
139
|
signing_key:
|
141
140
|
specification_version: 4
|
142
|
-
summary:
|
141
|
+
summary: A command line tool for Unicode Plotting
|
143
142
|
test_files: []
|