macでインフォマティクス

macでインフォマティクス

HTS (NGS) 関連のインフォマティクス情報についてまとめています。

グラフィック出力が利用できない環境で頻度分布を素早く確認できる bashplotlib

 

bashplotlibは、端末で基本的なプロットを作成するためのpythonパッケージおよびコマンドラインツール。 GUIがない場合にデータを視覚化する簡単な方法を提供する。pythonでコーディングされており、pipを使って素早くインストールできる。

 

特徴(githubより)

  • quick plotting from the command line
  • customize the color, size, title, and shape of plots
  • pipe data into plots with stdin

 

 bashplotlibに関するツイート

 

インストール

ubuntu16.04のpython2.7.13環境でテストした。

本体 Github

pip install bashplotlib

#from source
git clone git@github.com:glamp/bashplotlib.git
cd bashplotlib
python setup.py install

hist --help

$ hist --help

Usage: hist is a command for making histograms. it accepts a series of values in one of the following formats:

        1) txt file w/ 1 column of numbers

        2) standard in piped from another command line cat or curl

 

    for some examples of how to use hist, you can type the command:

        hist --demo

    or visit https://github.com/glamp/bashplotlib/blob/master/examples/sample.sh

    

 

Options:

  -h, --help            show this help message and exit

  -f F, --file=F        a file containing a column of numbers

  -t T, --title=T       title for the chart

  -b B, --bins=B        number of bins in the histogram

  -w BINWIDTH, --binwidth=BINWIDTH

                        width of bins in the histogram

  -s H, --height=H      height of the histogram (in lines)

  -p P, --pch=P         shape of each bar

  -x, --xlab            label bins on x-axis

  -c COLOUR, --colour=COLOUR

                        colour of the plot (blue, yellow, pink, default, aqua,

                        grey, green, black, white, red)

  -d, --demo            run demos

  -n, --nosummary       hide summary

  -r, --regular         use regular y-scale (0 - maximum y value), instead of

                        truncated y-scale (minimum y-value - maximum y-value)

> scatter --help

$ scatter --help

Usage: scatterplot is a command for making xy plots. it accepts a series of x values and a series of y values in the

    following formats:

        1) a txt file or standard in value w/ 2 comma seperated columns of x,y values

        2) 2 txt files. 1 w/ designated x values and another with designated y values.

 

    scatter -x <xcoords> -y <ycoords>

    cat <file_with_x_and_y_coords> | scatter

    

 

Options:

  -h, --help            show this help message and exit

  -f F, --file=F        a csv w/ x and y coordinates

  -t T, --title=T       title for the chart

  -x X                  x coordinates

  -y Y                  y coordinates

  -s SIZE, --size=SIZE  y coordinates

  -p PCH, --pch=PCH     shape of point

  -c COLOUR, --colour=COLOUR

                        colour of the plot (blue, yellow, pink, default, aqua,

                        grey, green, black, white, red)

 

実行方法

hist

以下のような1行、数値ファイル(1行1列)のテキストから頻度分布を出力する。

cd bashplotlib/examples/

#中身を確認
head data/exp.txt

$ head data/exp.txt 

1.12578195876

0.16026238021

0.0392117875843

0.968428864579

0.334430039433

0.235098864615

1.09595064233

2.37425604196

1.18110389062

0.551066224631

hist実行

hist --file data/exp.txt

451|  o         

 427|  o         

 403|  o         

 380|  o         

 356|  o         

 332|  o         

 309|  o         

 285|  o         

 261|  oo        

 238|  oo        

 214|  oo        

 190|  oo        

 166|  oo        

 143|  oo        

 119|  ooo       

  95|  ooo       

  72|  oooo      

  48|  oooo      

  24|  ooooo     

   1| ooooooooooo

     -----------

 

---------------------------------

|            Summary            |

---------------------------------

|       observations: 1000      |

|      min value: 0.001718      |

|        mean : 0.988786        |

|      max value: 6.552654      |

---------------------------------

頻度が◯の数で示される。

 

 

テストラン

cd bashplotlib/examples/
./sample.sh

$ ./sample.sh 

downloading data

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100   424    0   424    0     0    813      0 --:--:-- --:--:-- --:--:--   813

100 3421k  100 3421k    0     0  1672k      0  0:00:02  0:00:02 --:--:-- 2346k

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100   392    0   392    0     0   1007      0 --:--:-- --:--:-- --:--:--  1007

100 14618  100 14618    0     0  13349      0  0:00:01  0:00:01 --:--:-- 28274

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100   400    0   400    0     0   1156      0 --:--:-- --:--:-- --:--:--  1156

