DoBlastzChainNet.pl

From genomewiki
Jump to navigationJump to search

Prerequisites

This discussion assumes you are familiar with Unix shell command line programming and scripting. You will be encountering and interacting with csh/tcsh, bash, perl, and python scripting languages. You will need at least one computer with several CPU cores, preferably a multiple compute cluster system or equivalent in a cloud computing environment.

This entire discussion assumes the bash shell is the user's unix shell.

Parasol Job Control System

The scripts and programs used here expect to find the Parasol_job_control_system in place and operational.

Install scripts and kent command line utilities

This is a bit of a kludge at this time (April 2018), we are working on a cleaner distribution of these scripts. As was mentioned in the Parasol_job_control_system setup, the kent command line binaries and these scripts are going to reside in /data/bin/ and /data/scripts/. This is merely a style custom to keep scripts separate from binaries, this is not strictly necessary to keep them separate.


 mkdir -p /data/scripts /data/bin
 chmod 755 /data/scripts /data/bin

 rsync -a rsync://hgdownload.soe.ucsc.edu/genome/admin/exe/linux.x86_64/ /data/bin/
 git archive --remote=git://genome-source.soe.ucsc.edu/kent.git \
  --prefix=kent/ HEAD src/hg/utils/automation \
     | tar vxf - -C /data/scripts --strip-components=5 \
        --exclude='kent/src/hg/utils/automation/incidentDb' \
      --exclude='kent/src/hg/utils/automation/configFiles' \
      --exclude='kent/src/hg/utils/automation/ensGene' \
      --exclude='kent/src/hg/utils/automation/genbank' \
      --exclude='kent/src/hg/utils/automation/lastz_D' \
      --exclude='kent/src/hg/utils/automation/openStack'

PATH setup

Add or verify the two directories /data/bin and /data/scripts are added to the shell PATH environment. This can be added simply to the .bashrc file in your home directory:

echo 'export PATH=/data/bin:/data/scripts:$PATH' >> $HOME/.bashrc

Then, source that file to add that to this current shell:

. $HOME/.bashrc

Verify you see those pathnames on the PATH variable:

echo $PATH
/data/bin:/data/scripts:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/centos/.local/bin:/home/centos/bin

This entire discussion assumes the bash shell is the user's unix shell.

Working directory hierarchy

It is best to organize your work in a directory hierarchy. For example maintain all your genome sequences in:

 /data/genomes/
 /data/genomes/hg38/
 /data/genomes/mm10/
 /data/genomes/dm6/
 /data/genomes/ce11/
 ... etc ...

Where those database directories can have the 2bit files, chrom.sizes, and track construction directories, for example:

 /data/genomes/dm6/dm6.2bit
 /data/genomes/dm6/dm6.chrom.sizes
 /data/genomes/dm6/trackData/

Such organizations are a personal preference custom. However you do this, keep it consistent to make it easier to use scripts on multiple sequences.

Obtain genome sequences

Genome sequences from the U.C. Santa Cruz Genomics Institute can be obtained directly from the hgdownload server via rsync. For example

mkdir /data/genomes/dm6
cd /data/genomes/dm6
rsync -avzP \
   rsync://hgdownload.soe.ucsc.edu/goldenPath/dm6/bigZips/dm6.2bit .
rsync -avzP \
   rsync://hgdownload.soe.ucsc.edu/goldenPath/dm6/bigZips/dm6.chrom.sizes .
ls -og
-rw-rw-r--. 1 36969050 Aug 28  2014 dm6.2bit
-rw-rw-r--. 1    45055 Aug 28  2014 dm6.chrom.sizes

Genome sequences from the NCBI/Entrez/Genbank system can be found via the assembly_summary.txt text listing information files, for example invertebrate genomes:

wget -O /tmp/invertebrate.assembly_summary.txt 'ftp://ftp.ncbi.nlm.nih.gov/genomes/refseq/invertebrate/assembly_summary.txt'

