The EPO pipeline can be divided into 5 parts:
1). Generating the anchors for constructing the graph. The anchors consist of 
two or more sequences which are generated from pairwise whole-genome alignments 
(eg. BLASTZ or tBLAH alignments).
2). Once the anchors are generated these can be mapped to the target genomes 
(we use exonerate to do this).
3). The positions where the anchors map are then dumped to file and used as an 
input to the program Enredo, which generates a graph representation of the "syntenic"
regions shared by the target genomes.
4). The syntenic regions from enredo are loaded into a database and finally the these are 
aligned using ortheus (which also generates ancestral sequences).

###########################

Stage 1 - anchor generation:
Create a compara database for generating the anchors.
mysql -u$DBUSER -p$DBPASS -h$DBHOST -e"create database anchor_gen_test"
mysql -u$DBUSER -p$DBPASS -h$DBHOST -Danchor_gen_test <  ~/src/ensembl-compara/sql/table.sql
mysql -u$DBUSER -p$DBPASS -h$DBHOST -Danchor_gen_test <  ~/src/ensembl-compara/sql/pipeline-tables.sql
mysql -u$DBUSER -p$DBPASS -h$DBHOST -Danchor_gen_test < ~/src/ensembl-hive/sql/tables.sql

Transfer the dnafrags and genome_db entries from the compara-master database.

load in the information from the 'anchor_gen.conf" file (see below).
This file contains information regarding the "anchor_gen_test" database and the modules to use.
You will also need a newick tree representing the species you wish to generate the anchors from and the 
target species which you wish to map.

perl ~/src/ensembl-compara/scripts/pipeline/loadGenerateAnchors.pl --config $HOME/anchor_gen.conf 

run the beekeeper.
beekeeper.pl -url mysql://$DBUSER:$DBPASS@$DBHOST:3306/anchor_gen_test -sync
beekeeper.pl -url mysql://$DBUSER:$DBPASS@$DBHOST:3306/anchor_gen_test -loop

###########################

Stage 2 - map the anchors to the target genomes.

You will need a config file similar to anchor_map.conf (see below).
 
Run the loading script.
perl ~/src/ensembl-compara/scripts/pipeline/loadMapAnchors.pl --config $HOME/anchor_map.conf
run the beekeeper (as before).

###########################

Step 3 - Dump anchors for enredo

cat <<EOF >dump_script.sh
#!/bin/bash

mysql -u$ROUSER -h$DBHOST -Dcshl_test -NB -e"select aa.anchor_id, replace(gdb.name, \" \", \"_\"), df.name, aa.dnafrag_start, aa.dnafrag_end, \
aa.dnafrag_strand, aa.num_of_organisms, aa.score from anchor_align aa inner join dnafrag df on aa.dnafrag_id = df.dnafrag_id inner join \
genome_db gdb on gdb.genome_db_id = df.genome_db_id where aa.anchor_status is null and aa.method_link_species_set_id = ( \
select method_link_species_set_id from method_link_species_set where name=\"TrimAnchorAlign\") order by gdb.name,df.name, aa.dnafrag_start" \
| \
perl -we 'while(<>){ my@anc_align = split("\t", $_);$anc_align[5] = $anc_align[5]== 1 ? "+" : "-";print join("\t", @anc_align)}' \
> enredo_friendly.out
EOF

./dump_script.sh

run enredo.

cat <<EOF >run_enredo.sh
enredo  --min-score 0 --max-gap-length 200000 --max-path-dissimilarity 4 --min-length 10000 --min-regions 2 \
--min-anchors 3 --max-ratio 3 --simplify-graph 7 --bridges -o enredo.out enredo_friendly.out 
EOF

./run_enredo.sh

###########################

Step 4 - Run ortheus to generate the alignments.

This will require 2 new databases (a compara db "test_ortheus" for the alignments and a core db "test_ortheus_ancestral_core"
for the ancestral sequences)

mysql -u$DBUSER -h$DBHOST -p$DBPASS -e"create database test_ortheus"
mysql -u$DBUSER -p$DBPASS -h$DBHOST -Dtest_ortheus <  ~/src/ensembl-compara/sql/table.sql
mysql -u$DBUSER -p$DBPASS -h$DBHOST -Dtest_ortheus <  ~/src/ensembl-compara/sql/pipeline-tables.sql
mysql -u$DBUSER -p$DBPASS -h$DBHOST -Dtest_ortheus <  ~/src/ensembl-hive/sql/tables.sql

mysql -u$DBUSER -h$DBHOST -p$DBPASS -e"create database test_ortheus_ancestral_core"
mysql -u$DBUSER -p$DBPASS -h$DBHOST -Dtest_ortheus_ancestral_core < ~/src/ensembl/sql/table.sql

load the syntenic regions from the enredo.out file into the compara db
see ~ensembl-compara/scripts/pipeline/comparaLoadOrtheus.example

perl ~/src/ensembl-compara/scripts/pipeline/comparaLoadOrtheus.pl --reg-conf <ensembl_registry_file> --master <compara-master> \
  --to_db <to_db> --mlss_id <mlss_id> --species_tree <species_tree> --addMT 1 -i enredo.out

run the beekeeper (as before).
beekeeper.pl -url mysql://$DBUSER:$DBPASS@$DBHOST:3306/test_ortheus -sync
beekeeper.pl -url mysql://$DBUSER:$DBPASS@$DBHOST:3306/test_ortheus -loop