100  220k  100  220k    0     0   168k      0  0:00:01  0:00:01 --:--:--  260k

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100   396    0   396    0     0   1171      0 --:--:-- --:--:-- --:--:--  1168

100 16723  100 16723    0     0  13662      0  0:00:01  0:00:01 --:--:-- 15.9M

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100   398    0   398    0     0   1133      0 --:--:-- --:--:-- --:--:--  1133

100    23  100    23    0     0     22      0  0:00:01  0:00:01 --:--:--     0

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current

                                 Dload  Upload   Total   Spent    Left  Speed

100   398    0   398    0     0   1213      0 --:--:-- --:--:-- --:--:--  1217

100    23  100    23    0     0     23      0  0:00:01 --:--:--  0:00:01     0

plotting coordinates

------------------------------------------

|       xxxxxx        |

|       x    x        |

|       x    x        |

|       x    xx       |

|       x     xxxxxxx |

|       x        xxxxx|

|       x             |

|       x             |

| xx x xx             |

|  xx                 |

|   xx                |

|    xx               |

|    xx  xxx        xx|

|     xxx  xx       xx|

|      xx   x     xxx |

|           xx   xx   |

|            x  xx    |

|            xx xx    |

|             x xx    |

|             xxxx    |

------------------------------------------

with x and y coords

--------------------------------------------

|    x     |           |

|          |           |

|          |    x      |

|          |           |

| x       x|           |

|          |           |

|          |           |

| ---------o-----------|

|          |           |

|          |           |

|      x   |           |

|          |           |

|          |   x       |

|          |           |

|          |           |

|          |           |

|          |           |

|          |           |

|          |           |

|          |        x  |

|          |          x|

--------------------------------------------

plotting a histogram

 

 451|  o         

 427|  o         

 403|  o         

 380|  o         

 356|  o         

 332|  o         

 309|  o         

 285|  o         

 261|  oo        

 238|  oo        

 214|  oo        

 190|  oo        

 166|  oo        

 143|  oo        

 119|  ooo       

  95|  ooo       

  72|  oooo      

  48|  oooo      

  24|  ooooo     

   1| ooooooooooo

     -----------

 

-----------------------------------

|             Summary             |

-----------------------------------

|        observations: 1000       |

|       min value: 0.001718       |

|         mean : 0.988786         |

|       max value: 6.552654       |

-----------------------------------

with colors

 

 451|  o         

 427|  o         

 403|  o         

 380|  o         

 356|  o         

 332|  o         

 309|  o         

 285|  o         

 261|  oo        

 238|  oo        

 214|  oo        

 190|  oo        

 166|  oo        

 143|  oo        

 119|  ooo       

  95|  ooo       

  72|  oooo      

  48|  oooo      

  24|  ooooo     

   1| ooooooooooo

     -----------

 

-----------------------------------

|             Summary             |

-----------------------------------

|        observations: 1000       |

|       min value: 0.001718       |

|         mean : 0.988786         |

|       max value: 6.552654       |

-----------------------------------

changing the shape of the point

 

 451|  .         

 427|  .         

 403|  .         

 380|  .         

 356|  .         

 332|  .         

 309|  .         

 285|  .         

 261|  ..        

 238|  ..        

 214|  ..        

 190|  ..        

 166|  ..        

 143|  ..        

 119|  ...       

  95|  ...       

  72|  ....      

  48|  ....      

  24|  .....     

   1| ...........

     -----------

 

-----------------------------------

|             Summary             |

-----------------------------------

|        observations: 1000       |

|       min value: 0.001718       |

|         mean : 0.988786         |

|       max value: 6.552654       |

-----------------------------------

adding x-labels

 

 451|  .         

 427|  .         

 403|  .         

 380|  .         

 356|  .         

 332|  .         

 309|  .         

 285|  .         

 261|  ..        

 238|  ..        

 214|  ..        

 190|  ..        

 166|  ..        

 143|  ..        

 119|  ...       

  95|  ...       

  72|  ....      

  48|  ....      

  24|  .....     

   1| ...........

     -----------

     0 1 2 3 5 6 

     . . . . . . 

     0 3 6 9 2 5 

     0 1 2 3 4 5 

     1 1 2 2 2 2 

 

-----------------------------------

|             Summary             |

-----------------------------------

|        observations: 1000       |

|       min value: 0.001718       |

|         mean : 0.988786         |

|       max value: 6.552654       |

-----------------------------------

 

引用

GitHub - glamp/bashplotlib: plotting in the terminal

 

関連