From b004c3ddb38f8e690a0895a51ad0c83ff57a01e7 Mon Sep 17 00:00:00 2001 From: Den Shabalin Date: Wed, 13 Nov 2013 15:33:33 +0100 Subject: deprecate Pair and Triple --- test/pending/shootout/fasta.scala | 64 ++++++++++++++--------------- test/pending/shootout/revcomp.scala-2.scala | 18 ++++---- test/pending/shootout/revcomp.scala-3.scala | 40 +++++++++--------- 3 files changed, 61 insertions(+), 61 deletions(-) (limited to 'test/pending/shootout') diff --git a/test/pending/shootout/fasta.scala b/test/pending/shootout/fasta.scala index 8b711083a5..ae99ba5936 100644 --- a/test/pending/shootout/fasta.scala +++ b/test/pending/shootout/fasta.scala @@ -5,7 +5,7 @@ import java.io._ -object fasta { +object fasta { def main(args: Array[String]) = { val ALU = @@ -18,31 +18,31 @@ object fasta { "AGCCTGGGCGACAGAGCGAGACTCCGTCTCAAAAA" val _IUB = Array( - Pair('a', 0.27), - Pair('c', 0.12), - Pair('g', 0.12), - Pair('t', 0.27), - - Pair('B', 0.02), - Pair('D', 0.02), - Pair('H', 0.02), - Pair('K', 0.02), - Pair('M', 0.02), - Pair('N', 0.02), - Pair('R', 0.02), - Pair('S', 0.02), - Pair('V', 0.02), - Pair('W', 0.02), - Pair('Y', 0.02) + ('a', 0.27), + ('c', 0.12), + ('g', 0.12), + ('t', 0.27), + + ('B', 0.02), + ('D', 0.02), + ('H', 0.02), + ('K', 0.02), + ('M', 0.02), + ('N', 0.02), + ('R', 0.02), + ('S', 0.02), + ('V', 0.02), + ('W', 0.02), + ('Y', 0.02) ) val IUB = makeCumulative(_IUB) val _HomoSapiens = Array( - Pair('a', 0.3029549426680), - Pair('c', 0.1979883004921), - Pair('g', 0.1975473066391), - Pair('t', 0.3015094502008) + ('a', 0.3029549426680), + ('c', 0.1979883004921), + ('g', 0.1975473066391), + ('t', 0.3015094502008) ) val HomoSapiens = makeCumulative(_HomoSapiens) @@ -61,15 +61,15 @@ object fasta { s.writeRandomSequence(HomoSapiens,n*5) s.close - } + } - def makeCumulative(a: Array[Pair[Char,Double]]) = { + def makeCumulative(a: Array[Tuple2[Char,Double]]) = { var cp = 0.0 a map (frequency => - frequency match { - case Pair(code,percent) => - cp = cp + percent; new Frequency(code.toByte,cp) - } + frequency match { + case (code,percent) => + cp = cp + percent; new Frequency(code.toByte,cp) + } ) } @@ -79,7 +79,7 @@ object fasta { // We could use instances of Pair or Tuple2 but specific labels // make the code more readable than index numbers -class Frequency(_code: Byte, _percent: Double){ +class Frequency(_code: Byte, _percent: Double){ var code = _code; var percent = _percent; } @@ -101,13 +101,13 @@ class FastaOutputStream(out: OutputStream) extends BufferedOutputStream(out) { val m = if (n < LineLength) n else LineLength var i = 0 - while (i < m){ + while (i < m){ if (k == kn) k = 0 val b = alu(k) if (count < buf.length){ buf(count) = b; count = count + 1 } else { write(b) } // flush buffer k = k+1 - i = i+1 + i = i+1 } write(nl) @@ -122,11 +122,11 @@ class FastaOutputStream(out: OutputStream) extends BufferedOutputStream(out) { val m = if (n < LineLength) n else LineLength var i = 0 - while (i < m){ + while (i < m){ val b = selectRandom(distribution) if (count < buf.length){ buf(count) = b; count = count + 1 } else { write(b) } // flush buffer - i = i+1 + i = i+1 } if (count < buf.length){ buf(count) = nl; count = count + 1 } diff --git a/test/pending/shootout/revcomp.scala-2.scala b/test/pending/shootout/revcomp.scala-2.scala index 92260ad021..03fb25af1b 100644 --- a/test/pending/shootout/revcomp.scala-2.scala +++ b/test/pending/shootout/revcomp.scala-2.scala @@ -6,7 +6,7 @@ import java.io._ import scala.collection.mutable.Stack -object revcomp { +object revcomp { val IUB = IUBCodeComplements @@ -16,7 +16,7 @@ object revcomp { val a: Array[Byte] = new Array( 'z'.toByte ) for (indexValue <- code zip comp) - indexValue match { case Pair(i,v) => a(i) = v } + indexValue match { case (i,v) => a(i) = v } a } @@ -49,18 +49,18 @@ object revcomp { if (desc.length > 0) complementReverseWrite(desc, lines, w) w.close - } + } - def complementReverseWrite(desc: String, lines: LineStack, + def complementReverseWrite(desc: String, lines: LineStack, w: BufferedOutputStream) = { def inplaceComplementReverse(b: Array[Byte]) = { - var i = 0 + var i = 0 var j = b.length - 1 while (i < j){ - val swap = b(i) - b(i) = IUB( b(j) ) + val swap = b(i) + b(i) = IUB( b(j) ) b(j) = IUB( swap ) i = i + 1 j = j - 1 @@ -79,11 +79,11 @@ object revcomp { while (!lines.isEmpty) { val line = lines.pop inplaceComplementReverse(line) - + if (isSplitLine){ if (isFirstLine){ w.write(line); isFirstLine = false } else { w.write(line,0,n-k); w.write(nl); w.write(line,n-k,k) } - } + } else { w.write(line); w.write(nl) } } if (isSplitLine && !isFirstLine) w.write(nl) diff --git a/test/pending/shootout/revcomp.scala-3.scala b/test/pending/shootout/revcomp.scala-3.scala index ae12f0499b..39a0409127 100644 --- a/test/pending/shootout/revcomp.scala-3.scala +++ b/test/pending/shootout/revcomp.scala-3.scala @@ -6,7 +6,7 @@ import java.io._ import scala.collection.mutable.Stack -object revcomp { +object revcomp { def main(args: Array[String]) = { val out = new FastaOutputStream(System.out) val in = new FastaInputStream(System.in) @@ -17,12 +17,12 @@ object revcomp { in.close out.close - } + } } trait FastaByteStream { - val nl = '\n'.toByte + val nl = '\n'.toByte type Line = Array[Byte] type LineStack = Stack[Line] @@ -31,13 +31,13 @@ trait FastaByteStream { // extend the Java BufferedInputStream class -final class FastaInputStream(in: InputStream) +final class FastaInputStream(in: InputStream) extends BufferedInputStream(in) with FastaByteStream { val gt = '>'.toByte val sc = ';'.toByte - def readSequenceStack(): Pair[Line,LineStack] = { + def readSequenceStack(): Tuple2[Line,LineStack] = { var header: Line = null val lines: LineStack = new Stack @@ -49,14 +49,14 @@ final class FastaInputStream(in: InputStream) header = line } else { pos = pos - line.length - 1 // reposition to start of line - return Pair(header,lines) + return (header,lines) } } else { if (c != sc) lines push line // ';' } line = readLine() } - return Pair(header,lines) + return (header,lines) } def readLine() = { @@ -65,7 +65,7 @@ final class FastaInputStream(in: InputStream) else { mark(128) // mark the start of the line if (count == 0) read() // fill buffer - + var i = markpos while (i < count && buf(i) != nl) i = i + 1 @@ -74,11 +74,11 @@ final class FastaInputStream(in: InputStream) while (i < count && buf(i) != nl) i = i + 1 } - if (i < count){ + if (i < count){ bytes = new Array(i - markpos) System.arraycopy(buf, markpos, bytes, 0, i - markpos); pos = i+1 - } + } } bytes } @@ -87,7 +87,7 @@ final class FastaInputStream(in: InputStream) // extend the Java BufferedOutputStream class -final class FastaOutputStream(in: OutputStream) +final class FastaOutputStream(in: OutputStream) extends BufferedOutputStream(in) with FastaByteStream { private val IUB = IUBCodeComplements @@ -98,19 +98,19 @@ final class FastaOutputStream(in: OutputStream) val iub: Array[Byte] = new Array( 'z'.toByte ) for (indexValue <- code zip comp) - indexValue match { case Pair(i,v) => iub(i) = v } + indexValue match { case (i,v) => iub(i) = v } iub } - def writeReverseComplement(sequence: Pair[Line,LineStack]) = { + def writeReverseComplement(sequence: Tuple2[Line,LineStack]) = { def inplaceComplementReverse(b: Array[Byte]) = { - var i = 0 + var i = 0 var j = b.length - 1 while (i < j){ - val swap = b(i) - b(i) = IUB( b(j) ) + val swap = b(i) + b(i) = IUB( b(j) ) b(j) = IUB( swap ) i = i + 1 j = j - 1 @@ -119,7 +119,7 @@ final class FastaOutputStream(in: OutputStream) } sequence match { - case Pair(header,lines) => { + case (header,lines) => { write(header); write(nl) @@ -131,11 +131,11 @@ final class FastaOutputStream(in: OutputStream) while (!lines.isEmpty) { val line = lines.pop inplaceComplementReverse(line) - + if (isSplitLine){ - if (isFirstLine){ write(line); isFirstLine = false } + if (isFirstLine){ write(line); isFirstLine = false } else { write(line,0,LineLength-k); write(nl); write(line,LineLength-k,k) } - } + } else { write(line); write(nl) } } -- cgit v1.2.3