###########################

Configuration files:

############### anchor_gen.conf example ######################

[
	{
		TYPE => "anchorDBA",
		-dbname => "anchor_gen_test",
		-host => "$ENV{DBHOST}",
		-user => "$ENV{DBUSER}",
		-pass => "$ENV{DBPASS}",
		-port => 3306,
		-species => "Anchors",
	},
	{
		TYPE => "reference_genome_db_id",
		reference_genome_db_id => 90,
	},
	{
		TYPE => "analysis",
		analysis => [
				{ logic_name => "GetBlastzOverlaps", module => "Bio::EnsEMBL::Compara::Production::EPOanchors::GetBlastzOverlaps" }, #finds overlaps between ref and non-ref blastz alignments
				{ logic_name => "Pecan", module  => "Bio::EnsEMBL::Compara::Production::GenomicAlignBlock::Pecan", }, 
				{ logic_name => "Gerp", module  => "Bio::EnsEMBL::Compara::Production::GenomicAlignBlock::Gerp", },
				{ logic_name => "TrimStoreAnchors", module  => "Bio::EnsEMBL::Compara::Production::EPOanchors::TrimStoreAnchors", }, #this is a dummy analysis that sets up the last analysis for trimming and storing the anchors
			
		],
	},
	{
		TYPE => "non_ref_genome_db_ids",
		non_ref_genome_db_ids => [ 3,31,38,39,57,60,61,64 ],
	},
	{
		TYPE => "tree_file",
		tree_file => "$ENV{HOME}/CSHL/9way.nw",
	},
	{
		TYPE => "analysis_data",
		analysis_data =>{ 
			anchor_size_range => [50,250], 
			min_number_of_org_hits_per_base => 2,
			tree => "((((((((((42:0.2273,87:0.2273):0.1137,88:0.3400):0.1137,(((46:0.1855,91:0.1855):0.1855,((((58:0.0590,51:0.1214):0.0324,((((((90:0.0067,38:0.0076):0.0020,77:0.0140):0.0078,60:0.0220):0.0121,((1000:0.0083,31:0.0286):0.0085,1001:0.0154):0.0221):0.0120,82:0.0600):0.0120,((1002:0.0122,94:0.0295):0.0082,1003:0.0257):0.0272):0.0661):0.0171,((((57:0.0770,3:0.0817):0.0573,83:0.1400,52:0.1400):0.0860,69:0.2300):0.0860,(34:0.1034,67:0.2900):0.1034,48:0.1000):0.0233):0.0230,((49:0.1934,55:0.2617):0.0542,(((66:0.0739,39:0.0739):0.0739,((64:0.0398,84:0.0400,80:0.0400):0.0398,93:0.0796):0.0796):0.0049,(53:0.0694,85:0.0694):0.0694,61:0.1100):0.0101):0.0244,(86:0.1788,78:0.2000):0.0900,(81:0.1049,79:0.1750,33:0.2598):0.0404):0.2184):0.0653,43:0.4681):0.1239):0.1233,16:0.7825):0.1561,(((36:0.2000,37:0.2000):0.2000,(65:0.1994,4:0.2399):0.2600):0.2000,89:0.7826):0.1561):0.2000,(27:0.8000,18:0.8000):0.6000):0.2000,((((29:0.2500,1005:0.2500):0.2500,5:0.5000):0.2000,62:0.8000):0.1000,1004:0.9000):0.7000):0.1000,92:1.7000):0.3000,44:1.9000):0.3000);",
		 },
	},
]

############### anchor_map.conf ######################

[
	{
		TYPE => "anchorDBA",
		-dbname => "anchor_gen_test",
		-host => "$ENV{DBHOST}",
		-user => "$ENV{DBUSER}",
		-pass => "$ENV{DBPASS}",
		-port => 3306,
		-species => "Anchors",
	},
	{
		TYPE => "anchor_batch_size",
		anchor_batch_size => 100,
	},
	{
		TYPE => "anchor_sequences_mlssid",
		anchor_sequences_mlssid => 4, #method_link_species_set_id of the anchor sequences to be exonerated 
	},
	{
		TYPE => "modules",
		modules => {
			Exonerate_anchors => "Bio::EnsEMBL::Compara::Production::EPOanchors::ExonerateAnchors", #need this key/value pair
			post_exonerate_modules => [ #the order in the array is used to set up the analysis control rule
				{Remove_overlaps => "Bio::EnsEMBL::Compara::Production::EPOanchors::RemoveAnchorOverlaps"}, # are optional
				{TrimAnchorAlign => "Bio::EnsEMBL::Compara::Production::EPOanchors::TrimAnchorAlign"},
			],
		},
	},
	{
		TYPE => "target_genome_info",
		target_genome_info => {
			dump_dir => "$ENV{BLASTDIR}/compara_mammals/cshl_test",
			genome_db_ids => [3,31,38,39,57,60,61,64,90], # list of genomes to dump and map anchors to
		},
	},
	{
		TYPE => "program",
		program => "$ENV{EXONERATE}/`arch`/bin/exonerate",
	},
	{
		TYPE => "exonerate_options",
		exonerate_options => "{ bestn=>11, gappedextension=>\"no\", softmasktarget=>\"no\", percent=>75, showalignment=>\"no\", model=>\"affine:local\", }",
	},
	
]

