1
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?

WSL2 + Ubuntu でバイオインフォマティクスを始めたい!

Last updated at Posted at 2024-10-12

はじめに

初めまして。とある初心者バイオインフォマティシャンです。
昔はnoteに載せていたのですが、これからはQiitaに載せていきます。
これまでに書いたものも少しずつこちらに移していきます。

noteの方は、感じたことなどを連ねる場として展開しますので、もしよければ覗いて下さい。(更新少なめ)
note

Windowsでもバイオインフォマティクス環境は作れる!

Windows System for Linux 2 (WSL2) + Ubuntuの環境が作りやすくなりましたね。
ただ、だからといって、全部覚えてるかと言われればそうではない・・・ということで、

かつて九州大学の講義で扱われた内容をベースに、WSL2にUbuntuを導入し、解析環境を構築する最初の一歩を踏み出す手順をまとめました。

目次

はじめに
①PowerShellのダウンロード
②Powershellの起動
(1) Windows GUIでの起動
(2) Windows CUIでの起動
③Windows Subsystem for Linux (WSL)のインストール
(1) 以下のコマンドを実行
(2) Ubuntuを起動する
④sudoシステムのアップデート
⑤minicondaの導入
(1) minicondaのホームページに進む
(2) bashファイル・zshファイルを初期化する
(3) .condarcの作成
⑥mambaの導入
⑦Ubuntuの日本時間設定
⑧.bashrcの設定
⑨emacsの導入
(1) sudo apt installを使って導入
(2) emacsを起動
⑩conda環境の構築
⑪conda環境の起動

①PowerShellのダウンロード

Githubのページに進む
PowerShellのダウンロードサイト
→右下のReleasesの下の"Latest"と書かれた部分をクリック。
(例: v7.4.1 Release of PowerShell)
→使用しているOSごとにインストーラーが異なるので、適したインストーラーを選択。

②Powershellの起動

(1) Windows GUIでの起動

Windowsキー+"R"で"ファイル名を指定して実行"を起動し、その中に"pwsh"と入力。

Windows+R⇒pwsh

(2) Windows CUIでの起動

  1. コマンドプロンプトを起動(Windowsキー+"R"で"ファイル名を指定して実行"を起動し、その中に"cmd"と入力)
    commandprompt.png

  2. "pwsh"と入力

pwsh

もしくは

Windowsの場合はWindowsターミナルをMicrosoft Store等でインストールして使うのがおすすめ。Windows11以降は標準装備されているはず。
↓こういうものです
PowerShell 2024_10_11 23_05_49.png

③Windows Subsystem for Linux (WSL)のインストール

(1) 以下のコマンドを実行

wsl --install

この後、Ubuntuのインストールまで自動で実行。

(2) Ubuntuを起動する

ターミナルを起動する。
Windowsの場合はWindowsターミナルをMicrosoft storeで入手。
ターミナル上で"Ubuntu"を入力しUbuntuを起動。
対話型なので、ユーザー名やパスワードの設定などを順次行うこと。

Ubuntuが起動しないときは

・Linux用サブシステムを有効
Powershell内で以下のコマンドを実行。

#Linux用サブシステムを有効にする
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

#仮想マシンの機能を有効にする
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

参考にしたサイト↓

④sudoシステムのアップデート

これをしないと色々バグが生じる

sudo apt --fix-broken install

⑤minicondaの導入

(1) minicondaのホームページに進む

UbuntuはLinuxベースのOSなので、Quick command line installの"Linux"の部分をクリックし、以下のコマンドをコピー及び実行する。
最新の64-bitバージョンのインストーラを素早く静かにインストールするために実行する。

mkdir -p ~/miniconda3
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh
bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3
#.shインストーラは使用後消去する。
rm -rf ~/miniconda3/miniconda.sh

異なるバージョンやアーキテクチャのMiniconda for Linuxをインストールする際は、
wgetコマンドで.sh インストーラの名前を変更することで対応。

wget https://repo.anaconda.com/miniconda/Miniconda3-"ここを変える".sh

(2) bashファイル・zshファイルを初期化する

