Saturday, December 13, 2025

How to build KMER-DB on a Windows PC

After having a lot of difficulty compiling KMER-DB for windows, I have finally succeeded in getting it to compile on a Windows machine.

I started by downloading the latest release from : https://github.com/refresh-bio/kmer-db/releases




You can also obtain it from : https://github.com/refresh-bio/kmer-db

I then unzipped it and found that there was a Visual Studio solution file in the src folder:


I am currently using Visual Studio 2022 Community Edition.

But when I tried to compile it I found that it was not building as there was a pre-build step failing.




I then had to download some extra code for other libraries:



I had to download: 

https://github.com/intel/isa-l

https://github.com/microsoft/mimalloc

https://github.com/zlib-ng/zlib-ng

https://github.com/netwide-assembler/nasm

And I then put the extracted folder of each's code in the appropriate lib sub folder.


After I did this I also found that I had the ensure the NMAKE.exe utility's path was in my path variables:
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.43.34808\bin\Hostx64\x64

And the Resource Compiler RC.exe is in the path as well:
C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64

As well as the compiled NASM.exe , which I compiled here:
C:\Tools\nasm-master
(But I have an idea just having put it in the lib folder and just compiling as part of the Visual Studio pre build step could have worked.)

Anyhow, I compiled it with MINGW64 using the commands:


./autogen.sh

./configure

make

make install


After I had everything in place it built successfully in Visual Studio:








Thursday, January 2, 2025

How to build SAMTOOLS on a Windows PC

I have recently started to add functionality in the Visual genome Browser to be able to display the aligned reads from a SAM/BAM/CRAM file as a graphical representation similar to IGV. In order o be able to do that, I needed to compile a 64-bit EXE version of SAMTOOLS for Windows PCs. 

 These are the steps that I followed:

I read through the build instructions at:

In the section that says: "Windows MSYS2/MINGW64" I then realized I need a Compilation environment which is called MSYS, which contains a compiler: mingw64.exe


I then proceeded to download the file: msys2-x86_64-20241208.exe



I started the installation on my Windows PC:




Then you RUN: MSYS2 MINGW64
This will open the build environment.

First thing to do is to check if the MSYS is up to date by typing: pacman -Syuu


And respond with Y


Then you have to run it again after it has been upgraded: MSYS2 MINGW64

Also check that $MSYSTEM equals MINGW64 by typing: echo $MSYSTEM




Then update more components by typing the following one after the other and confirming by pressing enter.

pacman -S base-devel mingw-w64-x86_64-toolchain
pacman -S mingw-w64-x86_64-libdeflate mingw-w64-x86_64-zlib mingw-w64-x86_64-bzip2
pacman -S mingw-w64-x86_64-xz mingw-w64-x86_64-curl mingw-w64-x86_64-autotools
pacman -S mingw-w64-x86_64-tools-git






Now download the C language source code base for SAMTOOLS from 

These contain full source repositories which has the required libraries inside them:

Then I unzipped it. Probably a good idea to put it in a folder without spaces in the path, otherwise you will have to use "SAM\ TOOLS" with a backslash escape character to escape the spaces in the path.




Next step is to ensure that the folder where the compiler resides is in your WINDOWS Path variable:
(Depending on where you installed it initially)

E:\msys64\mingw64\bin

This is also where the SAMTOOLS will be put when it is compiled and installed.






Now you change to the folder where you have put the SAMTOOLS source code using the UNIX syntax in the console window of MINGW64
The following procedure is explained in : https://github.com/samtools/samtools/blob/develop/INSTALL

Then you have to change the current directory to where it was unzipped.

cd /F/Home/Development/SAMTOOLS/samtools-1.21

You can type  LS to get the directory listing

You then run autoreconf to create the configure file if it does not exist

Next step is to type: ./configure



Next is to compile and link the exe:
just type: make



This will use the Makefile to build the EXE



At the end of this build process you will end up with the SAMTOOLS.EXE



You can now "install" this to the E:\msys64\mingw64\bin folder which is in your path by typing:
make install

This will result in the SAMTOOLS.exe being put in the folder together with all of its dependencies:


To test if it works you can open a normal windows command line window and change to the folder:
F:\Home\Development\SAMTOOLS\samtools-1.21\test\quickcheck

Then you simply check if it can open a BAM file :
samtools view 3.quickcheck.ok.bam



That is what is needed to compile SAMTOOLS.EXE

If you want to re-run the make for some reason, you will have to remove the config.mk file first otherwise it will not work. (rm = remove)
rm config.mk
rm /e/msys64/mingw64/bin/samtools.exe
./configure

and then proceed to run
make 
and 
make install 


You can follow a similar procedure to build BCFTOOLS as obtained from:
https://www.htslib.org/download/

When you want to view a SAM file:
samtools view "F:\Home\Development\samtools-1.21\htslib-1.21\test\ce#1000.bam" 

When you want to view a CRAM file:
samtools view "F:\Home\Development\samtools-1.21\htslib-1.21\test\ce#1000.cram"

When you want to create an index to allow you to search within ranges:
samtools index "F:\Home\Development\samtools-1.21\htslib-1.21\test\ce#1000.cram"

When you only want to view a specific range:
samtools view "F:\Home\Development\samtools-1.21\htslib-1.21\test\ce#1000.cram" CHROMOSOME_I:3-3