Looking for the Anopheles genome:


 grep -w Anopheles /tmp/invertebrate.assembly_summary.txt 
 GCF_000005575.2 PRJNA163        SAMN02952903    AAAB00000000.1  representative genome   180454  7165    Anopheles gambiae str. PEST     strain=PEST            latest   Chromosome      Major   Full    2006/10/16      AgamP3  The International Consortium for the Sequencing of Anopheles Genome     GCA_000005575.1 different       ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/005/575/GCF_000005575.2_AgamP3

Note the Assembly identification from the ftp path GCF_000005575.2_AgamP3, working with that sequence:


 mkdir /data/genomes/dm6/trackData/GCF_000005575.2_AgamP3
 cd /data/genomes/dm6/trackData/GCF_000005575.2_AgamP3
 wget --timestamping 'ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/005/575/GCF_000005575.2_AgamP3/GCF_000005575.2_AgamP3_genomic.fna.gz'
 wget --timestamping \
     'ftp://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/005/575/GCF_000005575.2_AgamP3/GCF_000005575.2_AgamP3_assembly_report.txt'
 ls -og
 total 79908
 -rw-rw-r--. 1   811394 Mar  7  2017 GCF_000005575.2_AgamP3_assembly_report.txt
 -rw-rw-r--. 1 81010275 Jun 15  2016 GCF_000005575.2_AgamP3_genomic.fna.gz

The assembly_report.txt file is useful to have for the meta-data information it has about the assembly. The fna.gz file needs to be in 2bit format for the processing system, and the chrom.sizes made from the 2bit:

faToTwoBit GCF_000005575.2_AgamP3_genomic.fna.gz GCF_000005575.2_AgamP3.2bit
twoBitInfo GCF_000005575.2_AgamP3.2bit stdout | sort -k2,2nr > GCF_000005575.2_AgamP3.chrom.sizes
ls -og
total 156132
-rw-rw-r--. 1 77912208 Apr  6 03:48 GCF_000005575.2_AgamP3.2bit
-rw-rw-r--. 1   138303 Apr  6 03:48 GCF_000005575.2_AgamP3.chrom.sizes
-rw-rw-r--. 1   811394 Mar  7  2017 GCF_000005575.2_AgamP3_assembly_report.txt
-rw-rw-r--. 1 81010275 Jun 15  2016 GCF_000005575.2_AgamP3_genomic.fna.gz

lastz parameter file

The DEF file is used with the script to specify alignment parameters to lastz and the axtChain operations. (Discussion about this file TBD). The example for dm6 target vs. A. gambiae query sequence, loose parameters are used for this distant alignment:

cat DEF
# dm6 vs GCF_000005575.2_AgamP3
PATH=/data/bin:/data/scripts
BLASTZ=/data/lastz/lastz-1.04.00
BLASTZ_H=2000
BLASTZ_Y=3400
BLASTZ_L=4000
BLASTZ_K=2200
BLASTZ_Q=/data/lastz/HoxD55.q

# TARGET: D. melanogaster dm6
SEQ1_DIR=/data/genomes/dm6/dm6.2bit
SEQ1_LEN=/data/genomes/dm6/dm6.chrom.sizes
SEQ1_CHUNK=32100000
SEQ1_LAP=10000
SEQ1_LIMIT=18

# QUERY: GCF_000005575.2_AgamP3
SEQ2_DIR=/data/genomes/dm6/trackData/GCF_000005575.2_AgamP3/GCF_000005575.2_AgamP3.2bit
SEQ2_LEN=/data/genomes/dm6/trackData/GCF_000005575.2_AgamP3/GCF_000005575.2_AgamP3.chrom.sizes
SEQ2_CHUNK=1000000
SEQ2_LIMIT=2000
SEQ2_LAP=0

BASE=/data/genomes/dm6/trackData/GCF_000005575.2_AgamP3
TMPDIR=/dev/shm

perform alignment

After the DEF file is established, verify the files specified in it are actually present at the locations specified:

egrep "_DIR|_LEN" DEF | sed -e 's/.*=//;' | xargs ls -og
-rw-rw-r--. 1 36969050 Aug 28  2014 /data/genomes/dm6/dm6.2bit
-rw-rw-r--. 1    45055 Aug 28  2014 /data/genomes/dm6/dm6.chrom.sizes
-rw-rw-r--. 1 77912208 Apr  6 03:48 /data/genomes/dm6/trackData/GCF_000005575.2_AgamP3/GCF_000005575.2_AgamP3.2bit
-rw-rw-r--. 1   138303 Apr  6 03:48 /data/genomes/dm6/trackData/GCF_000005575.2_AgamP3/GCF_000005575.2_AgamP3.chrom.sizes

Use a screen to keep this command attached to a terminal that you can detach from and reattach to at a later time. For large genomes, or with fewer CPU cores available, this command can run for many days. Time the operation of the command and record all output from it for later analysis if any problems arise from the operation:

screen -S dm6.GCF_000005575
time (/data/scripts/bigBlastzChainNet.pl `pwd`/DEF -verbose=2 -noDbNameCheck \
 -workhorse=localhost -bigClusterHub=localhost -skipDownload \
   -dbHost=localhost -smallClusterHub=localhost \
     -trackHub -fileServer=localhost -syntenicNet) > do.log 2>&1 &

The screen -S dm6.GCF_000005575 gives a name to the terminal so you can find it later in a listing of a number of screens. To detach from the running terminal, use two key presses:

"Ctrl-a Ctrl-d"

to reattach to this screen: screen -r -d dm6.GCF_000005575

BEWARE the drawback of the screen is that you can accidentally exit the shell while in the screen and you thus lose it. The processes that were attached to that shell can continue if they do not respond to the SIGHUP signal. To avoid this side-effect, develop a habit of always exiting a shell with the two key presses "Ctrl-a Ctrl-d", in a shell that is not in a screen it will merely echo those keystrokes and do nothing.

Monitor progress

To determine which step the process is working on, in this working directory, look for the word step in the do.log file:

cd /data/genomes/dm6/trackData/GCF_000005575.2_AgamP3
grep -w step do.log
HgStepManager: executing from step 'partition' through step 'syntenicNet'.
HgStepManager: executing step 'partition' Fri Apr  6 04:50:34 2018.
HgStepManager: executing step 'blastz' Fri Apr  6 04:50:46 2018.

To view the parasol status of your batch:

parasol list batches
#user     run   wait   done crash pri max cpu  ram  plan min batch
centos    323  18446  10283     0  10  -1   1  2.0g  323   0 /data/genomes/dm6/trackData/GCF_000005575.2_AgamP3/run.blastz/

To view the status of that particular batch:

