Scala is a combination of an object oriented framework and a functional programming language. For a good introduction see the free online book Programming Scala.
The following are extremely brief answers to frequently asked questions about Scala which often pop up when first viewing or editing QScripts. For more information on Scala there a multitude of resources available around the web including the Scala home page and the online Scala Doc.
var is a value you can later modify, while
val is similar to
final in Java.
Because the GATK and Queue are a mix of Scala and Java sometimes you'll run into problems when you need a Scala collection and instead a Java collection is returned.
MyQScript.scala:39: error: type mismatch; found : java.util.List[java.lang.String] required: scala.List[String] val wrapped: List[String] = TextFormattingUtils.wordWrap(text, width)
Use the implicit definitions in
JavaConversions to automatically convert the basic Java collections to and from Scala collections.
Scala has a very rich collections framework which you should take the time to enjoy. One of the first things you'll notice is that the default Scala collections are immutable, which means you should treat them as you would a String. When you want to 'modify' an immutable collection you need to capture the result of the operation, often assigning the result back to the original variable.
var str = "A" str + "B" println(str) // prints: A str += "C" println(str) // prints: AC var set = Set("A") set + "B" println(set) // prints: Set(A) set += "C" println(set) // prints: Set(A, C)
:+ operator for a single value.
var myList = List.empty[String] myList :+= "a" myList :+= "b" myList :+= "c"
++ for appending a list.
var myList = List.empty[String] myList ++= List("a", "b", "c")
var mySet = Set.empty[String] mySet += "a" mySet += "b" mySet += "c"
var myMap = Map.empty[String,Int] myMap += "a" -> 1 myMap += "b" -> 2 myMap += "c" -> 3
Option is a Scala generic type that can either be some generic value or
None. Queue often uses it to represent primitives that may be null.
var myNullableInt1: Option[Int] = Some(1) var myNullableInt2: Option[Int] = None
To quote from his slides:
Give me a variable name but - I don't care of what it is - and/or - don't want to pollute my namespace with it
This Java snippet:
String formatted = String.format("%s %i", myString, myInt);
In Scala would be:
val formatted = "%s %i".format(myString, myInt)
No. Currently Scala's
Enumeration class does not interact with the Java reflection API in a way that could be used for Queue command line arguments. You can use Java
enums if for example you are importing a Java based walker's
If/when we find a workaround for Queue we'll update this entry. In the meantime try using a String.