Showing posts with label genomics. Show all posts
Showing posts with label genomics. Show all posts

Tuesday, February 16, 2016

Adventures in compiling bgc for Bayesian estimation of genomic clines

Now that I have Ubuntu, installed the required libraries, and downloaded the program source code, I can install bgc.  It took me a lot of following error messages and looking for files, so please go to the end to see my final commands to get it compiled.  Even then, do not use my commands exactly.  This post is more to show you how the compilation process went and where things went wrong.  (Everywhere, that's where; mainly due to my inexperience.)

After reading the instruction manual for bgc, I ran this in the terminal:

/usr/local/src/bgcdist$ h5c++ -Wall -O2 -L/usr/include/gsl/lib -I/usr/local/gsl-1.15/include -o bgc

I got an error message:
The program 'h5c++' is currently not installed. You can install it by typing:
sudo apt-get install hdf5-helpers

So I did.

Note that I changed the directory for where to find GSL (highlighted) because I couldn't find it in usr/local.   Eventually I gave up looking for it and uninstalled GSL, then downloaded it to install from source where I specified the directory using ./configure --prefix=/usr/local .  (Spoiler alert: I mistyped this as "user/local" when I downloaded from source and this caused most of my problems later on.  I believe I should have used the Ubuntu software center to resintall it and make sure I had all the GSL libraries I needed because when I reinstalled GSL at the very end, it worked fine from the software center.)

**********************************************************************

 Done. The new package has been installed and saved to

 /usr/local/src/gsl-1.16/gsl_1.16-1_amd64.deb

 You can remove it from your system anytime using:

      dpkg -r gsl

**********************************************************************

It still went into src.  Hmm.

h5c++ -Wall -O2 -o bgc bgc_main.C bgc_func_readdata.C bgc_func_initialize.C bgc_func_mcmc.C bgc_func_write.C bgc_func_linkage.C bgc_func_ngs.C bgc_func_hdf5.C mvrandist.c -lgsl -lgslcblas

Be careful pasting from the manual, as in my terminal the underscores disappeared and then it couldn't find the files.

This gave me different errors, where it couldn't find GSL and compilation terminated.

h5c++ -Wall -O2 -L/usr/local/src/gsl-1.16 -I/usr/local/src/gsl-1.16 -o bgc bgc_main.C bgc_func_readdata.C bgc_func_initialize.C bgc_func_mcmc.C bgc_func_write.C bgc_func_linkage.C bgc_func_ngs.C bgc_func_hdf5.C mvrandist.c -lgsl -lgslcbla

This changed the missing files from those from gsl to one called hdf5.h.

h5c++ -Wall -O2 -L/usr/local/src/gsl-1.16 -I/usr/local/src/gsl-1.16 -prefix=/usr/local/src/hdf5-1.8.15-patch1/hdf5 -o bgc bgc_main.C bgc_func_readdata.C bgc_func_initialize.C bgc_func_mcmc.C bgc_func_write.C bgc_func_linkage.C bgc_func_ngs.C bgc_func_hdf5.C mvrandist.c -lgsl -lgslcbla

Nope.

Uninstalled hdf5.  Then I found a recommendation to install an hdf5 cpp.  Nope, still didn't work.  (The observant or more experienced reader may note that I keep changing that last green-highlighted portion of the commands to have an s at the end or not.  You will see below that this was of course a problem too.)

**********************************************************************
Finally, I was told that I had the prefixes wrongly specified (prefix just means it should be L or I, not actually saying prefix) and I had accidentally installed GSL into "user" instead of "usr" (the standard folder name).  So this code below works because I needed to replace prefix with -I/, installed hdf5-dev and hdf5-serial-dev to get some of the files when they weren't found, and pointed the compiler to the wayward GSL files in the weird directory.  I also sometimes forgot the s at the end of the green-highlighted command in previous attempts.
h5c++ -Wall -O2 -L/user/local/lib -L/usr/local/src/hdf5-1.8.15-patch1/hdf5/lib/ -I/usr/local/src/gsl-1.16 -I/usr/local/src/hdf5-1.8.15-patch1/hdf5/include/ -o bgc bgc_main.C bgc_func_readdata.C bgc_func_initialize.C bgc_func_mcmc.C bgc_func_write.C bgc_func_linkage.C bgc_func_ngs.C bgc_func_hdf5.C mvrandist.c -lgsl -lgslcblas

As with most things, essentially the installation process is following the error messages.  If the compiler can't find a file, make sure the compile commands point to the correct directories (search for where the file is located), or go install the package/library or a related thing (like the -dev versions of hdf5) if it can't find it because it doesn't exist yet.  Finally, when I went to run the compiled bgc, it turned out that the bgc program still couldn't find GSL in the misnamed "user" folder anyway.  I uninstalled GSL (using the Ubuntu software center), reinstalled it, and bgc started then.

UPDATE 2016/07/14: This is much easier if you don't fill your commands with typos and install the required packages in the correct places.  I upgraded to Ubuntu 16.04 LTS and it apparently removed GSL, so bgc no longer ran.  I reinstalled gsl and the gsl development versions from the command line this time using 'sudo apt-get install gsl-bin libgsl-dev'.  That presumably put them in the right place this time.  I then navigated to the bgcdist folder where the files were stored, and ran the exact compiling command from the user manual/documentation.  I was dreading a multi-hour fiasco again and it just worked.  I think the moral of the story here is that this is a lot easier if you have installed packages a few times in Ubuntu by the time you attempt this, but it is doable even if you are brand new.

Tuesday, November 03, 2015

Installing libraries on a linux operating system

Now that my computer can dual-boot into Ubuntu and Windows, I am going to start getting things set up for my original need for a Linux-type operating system: a program for estimation of genomic clines called bgc.  Installing the GNU Scientific Library was first.  I searched for it in the software center, and I was surprised to have 15+ options in the search results.  I eventually chose "GNU Scientific Library (GSL) -- library package".  It noted in "more info" that "To compile your own programs you also need to install libgsl0-dev", which I figure I do since bgc requires compiling.  I installed that one too.  Easy enough!

HDF5 at first seemed like it would be similarly easy, but all the binaries ready for installing were for either Windows or CentOS Linux, which I assume would be different.  So I have to compile it.  I followed "Compiling the easy way" from the Ubuntu website.

Step 1.  I wasn't sure if I was supposed to remove the $ before $USER.  Turns out I was.  I got an error when I tried $claire for my user name.  "chown: missing operand after ‘/usr/local/src’"  It worked fine when I just put claire though.  The hdf5 instructions say I need 'gcc' to compile it.  This Ubuntu help says build-essential contains gcc, and the "Compiling the easy way" did have me install it in this step.

Step 2. Obtain the package!  I got a .tar with Unix line endings (since the other options were Mac or Windows line endings) and .tar.gz seemed more complicated.  I moved it to the /user/local/src folder (which is under "Home") and right-clicked, then "Extract here".  I looked in the folder and there seemed to be some configure files, so I'll go ahead and try the next step

Step 3. The link to auto-apt confused me, so i went with the manual version, installing apt-file and its update ("sudo apt-get install apt-file" then "sudo apt-file update" which did not take as long as the instructions threatened on my reasonably fast connection, maybe five minutes at most).  I went into my directory (/usr/local/src) in the terminal as instructed, and ran ./configure and it gave me a different error message.  I navigated one level lower (to /usr/local/src/hdf5-1.8.15-patch1) and then it worked!  It did not end with any dependency errors, but it also did not obviously with config.status: creating Makefile.  I scrolled back up and found it, though, along with lots of other creating of filenames in various directories, and "no obvious errors" as the Ubuntu page said, so on to Step 4.

Step 4. It says to give the command "make".  I did.  Many things began happening, including warnings about overflows and floating points and such.  However, it kept going, so I let it be.  The hdf5 instructions said to "make install" in their step 4.3.1 so hopefully that didn't mess it up.  It took maybe five minutes.  As I read the Ubuntu instructions further "sudo checkinstall" replaces "make install".  I did the sudo checkinstall and the terminal asked if i wanted to create a default set of package docs.  Only one option ("y") so I said yes.  Then it wanted me to write a description for the package and end it with an empty line or EOF.  I wrote hdf5 and then pressed enter.  But enter just gave me a new line prefixed with >>.  So, end of file (EOF) is ctrl+D in linux?  But a blank line might work too?  I tried the blank line first.  That worked (pressing enter twice to create the blank line).  Next up it gave me a list of values for building the package (maintainer, summary, name, version, etc).  I couldn't think of any changes so I pressed enter to continue.  Then I messed up and tried to copy the message and ctrl+c did something, not sure what.  So I ran "sudo checkinstall" again and it seemed happy to return to the same message.  I pressed "y" when it asked me this:

Some of the files created by the installation are inside the build
directory: /usr/local/src/hdf5-1.8.15-patch1

You probably don't want them to be included in the package,
especially if they are inside your home directory.
Do you want me to list them?  [n]: y

This got me to a weird screen with (END) at the bottom.  Help me, google!  Pressing Q and then enter got me back to the main screen where it asked:

Should I exclude them from the package? (Saying yes is a good idea)  [y]: y

The install failed.

dpkg-deb: error: parsing file '/var/tmp/tmp.d7tq23dvxW/package/DEBIAN/control' near line 7 package 'hdf5-1.8.15':
 error in 'Version' field string 'patch1-1': version number does not start with digit

So I tried again.

I keep forgetting and pressing ctrl+c.
*** SIGINT received ***

Restoring overwritten files from backup...OK

Cleaning up...OK

Bye.

According to wikipedia, if I understand correctly, this just interrupts the current process.  So, it should be okay.

Anyway, the new install with version number changed to 1.8.15-patch1 installed fine!

******************************************************************
 Done. The new package has been installed and saved to

 /usr/local/src/hdf5-1.8.15-patch1/hdf5-1.8.15_1.8.15-patch1-1_amd64.deb

 You can remove it from your system anytime using:

      dpkg -r hdf5-1.8.15
*******************************************************************

I'm still not really sure if that's where I wanted it installed, but this stackexchange answer seems to indicate it is an appropriate place and I think section 4.6 in the hdf5 instructions agrees.

Step 4.5 in the hdf5 instructions suggests testing the library, so I ran "make check" and waited for it to go through its paces, which took about three minutes.  It didn't return any errors so I appear to have installed it!   Soon I will compile bgc and see if that works; presumably if the hdf5 install didn't go right in non-obvious way, I will find out then.

Thursday, February 26, 2015

Setting up a virtual machine to run a linux operating system

I need linux so I can start learning how to use bgc, a program for analyzing genomic clines.  As I don't have any spare computers around to install linux on (and it seemed easier than dual-booting one of my main working computers), I decided to try a virtual machine.

First, download Oracle's free VirtualBox and your operating system of choice.  From the many flavors of linux, I started with Ubuntu as it seemed least intimidating and likely to do be sufficient for my purpose of running the one program.

Install VirtualBox first.  Once you've set up your first machine (I let it do all the default settings), copy the Ubuntu .iso file into your VM's folder.  Mine was stored at C:/Users/Username/VirtualBox VMs/yourvirtualmachinesname/ and I placed the .iso file in that folder.

Run your VM.  It'll ask you from what optical drive you want to boot.  Set the CD/DVD optical drive to the .iso file.  If you get a fatal boot error because you didn't do this the first time, just set the drive, then restart, and it should boot as if you had an operating system disk in a real computer.  It took a while to get to the install screen.  I let it run in the background and worked on other stuff.  Same for the Install Ubuntu wizard.  Periodically check and answer its questions.  It took a while (started 1pm, finished around 4pm), just like a real operating system install.

I found Ubuntu ran pretty slow in the VM on my aging tiny laptop, and XUbuntu was suggested to me as a less graphics-intensive alternative.  That's what I'm using now (just create a new VM in VirtualBox and follow the same steps) and that install also took less time (maybe an hour or two with me ignoring it as I did other tasks).  Stay tuned as I learn how to install some prerequisites for bgc (GNU Scientific Library and HDF5).