cd /data/genomes/dm6/trackData/GCF_000005575.2_AgamP3/run.blastz/
para time
29052 jobs in batch
16647 jobs (including everybody's) in Parasol queue or running.
Checking finished jobs
..........................
Completed: 12405 of 29052 jobs
Jobs currently running: 323
In queue waiting: 16324 jobs
CPU time in finished jobs:      81145s    1352.42m    22.54h    0.94d  0.003 y
IO & Wait Time:                142817s    2380.28m    39.67h    1.65d  0.005 y
Time in running jobs:            4076s      67.93m     1.13h    0.05d  0.000 y
Average job time:                  18s       0.30m     0.01h    0.00d
Longest running job:               43s       0.72m     0.01h    0.00d
Longest finished job:              72s       1.20m     0.02h    0.00d
Submission to last job:           718s      11.97m     0.20h    0.01d
Estimated complete:               930s      15.51m     0.26h    0.01d

This example happens to be running on an Open Stack cluster with 323 allocated CPU cores:

parasol status
CPUs total: 323
CPUs free: 0
CPUs busy: 323
Nodes total: 20
Nodes dead: 0
Nodes sick?: 0
Jobs running:  323
Jobs waiting:  14977
Jobs finished: 13752
Jobs crashed:  0
Spokes free: 30
Spokes busy: 0
Spokes dead: 0
Active batches: 1
Total batches: 1
Active users: 1
Total users: 1
Days up: 0.012685
Version: 12.18

When a parasol batch is completed, this scripting process leaves a run.time file in the batch directory where you can see what type of cluster time you have used:

cd /data/genomes/dm6/trackData/GCF_000005575.2_AgamP3/run.blastz
cat run.time
Completed: 29052 of 29052 jobs
CPU time in finished jobs:     149061s    2484.35m    41.41h    1.73d  0.005 y
IO & Wait Time:                268812s    4480.20m    74.67h    3.11d  0.009 y
Average job time:                  14s       0.24m     0.00h    0.00d
Longest finished job:              72s       1.20m     0.02h    0.00d
Submission to last job:          1312s      21.87m     0.36h    0.02d
Estimated complete:                 0s       0.00m     0.00h    0.00d

For small genomes such as the two in this example, the steps after the lastz alignment can proceed rapidly:

grep -w step do.log
HgStepManager: executing from step 'partition' through step 'syntenicNet'.
HgStepManager: executing step 'partition' Fri Apr  6 04:50:34 2018.
HgStepManager: executing step 'blastz' Fri Apr  6 04:50:46 2018.
HgStepManager: executing step 'cat' Fri Apr  6 05:13:52 2018.
HgStepManager: executing step 'chainRun' Fri Apr  6 05:14:12 2018.
HgStepManager: executing step 'chainMerge' Fri Apr  6 05:15:49 2018.
HgStepManager: executing step 'net' Fri Apr  6 05:15:58 2018.
HgStepManager: executing step 'load' Fri Apr  6 05:17:06 2018.
HgStepManager: executing step 'download' Fri Apr  6 05:17:35 2018.
HgStepManager: executing step 'cleanup' Fri Apr  6 05:17:36 2018.
HgStepManager: executing step 'syntenicNet' Fri Apr  6 05:17:42 2018.

The syntenicNet is the last step in this process, the do.log timing will indicate the full time for this alignment:

tail -3 do.log
real    27m20.456s
user    0m0.720s
sys     0m0.394s

And featureBits measurements have taken place to indicate the amount of coverage of the target genome by the query genome, for both the fundamental alignment, and the syntenic filtered alignment:

ls fb.*
fb.dm6.chain.GCF_000005575.2_AgamP3Link.txt
fb.dm6.chainSyn.GCF_000005575.2_AgamP3Link.txt
cat fb.*
19155294 bases of 143726002 (13.328%) in intersection
1617815 bases of 143726002 (1.126%) in intersection

Reciprocal Best

After that alignment is completed, the reciprocal best alignment can be computed:

cd /data/genomes/dm6/trackData/GCF_000005575.2_AgamP3
export tDb=`grep "SEQ1_DIR=" DEF | sed -e 's#.*/##; s#.2bit##;'`
export qDb=`grep "SEQ2_DIR=" DEF | sed -e 's#.*/##; s#.2bit##;'`
export target2Bit=`grep "SEQ1_DIR=" DEF | sed -e 's/.*=//;'`
export targetSizes=`grep "SEQ1_LEN=" DEF | sed -e 's/.*=//;'`
export query2Bit=`grep "SEQ2_DIR=" DEF | sed -e 's/.*=//;'`
export querySizes=`grep "SEQ2_LEN=" DEF | sed -e 's/.*=//;'`
time (/data/scripts/doRecipBest.pl -buildDir=`pwd` -load \
  -workhorse=localhost -dbHost=localhost -skipDownload \
   -target2Bit=${target2Bit} -query2Bit=${query2Bit} \
    -targetSizes=${targetSizes} -querySizes=${querySizes} \
      -trackHub ${tDb} ${qDb}) > rbest.log 2>&1 &

This process does not have any parasol batch procedures. The procedure only does transformations on some of the result files computed during the first alignment procedure.