以下のコマンドを実行する
minicondaのインストール直後は、環境設定やパスがシェルに反映されていないことがある。
この操作によって、condaコマンドが正しく動作し、ターミナルでconda環境が利用できる。

~/miniconda3/bin/conda init bash
~/miniconda3/bin/conda init zsh

(3) .condarcの作成

conda installを使う際に、".condarc"を作成し、以下のように書く

# This is a sample .condarc file.
# It adds the r Anaconda.org channel and enables
# the show_channel_urls option.

# channel locations. These override conda defaults, i.e., conda will
# search *only* the channels listed here, in the order given.
# Use "defaults" to automatically include all default channels.
# Non-url channels will be interpreted as Anaconda.org usernames
# (this can be changed by modifying the channel_alias key; see below).
# The default is just 'defaults'.
channels:
  - r
  - defaults
  - bioconda
  - anaconda
  - conda-forge
# Show channel URLs when displaying what is going to be downloaded
# and in 'conda list'. The default is False.
show_channel_urls: True

# For more information about this file see:
# https://conda.io/docs/user-guide/configuration/use-condarc.html

しかし、2020/4より、従業員数200名以上の営利企業では、Anacondaの利用が有償化されたようです。
無料のIndividual Editionではなく、Commercial Editionを利用するよう規約改定されました。
また、2024年には教育機関で研究目的の利用時は200人以上の組織であれば有償教育機関はカリキュラムベースのコースの使用のみに限定される場合には免除されるとのことです。

これを適用すると、.condarcにおいて、

  - r
  - defaults
  - bioconda
  - anaconda
  - conda-forge

  - nodefaults
  - bioconda
  - conda-forge

に修正されるので、該当する人は忘れずに修正した方がいいと思います。

⑥mambaの導入

mambaは、Condaパッケージマネージャーの高速な代替ツールである。

conda install conda-forge::mamba

⑦Ubuntuの日本時間設定

まず、現在の時間設定を確認。
基本的には協定世界時間(UTC)で時刻表示されている。

date
#Fri Oct 11 14:57:07 UTC 2024 

以下のコマンドで日本時間に変更。

sudo apt install dbus
sudo timedatectl set-timezone Azia/Tokyo
date
#Fri Oct 11 23:57:27 JST 2024

⑧.bashrcの設定

使い勝手がよい.bashrcの設定として、国立遺伝研のスパコンの設定を使うとよい。

実際の例
.bashrc
# If this variable is already set, skip the rest of the script
if [ -n "$BASHRC_LOADED" ]; then
    return
fi

# Set the variable to indicate that the script has been loaded
BASHRC_LOADED=1

# ---

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
case $- in
    *i*) ;;
      *) return;;
esac

# don't put duplicate lines or lines starting with space in the history.
# See bash(1) for more options
HISTCONTROL=ignoreboth

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# If set, the pattern "**" used in a pathname expansion context will
# match all files and zero or more directories and subdirectories.
#shopt -s globstar

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
	# We have color support; assume it's compliant with Ecma-48
	# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
	# a case would tend to support setf rather than setaf.)
	color_prompt=yes
    else
	color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# colored GCC warnings and errors
#export GCC_COLORS='error=01;31:warning=01;35:note=01;36:caret=01;32:locus=01:quote=01'

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Add an "alert" alias for long running commands.  Use like so:
#   sleep 10; alert
alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

以下、必要な場合

⑨emacsの導入

emacsはvimのようなエディタの一種。あまり使ったことはないですね。

(1) sudo apt installを使って導入

sudo apt update
sudo apt install emacs

(2) emacsを起動

GUIベースでは砂嵐が発生するので、-nw(no window)コマンドを使う

echo "alias emacs='emacs -nw'" >> ~/.bashrc #.bashrcファイルに書き込む
source ~/.bashrc #再起動

⑩conda環境の構築

conda create -n "環境名" -y 

mamba環境でもよい

mamba create -n "環境名" -y 

⑪conda環境の起動

conda activate "環境名"

mamba環境でもよい

mamba activate "環境名"

#終了したいときは

conda deactivate "環境名"

最後に

今後も解析手法を投稿していこうと思います。それでは。
最初に戻る

1
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
1
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?