Skip to content
Snippets Groups Projects
Commit 41a5ea2a authored by Wai Yi Leung's avatar Wai Yi Leung
Browse files

Merge branch 'feature-sample_selector' into 'develop'

Added sample selector when fasta file can't be found in the config

Fixes #290 

See merge request !343
parents 58d986d3 bb12d6db
Branches
Tags
No related merge requests found
...@@ -19,8 +19,8 @@ import java.io.File ...@@ -19,8 +19,8 @@ import java.io.File
import htsjdk.samtools.reference.IndexedFastaSequenceFile import htsjdk.samtools.reference.IndexedFastaSequenceFile
import nl.lumc.sasc.biopet.core.summary.{ SummaryQScript, Summarizable } import nl.lumc.sasc.biopet.core.summary.{ SummaryQScript, Summarizable }
import nl.lumc.sasc.biopet.utils.Logging import nl.lumc.sasc.biopet.utils.{ ConfigUtils, Logging }
import nl.lumc.sasc.biopet.utils.config.Configurable import nl.lumc.sasc.biopet.utils.config.{ Config, Configurable }
import scala.collection.JavaConversions._ import scala.collection.JavaConversions._
...@@ -69,16 +69,40 @@ trait Reference extends Configurable { ...@@ -69,16 +69,40 @@ trait Reference extends Configurable {
/** Returns the fasta file */ /** Returns the fasta file */
def referenceFasta(): File = { def referenceFasta(): File = {
val file: File = config("reference_fasta") val file: File = config("reference_fasta")
checkFasta(file) if (config.contains("reference_fasta")) {
checkFasta(file)
val dict = new File(file.getAbsolutePath.stripSuffix(".fa").stripSuffix(".fasta").stripSuffix(".fna") + ".dict")
val fai = new File(file.getAbsolutePath + ".fai") val dict = new File(file.getAbsolutePath.stripSuffix(".fa").stripSuffix(".fasta").stripSuffix(".fna") + ".dict")
val fai = new File(file.getAbsolutePath + ".fai")
this match {
case c: BiopetCommandLineFunction => c.deps :::= dict :: fai :: Nil this match {
case _ => case c: BiopetCommandLineFunction => c.deps :::= dict :: fai :: Nil
case _ =>
}
} else {
val defaults = ConfigUtils.mergeMaps(this.defaults, this.internalDefaults)
def getReferences(map: Map[String, Any]): Set[(String, String)] = (for (
(species, species_content: Map[String, Any]) <- map.getOrElse("references", Map[String, Any]()).asInstanceOf[Map[String, Any]].toList;
(reference_name, _) <- species_content.toList
) yield (species, reference_name)).toSet
val references = getReferences(defaults) ++ getReferences(Config.global.map)
if (!references.contains((referenceSpecies, referenceName))) {
val buffer = new StringBuilder()
if (references.exists(_._1 == referenceSpecies)) {
buffer.append(s"Reference: '$referenceName' does not exist in config for species: '$referenceSpecies'")
buffer.append(s"\nRefrences found for species '$referenceSpecies':")
references.filter(_._1 == referenceSpecies).foreach(x => buffer.append("\n - " + x._2))
} else {
buffer.append(s"Species: '$referenceSpecies' does not exist in config")
if (references.nonEmpty) buffer.append("\n References available in config (species -> reference_name):")
else buffer.append("\n No references found in user or global config")
references.toList.sorted.foreach(x => buffer.append(s"\n - ${x._1} -> ${x._2}"))
}
Logging.addError(buffer.toString)
}
} }
file file
} }
...@@ -117,6 +141,7 @@ object Reference { ...@@ -117,6 +141,7 @@ object Reference {
/** /**
* Raise an exception when given fasta file has no fai file * Raise an exception when given fasta file has no fai file
*
* @param fastaFile Fasta file * @param fastaFile Fasta file
*/ */
def requireFai(fastaFile: File): Unit = { def requireFai(fastaFile: File): Unit = {
...@@ -132,6 +157,7 @@ object Reference { ...@@ -132,6 +157,7 @@ object Reference {
/** /**
* Raise an exception when given fasta file has no dict file * Raise an exception when given fasta file has no dict file
*
* @param fastaFile Fasta file * @param fastaFile Fasta file
*/ */
def requireDict(fastaFile: File): Unit = { def requireDict(fastaFile: File): Unit = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment