#!/usr/bin/env bds

#-------------------------------------------------------------------------------
#
# Download genome data from ENSEMBL
#
#-------------------------------------------------------------------------------

void downloadEnsemblGenome(string genome, string species) {
	if( species.isEmpty() ) error "Missing parameter 'downloadEnsemblSpecies'?"
	dg := new DownloadEnsembl(genome, species)
	dg.download()
}


class DownloadEnsembl extends DownloadGenome {
	string species

	void DownloadEnsembl(string genome, string species) {
		super.DownloadGenome(genome)
		this.species = species

		speciesLower := species.toLower()
		downloadDir = "$dirDownload/$className/$version/$genome"
		urlBase := "http://ftp.ensembl.org/pub/release-$version"

		versionNum := version.parseInt()
		if( versionNum > 75 ) {
			cdsUrl = "$urlBase/fasta/$speciesLower/cds/$species\.$genomeNoVer\.cds.all.fa.gz"
			fastaUrl = "$urlBase/fasta/$speciesLower/dna/$species\.$genomeNoVer\.dna.toplevel.fa.gz"
			genesUrl = "$urlBase/gtf/$speciesLower/$species\.$genome\.gtf.gz"
			protUrl = "$urlBase/fasta/$speciesLower/pep/$species\.$genomeNoVer\.pep.all.fa.gz"
		} else {
			cdsUrl = "$urlBase/fasta/$speciesLower/cds/$species\.$genome\.cds.all.fa.gz"
			fastaUrl = "$urlBase/fasta/$speciesLower/dna/$species\.$genome\.dna.toplevel.fa.gz"
			genesUrl = "$urlBase/gtf/$speciesLower/$species\.$genome\.gtf.gz"
			protUrl = "$urlBase/fasta/$speciesLower/pep/$species\.$genome\.pep.all.fa.gz"
		}
	}
}

