htslib과 samtools를 windows에서 compile 하기




머리말

Samtools를 windows에서 exe 파일로 compile 하는 과정 정리.

htslib과 samtools에서 공식적으로 제공한다. 하지만, 문서가 파편화되어 보인다.

한국어로는 정리된게 없으므로 정리해본다.

순서는 다음과 같다.

  1. MSYS2 환경을 만들고, samtools에 필요한 tool과 library를 설치한다.
  2. htslib과 samtools의 git source를 받고 compile 한다.



1. MSYS2 설치

MSYS2 환경을 설치해야한다. 아래 링크에서 install파일을 받고 설치한다.

https://www.msys2.org/



⭐ 설치 디렉토리는 compile된 samtools도 포함될 예정이므로 기억해두자. 나의 경우에는 아래와 같다.



설치가 끝나면 실행하지 않고 종료하자. 실행했다면, MSYS2 ucrt64 터미널이 열리는데 닫아주자.

samtools contributer가 MingGW64를 언급해서 해당 환경만 해보았다.



2. MSYS2 MINGW64 실행.

windows 키를 누르고 MSYS2 MINGW64 입력하면 터미널 실행이 된다.

MSYS2가 windows에서 POSIX 실행 환경을 제공하는 cygwin을 기반으로 구성되어 있기 때문에, 왠만한 linux 커맨드는 다 된다.



3. MSYS2 MINGW64에서 필요한 라이브러리 설치

MSYS2에서는 pacman 소프트웨어 매니저를 사용한다.

아래 명령어로, 빌드에 필요한 tool과 library를 설치한다.

1
pacman -S --noconfirm mingw-w64-x86_64-autotools mingw-w64-x86_64-toolchain mingw-w64-x86_64-curl mingw-w64-x86_64-zlib mingw-w64-x86_64-bzip2 mingw-w64-x86_64-xz mingw-w64-x86_64-ncurses git

약 1200MiB 공간이 필요하다.

옵션 설명

  • -S 는 sync라는 옵션으로 설치, 업그레이드 등에 사용된다.
  • --noconfirm은 설치 동의를 묻지 않게 해준다.

설치 항목 설명

  • mingw-w64-x86_64-autotools: MSYS2에서 compile에 사용할 autoheader과 autoconfig를 설치해준다.
  • mingw-w64-x86_64-toolchain: compiler 관련된 도구들을 설치해준다.
  • mingw-w64-x86_64-curl, mingw-w64-x86_64-zlib, mingw-w64-x86_64-bzip2, mingw-w64-x86_64-xz, mingw-w64-x86_64-ncurses : htslib, samtools에 필요한 library들.
  • git



4. htlib 및 samtools 설치

htslib Compile

나는 user 경로에서 진행했다.

1
cd ~

git clone 및 compile은 아래 과정으로 진행된다.

1
2
3
4
5
6
7
8
9
10
11
12
13
git clone -b master https://github.com/samtools/htslib
cd htslib

# htscodecs 서브 모듈 설치
git submodule update --init --recursive


# autoconf는 2.69 버전으로 돌려준다.
autoheader && autoconf-2.69 && ./configure && make -j4 && make install

# 혹은 아래를 이용한다.
# autoheader && autoconf && ./configure && make -j4 && make install

아직 잘 모르는점. autoconf를 실행하면 2.72 버전 (최신)이 실행되는데, 이걸로는 compile이 되지 않는다. 여기서는 2.69 버전을 실행하면 정상적으로 된다.

Samtools Compile

나는 user 경로에서 진행했다.

1
cd ~

git clone 및 compile은 아래 과정으로 진행된다.

1
2
3
4
git clone -b master https://github.com/samtools/samtools
cd samtools

autoheader && autoconf && ./configure && make -j4 && make install

🎈compile 과정에서 아래의 warning이 나타날 수 있지만 무시해도 된다. github:samtools:autoconf warnings

1
2
3
4
configure.ac:64: warning: _AC_CONFIG_SUBDIRS: you should use literals
../autoconf-2.72/lib/autoconf/status.m4:1096: AC_CONFIG_SUBDIRS is expanded from...
m4/ax_with_htslib.m4:55: AX_WITH_HTSLIB is expanded from...
configure.ac:64: the top level

이 과정을 통해 samtools.exe 가 생성되며, 정상 작동한다.



5. windows에서 사용하기

exe 파일을 powershellcmd에서 써보자.

위 1번의 MSYS2를 설치한 경로 하위에서, samtools는 아래 2개 경로에 위치한다.

  1. D:\msys64\home\{username}\samtools
  2. D:\msys64\mingw64\bin

두 경로로 가보면 samtools가 있음을 확인할 수 있다.



이 경로 그대로 terminal에서 실행 가능하다.



PATH 설정하기

MSYS2를 이용하면 linux에서만 compile 가능하던 binary를 windows에서 사용할 수 있다.

좀더 편하게 쓰기 위해 PATH를 설정해보았다.

설정

  1. 내 PC 우클릭 후 속성 선택
  2. 고급 시스템 설정 선택
  3. 고급 탭의 환경 변수 선택
  4. 사용자에 대한 사용자 변수 에서 Path를 선택하고 편집 클릭
  5. 새로 만들기를 선택하고 D:\msys64\mingw64\bin 입력

이제 MSYS2의 파일도 path에 추가되었으므로, terminal에서 samtools 명령어로 접근 가능하다.



테스트

samtools view



맺음말

  • MSYS2의 사용방법을 배웠다. 유용하게 사용할 수 있을 것 같다.
  • 이번 htslib & samtools 설치로, windows compile이 가능해지니 htslib을 binding하는 다른 언어의의 library에서도 편하게 사용이 가능하다. (조금 수정이 필요할 순 있다)




Reference

  1. https://github.com/samtools/htslib
  2. https://github.com/samtools/samtools
  3. https://github.com/samtools/htslib/issues/907
  4. https://github.com/samtools/samtools/issues/689#issuecomment-308400164