consolidated go and scala repos into this repo as well

This commit is contained in:
Fizzizist
2025-01-04 16:03:27 -05:00
parent af2ce045ec
commit 8d4cc2b83c
20 changed files with 535 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
import sbt._
object Dependencies {
lazy val scalaTest = "org.scalatest" %% "scalatest" % "3.0.5"
}

View File

@@ -0,0 +1,14 @@
package dna
import scala.io.Source
object DNA {
def main(args: Array[String]) = {
val filename = "DNA.txt"
val dnaStr = Source.fromFile(filename).getLines.mkString
val acgt = Array(0, 0, 0, 0)
val acgtMap = Map('A' -> 0, 'C' -> 1, 'G' -> 2, 'T' -> 3)
for (c <- dnaStr) acgt(acgtMap(c)) += 1
println("%d %d %d %d".format(acgt(0), acgt(1), acgt(2), acgt(3)))
}
}

View File

@@ -0,0 +1,21 @@
package fib
import scala.io.Source
object FIB {
def main(args: Array[String]) = {
val n = args(0).toInt
val k = args(1).toInt
var b = BigInt(0)
var a = BigInt(1)
var newA = BigInt(0)
var i = 0
for (i <- 2 until n) {
a += newA
newA = b
b = a*k
}
val res = a + b + newA
println(res.toString)
}
}

View File

@@ -0,0 +1,48 @@
package gc
import scala.io.Source
import java.io._
class GCCalculator() {
var dnaStr = ""
var topContent = 0.0
var topDNA = ""
var currentDNA = ""
def checkCurrDNA() {
val gcCheck = (c: Char) => (c == 'G' || c == 'C')
val gcContent = dnaStr.filter(gcCheck).length
val contentPerc = (gcContent.toFloat / dnaStr.length.toFloat) * 100.0
if (contentPerc > topContent) {
topContent = contentPerc
topDNA = currentDNA
}
}
def printTopGC() {
val filename = "GC.txt"
for (line <- Source.fromFile(filename).getLines) {
if (line.startsWith(">")) {
if (dnaStr.length > 0) {
checkCurrDNA
}
currentDNA = line
dnaStr = ""
} else {
dnaStr += line
}
}
checkCurrDNA
println(topDNA)
println(f"$topContent%.6f")
}
}
object GC {
def main(args: Array[String]) = {
val gcCalc = new GCCalculator
gcCalc.printTopGC
}
}

View File

@@ -0,0 +1,18 @@
package hamm
import scala.io.Source
import java.io._
object HAMM {
def main(args: Array[String]) = {
val filename = "HAMM.txt"
val dna = Source.fromFile(filename).getLines.toList
var count = 0
for ((i, j) <- (dna(0), dna(1)).zipped) {
if (i != j) {
count += 1
}
}
println(count)
}
}

View File

@@ -0,0 +1,24 @@
package rna
import scala.io.Source
object IPRB {
def main(args: Array[String]) = {
val popul = args.map(_.toDouble)
// algorithm just assumes the following inputs
// popul(0) = homozygous dominant
// popul(1) = heterozygous
// popul(2) = homozygous recessive
val total = popul.sum
// case of both homozygous recessive
var probabTotal = (popul(2) / total) * ((popul(2) - 1) / (total - 1))
// case of heterozygous and homozygous recessive mix
probabTotal += ((popul(2) / total) * (popul(1) / (total - 1))) * 0.5
// case of homozygous recessive and heterozygous mix
probabTotal += ((popul(1) / total) * (popul(2) / (total - 1))) * 0.5
// case of both heterozygous
probabTotal += ((popul(1) / total) * ((popul(1) - 1) / (total - 1))) * 0.25
probabTotal = 1 - probabTotal
println(f"$probabTotal%.5f")
}
}

View File

@@ -0,0 +1,84 @@
package prot
import scala.io.Source
import java.io._
object PROT {
def main(args: Array[String]) = {
val filename = "PROT.txt"
val rnaStr = Source.fromFile(filename).getLines.mkString
val transMap = Map(
"UUU" -> "F",
"CUU" -> "L",
"AUU" -> "I",
"GUU" -> "V",
"UUC" -> "F",
"CUC" -> "L",
"AUC" -> "I",
"GUC" -> "V",
"UUA" -> "L",
"CUA" -> "L",
"AUA" -> "I",
"GUA" -> "V",
"UUG" -> "L",
"CUG" -> "L",
"AUG" -> "M",
"GUG" -> "V",
"UCU" -> "S",
"CCU" -> "P",
"ACU" -> "T",
"GCU" -> "A",
"UCC" -> "S",
"CCC" -> "P",
"ACC" -> "T",
"GCC" -> "A",
"UCA" -> "S",
"CCA" -> "P",
"ACA" -> "T",
"GCA" -> "A",
"UCG" -> "S",
"CCG" -> "P",
"ACG" -> "T",
"GCG" -> "A",
"UAU" -> "Y",
"CAU" -> "H",
"AAU" -> "N",
"GAU" -> "D",
"UAC" -> "Y",
"CAC" -> "H",
"AAC" -> "N",
"GAC" -> "D",
"UAA" -> "Stop",
"CAA" -> "Q",
"AAA" -> "K",
"GAA" -> "E",
"UAG" -> "Stop",
"CAG" -> "Q",
"AAG" -> "K",
"GAG" -> "E",
"UGU" -> "C",
"CGU" -> "R",
"AGU" -> "S",
"GGU" -> "G",
"UGC" -> "C",
"CGC" -> "R",
"AGC" -> "S",
"GGC" -> "G",
"UGA" -> "Stop",
"CGA" -> "R",
"AGA" -> "R",
"GGA" -> "G",
"UGG" -> "W",
"CGG" -> "R",
"AGG" -> "R",
"GGG" -> "G",
)
val rnaSegs = rnaStr.grouped(3).toList
var protStr = ""
rnaSegs.iterator.takeWhile(transMap(_) != "Stop").foreach(protStr += transMap(_))
println(protStr)
val pw = new PrintWriter(new File("PROTOut.txt"))
pw.write(protStr)
pw.close()
}
}

View File

@@ -0,0 +1,16 @@
package rna
import scala.io.Source
import java.io._
object RNA {
def main(args: Array[String]) = {
val filename = "REVC.txt"
val dnaStr = Source.fromFile(filename).getLines.mkString
val compMap = Map('A' -> 'T', 'T' -> 'A', 'C' -> 'G', 'G' -> 'C')
val comp = dnaStr.reverse.map(compMap(_))
val pw = new PrintWriter(new File("REVCOut.txt"))
pw.write(comp)
pw.close()
}
}

View File

@@ -0,0 +1,15 @@
package rna
import scala.io.Source
import java.io._
object RNA {
def main(args: Array[String]) = {
val filename = "RNA.txt"
val dnaStr = Source.fromFile(filename).getLines.mkString
val rnaStr = dnaStr.replace('T', 'U')
val pw = new PrintWriter(new File("RNAOut.txt"))
pw.write(rnaStr)
pw.close()
}
}

View File

@@ -0,0 +1,9 @@
package example
import org.scalatest._
class HelloSpec extends FlatSpec with Matchers {
"The Hello object" should "say hello" in {
Hello.greeting shouldEqual "hello"
}
}