# Compiling DIDA from source
To compile and install DIDA in /usr/local:

$ ./configure
$ make 
$ sudo make install 

To install DIDA in a specified directory:

$ ./configure --prefix=/opt/dida
$ make 
$ sudo make install 

DIDA uses OpenMP for parallelization, which requires a modern compiler such as GCC 4.2 or greater. If you have an older compiler, it is best to upgrade your compiler if possible. If you have multiple versions of GCC installed, you can specify a different compiler:

$ ./configure CC=gcc-4.9 CXX=g++-4.9 

If you wish to build the DIDA with MPI support, MPI should be found in /usr/include and /usr/lib or its location specified to configure:

$ ./configure --with-mpi=/usr/lib/openmpi 

To run DIDA, its executables should be found in your PATH. If you installed DIDA in /opt/dida, add /opt/dida/bin to your PATH:

$ PATH=/opt/dida/bin:$PATH

To run DIDA, its executables should be found in your PATH. If you installed DIDA in /opt/DIDA, add /opt/dida/bin to your PATH:

$ PATH=/opt/dida/bin:$PATH

# Distribute Indexing and Alignment 
To align a library of read files named <query.in> against the target named <target> using the batch version of DIDA, run the set of following commands:

1. prt -p <partition> <target>
2. index <sub-target>
3. dsp [options] -p <partition> -l <l-mer> <query.in> 
4. map <sub-query> <sub-target>
5. mrg -p <partition> -a <aligner> -m <mode> 

In dsp command, -l <l-mer> is the minimum seed or exact match length related to aligners for candidate hits. [options] are:
-b: specifies the b-mer length for loading and querying Bloom filters.
-s: specifies the step size when breaking a query sequence into b-mers. 
-h: specifies the number of hash functions for Bloom filter, [default=5]. 
-i: specifies the number of bits per item for Bloom filter, [default=8]. 

In mrg command, <mode> values are: 
-mem: this mode is coupled with -r <record> option and reports the best alignment records for each read sequence up to the number specified by -r <record> option. The default value for -r <record> is [5]. 
-best: the final alignment result includes the best quality mapped record for each read sequence from the related records in all partitions. 
-ord: reports all alignment records for each read sequence with the output order matching order of input reads. 
-fast: merges all partial alignment results from different partitions very quickly without keeping the order of input reads. 

In the command lines 2 and 4, instead of index <sub-target> and map <sub-query> <sub-target>, different indexing and alignment commands related to each method can be used which are as follows: 
BWA - version 0.7.10
$ bwa index <target> 
$ bwa mem -k <k-mer> -t <max−thread> <target> <query> 

Bowtie2 - version 2.1.0 
$ bowtie2-build <target> <target-index>
$ bowtie2-align --reorder -p <max−thread> -x <target-index> -U <query> 

Novoalign - version 3.01.02
$ novoindex -k <k-mer> <target-index> <target> 
$ novoalign -o Sync -o SAM -f <query> -d <target-index> 

ABySS-map - version 1.5.2 
$ abyss-index <target>
$ abyss-map -l <k-mer> -j <max−thread> --order <query> <target> 

Example of aligning a subset of chromosome 14 reads, chr14.in, against its draft assembly, CHR14.fa,CHR14.adj on 4 nodes using DIDA+ABySS-map. To install ABySS-map from ABySS Package:	http://www.bcgsc.ca/platform/bioinfo/software/abyss. We have included the binaries for abyss-index and abyss-map in the bin folder of DIDA package.   

bash
#!/bin/bash

# step 1: partition target
prt -p4 CHR14.fa

# step 2: index target partitions
for i in {1..4}
do
	abyss-index mref-$i.fa
done

# step 3: dispatch reads to target partitions
dsp -p4 -l28 chr14.in

# step 4: align reads against target partitions
for i in {1..4}
do
	abyss-map -l28 -j12 --order mreads-$i.fa mref-$i.fa > aln-$i.sam
done

# step 5: merge alignments against target partitions
mrg -p4 -a abyss-map -m best 

If we want to use bwa-mem instead of ABySS-map, we would use the same script with changes to steps 2, 4 and 5:

bash
#!/bin/bash

# step 1: partition target
prt -p4 CHR14.fa

# step 2: index target partitions
for i in {1..4}
do
	bwa index mref-$i.fa
done

# step 3: dispatch reads to target partitions
dsp -p4 -l28 chr14.in

# step 4: align reads against target partitions
for i in {1..4}
do
	bwa mem -t12 -k28 mref-$i.fa mreads-$i.fa > aln-$i.sam
done

# step 5: merge alignments against target partitions
mrg -p4 -a bwa-mem -m best


# Running DIDA on a cluster

DIDA integrates well with cluster job schedulers, such as:
	SGE (Sun Grid Engine)
	Portable Batch System (PBS)
	Load Sharing Facility (LSF)
	IBM LoadLeveler

DIDA has two versions to be run on a cluster, wrapper and mpi versions. In the wrapper version of DIDA, dida-wrapper, all steps in the batch version are linked together using Message Passing Interface (MPI). dida-wrapper can be further streamlined through implementing a massage passing interface protocol that sends reads or alignment records directly to the corresponding nodes instead of using temporary files to dispatch reads to target partitions or alignment record to the merger. This fully-streamlined version of DIDA is named dida-mpi.
To align a library of reads files named query.in={query1,query2,...} against the target set named target with the dida-wrapper version on n partitions use:
$ mpirun -np <n+1> dida-wrapper [options] -l <l-mer> -a <aligner> <query1,query2,...> <target>

With dida-mpi version use:
$ mpirun -np <n+2> dida [options] -l <l-mer> -a <aligner> <query1,query2,...> <target>


For example, to submit the above DIDA job for aligning a subset of chromosome 14 reads, chr14.in, against its draft assembly, CHR14.fa,CHR14.adj on 4 nodes using DIDA+ABySS-map on SGE Clusters using dida-wrapper version run: 

$ qsub -N dida-chr14 -pe openmpi 5 <<< 'mpirun -np 5 dida-wrapper -l28 -a abyss-map -m best frag_1.fastq frag_2.fastq CHR14.fa > res-chr14.sam'

and for dida-mpi version use:

$ qsub -N dida-chr14 -pe openmpi 6 <<< 'mpirun -np 6 dida-mpi -l28 frag_1.fastq frag_2.fastq CHR14.fa > res-chr14.sam'

