0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

獣医師が必死にバイオインフォマティクスPythonによる実践レシピをwin10で動かす(その2)

Posted at

rpy2によるRの実行

下記コードを実行せよと書かれている

!rm sequence.index 2>/dev/null
!wget -nd ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/historical_data/former_toplevel/sequence.index -O sequence.index

winでwgetが使えないので、しょうがなく普通にDL
普通に長いので経過を表示するプログラムも借りて作成

DL.py
import urllib.request
from colorama import init, Fore, Back, Style

# 進捗を表示させるためのコールバック関数
# イメージ:[=====>    ] 50.54% ( 1050KB )
def progress_print(block_count, block_size, total_size):
  percentage = 100.0 * block_count * block_size / total_size
  # 100より大きいと見た目が悪いので……
  if percentage > 100:
    percentage = 100
  # バーはmax_bar個で100%とする
  max_bar = 50
  bar_num = int(percentage / (100 / max_bar))
  progress_element = '=' * bar_num
  if bar_num != max_bar:
    progress_element += '>'
  bar_fill = ' ' # これで空のとこを埋める
  bar = progress_element.ljust(max_bar, bar_fill)
  total_size_kb = total_size / 1024
  print(
    Fore.LIGHTCYAN_EX,
    f'[{bar}] {percentage:.2f}% ( {total_size_kb:.0f}KB )\r',
    end=''
  )

def download(url, filepath_and_filename):
  init()
  print(Fore.LIGHTGREEN_EX, 'download from:', end="")
  print(Fore.WHITE, url)
  # コールバックでprogress_printを呼んで進捗表示
  urllib.request.urlretrieve(url, filepath_and_filename, progress_print)
  print('') # 改行
  print(Style.RESET_ALL, end="")

url = 'ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/historical_data/former_toplevel/sequence.index'
download(url, './sequence.index')

なんか矢印が動いているのを見ると楽しい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?