Enumerated data type arguments

ynnusynnus everywherePosts: 4Member

I am working on a Queue script that uses the selectVariants walker. Two of the arguments that I am trying to use both use an enumerated type: restrictAllelesTo and selectTypeToInclude. I have tried passing these as strings however I get java type mismatch errors. What is the simplest way to pass these parameters to the selectVariant walker in the qscript?

Best Answer


  • Geraldine_VdAuweraGeraldine_VdAuwera Posts: 9,959Administrator, Dev admin

    Hi there,

    Have a look at the presentations from our recent Queue workshop, I think we give some examples of how to pass the different types in there:


    Geraldine Van der Auwera, PhD

  • ynnusynnus everywherePosts: 4Member

    Maybe it's my lack of understanding scala but I still can't pass an enumerated data type. The workshop shows this as an example:

    @Argument(doc=”gender identity") // some object defined elsewhere 
     var gender: Gender = Gender.UNKNOWN

    my code uses this
    @Argument(doc="Select only variants of a particular allelicity.", shortName="restrictAllelesTo", required=false)
      var rAT: restrictAllelesTo = restrictAllelesTo.BIALLELIC

    This still errors with "not found: type restrictAllelesTo".

    I've even tried defining the object itself:

    object restrictAllelesTo extends Enumeration {
        type restrictAllelesTo = Value
        val BIALLELIC, ALLELIC, BOTH = Value
      import restrictAllelesTo._

    However, this then errors with "Can't process command-line arguments of type: scala.Enumeration$Value"
  • Geraldine_VdAuweraGeraldine_VdAuwera Posts: 9,959Administrator, Dev admin

    I believe the correct way to define your object should look like this (from a real object defined in the Queue codebase):

    object RunnerStatus extends Enumeration {
         val PENDING = Value("pending")
         val RUNNING = Value("running")
         val FAILED = Value("failed")
         val DONE = Value("done")
         val SKIPPED = Value("skipped")

    Geraldine Van der Auwera, PhD

  • Geraldine_VdAuweraGeraldine_VdAuwera Posts: 9,959Administrator, Dev admin

    @pdexheimer's suggestion should do the trick. Also, I haven't tested it at the moment, but java enums may be parseable by Sting (including Queue) as @Argument variable types, eliminating the need for string-to-enum mapping. FYI- walkers exclusively use Java enums, including the NumberAlleleRestriction shown here.

    Geraldine Van der Auwera, PhD

  • pdexheimerpdexheimer Posts: 533Member, Dev ✭✭✭✭

    Ah, I had it backwards - I remembered that one of the enumerated types didn't work properly, and thought it was Java. But I was thinking of the 11th question in the Scala FAQ, which says that Scala enums can't be used as arguments

  • ynnusynnus everywherePosts: 4Member

    Thanks a bunch guys, I think I'll be able to get it working from here.

  • DavidRiesDavidRies Posts: 11Member


    I have a similar Problem, but I want to select for SNPs.
    Although org.broadinstitute.variant.variantcontext.VariantContext.Type is accessible, there doesn't seem to be a type SNP.

    Running the following SelectVariants walker:

    val selectVars = new SelectVariants with UnifiedGenotyperArguments    
        selectVars.variant = "Variations.vcf"
        selectVars.select = Seq("QD < 2.0 || FS > 60.0 || MQ < 40.0 || HaplotypeScore > 13.0 || MappingQualityRankSum < -12.5 || ReadPosRankSum < -8.0")
        selectVars.selectTypeToInclude = List[org.broadinstitute.variant.variantcontext.VariantContext.Type.SNP]
        selectVars.restrictAllelesTo = org.broadinstitute.sting.gatk.walkers.variantutils.SelectVariants.NumberAlleleRestriction.BIALLELIC
        selectVars.excludeNonVariants = true
        selectVars.out = "biallelic_true_SNPS.qual.filtered.vcf"

    gives me the error message:

    INFO 17:58:31,089 QScriptManager - Compiling 1 QScript
    ERROR 17:58:34,029 QScriptManager - SelectVariants.scala:66: type SNP is not a member of object org.broadinstitute.variant.variantcontext.VariantContext.Type
    ERROR 17:58:34,037 QScriptManager - selectVars.selectTypeToInclude = List[org.broadinstitute.variant.variantcontext.VariantContext.Type.SNP]
    ERROR 17:58:34,038 QScriptManager - ^
    ERROR 17:58:34,137 QScriptManager - one error found

    ERROR ------------------------------------------------------------------------------------------
    ERROR stack trace

    org.broadinstitute.sting.queue.QException: Compile of ./SelectVariants.scala failed with 1 error
    at org.broadinstitute.sting.queue.QScriptManager.loadScripts(QScriptManager.scala:71)
    at org.broadinstitute.sting.queue.QCommandLine.org$broadinstitute$sting$queue$QCommandLine$$qScriptPluginManager(QCommandLine.scala:95)
    at org.broadinstitute.sting.queue.QCommandLine.getArgumentSources(QCommandLine.scala:227)
    at org.broadinstitute.sting.commandline.CommandLineProgram.start(CommandLineProgram.java:202)
    at org.broadinstitute.sting.commandline.CommandLineProgram.start(CommandLineProgram.java:152)
    at org.broadinstitute.sting.queue.QCommandLine$.main(QCommandLine.scala:62)
    at org.broadinstitute.sting.queue.QCommandLine.main(QCommandLine.scala)

    Other than NumberAlleleRestriction, I don't see a way to set the List<VariantContext.Type> directly.

    Help much appreciated,


  • ynnusynnus everywherePosts: 4Member

    Here is a snippet from my code that I used to get it working, I wanted to be able to change the type selection on the fly so I had to define a function to convert the list of inputed strings into a list of "Type".

    import org.broadinstitute.variant.variantcontext.VariantContext.Type
    //define a function that takes a list of strings as input and 
    //returns a list of enumerated data values of type "Type"
    def getTypeSelect : List[Type] = {
        //create enumerated list of type "Type"
        var LtypeSelect: List[Type] = Nil
        //if list sTTI contains a value, append that value to the enumerated list
            LtypeSelect :+ Type.INDEL
        LtypeSelect :+ Type.SNP
        LtypeSelect :+ Type.MIXED
        LtypeSelect :+ Type.MNP
        LtypeSelect :+ Type.SYMBOLIC
        LtypeSelect :+ Type.NO_VARIATION
        return LtypeSelect
    //Apply the previously defined function to select variants parameter
    selectVars.selectTypeToInclude = getTypeSelect

    Hopefully this helps.

  • pdexheimerpdexheimer Posts: 533Member, Dev ✭✭✭✭

    @DavidRies -

    SNP is definitely one of the members of VariantContext.Type, so I think the error you're getting from the Scala compiler is misleading. Is it possible that you're not even seeing the org.broadinstitute.variant packages? They've moved out of the main GATK repository and into a separate "variant" jar, which I believe is hosted and built by the Picard team. It's possible - especially if you built Queue yourself - that you somehow lost that dependency.

  • DavidRiesDavidRies Posts: 11Member

    @ynnus -

    That did the trick. I suppose my mistake was, that I tried to directly assign the type to selectVars.selectTypeToInclude,
    rather than first creating the empty list, adding the types and then assigning it. I now do it directly like this:

    var LtypeSelect2: List[Type] = Nil
    LtypeSelect2 :+ Type.INDEL

    val selectIndels = new SelectVariants with VariantFiltrationArguments
    selectIndels.variant = variantFile
    selectIndels.select = Seq("QD < 2.0 || FS > 60.0 || MQ < 40.0 || HaplotypeScore > 13.0 || MappingQualityRankSum < -12.5 || ReadPosRankSum < -8.0")
    selectIndels.selectTypeToInclude = LtypeSelect2
    selectVars.restrictAllelesTo = org.broadinstitute.sting.gatk.walkers.variantutils.SelectVariants.NumberAlleleRestriction.BIALLELIC
    selectIndels.out = "biallelic_true_INDELS.qual.filtered.vcf"

    Thanks for your help!


  • DavidRiesDavidRies Posts: 11Member

    I don't know how to edit my previous post, so:

    It has to be
    LtypeSelect2 :+= Type.INDEL

Sign In or Register to comment.