Bioinformatics/base count: Difference between revisions

Content added Content deleted
(→‎{{header|REXX}}: Refurbished (better variable names and no Upper instruction))
Line 1,783: Line 1,783:
</pre>
</pre>
=={{header|Kotlin}}==
=={{header|Kotlin}}==
For the first part, we can leverage the built-in <code>String.chunked</code> to transform a <code>String</code> into a <code>List&lt;String&gt;</code>, where each <code>String</code> has a defined chunk size. <code>Iterable.withIndex</code> allows you to loop over an <code>iterable</code>, while keeping track of the iteration index.
For the first part, we can leverage the built-in <code>String.chunked</code> to transform a <code>String</code> into a <code>List&lt;String&gt;</code>, where each <code>String</code> has a defined chunk size.

For counting the bases, we use <code>groupingBy</code>, which is a versatile tool for aggregating objects based on a key-function. In this case, the key function is the identity function (<code>it</code>), and the aggregation function is the counting function: <code>eachCount</code>.
For counting the bases, we use <code>groupingBy</code>, which is a versatile tool for aggregating objects based on a key-function. In this case, the key function is the identity function (<code>it</code>), and the aggregation function is the counting function: <code>eachCount</code>.


Finally, the total count is simply the input’s length.
Finally, the total count is simply the input’s length.


<syntaxhighlight lang="kotlin">fun printSequence(sequence: String, width: Int = 50) {
<syntaxhighlight lang="kotlin">

fun <K, V> printWithLabel(k: K, v: V) {
fun printSequence(sequence: String, width: Int = 50) {
val label = k.toString().padStart(5)

println("$label: $v")
fun printWithLabel(label: Any, data: Any) =
}
label.toString().padStart(5).also { println("$it: $data") }


println("SEQUENCE:")
println("SEQUENCE:")
sequence.chunked(width).withIndex().forEach { (i, line) ->
sequence.chunked(width).forEachIndexed() { i, chunk ->
printWithLabel(i*width + line.length, line)
printWithLabel(i * width + chunk.length, chunk)
}
}

println("BASE:")
println("BASE:")
sequence.groupingBy { it }.eachCount().forEach { (k, v) ->
sequence.groupingBy { it }.eachCount().forEach { (k, v) ->
Line 1,806: Line 1,807:
}
}


const val BASE_SEQUENCE =
const val BASE_SEQUENCE = "CGTAAAAAATTACAACGTCCTTTGGCTATCTCTTAAACTCCTGCTAAATGCTCGTGCTTTCCAATTATGTAAGCGTTCCGAGACGGGGTGGTCGATTCTGAGGACAAAGGTCAAGATGGAGCGCATCGAACGCAATAAGGATCATTTGATGGGACGTTTCGTCGACAAAGTCTTGTTTCGAGAGTAACGGCTACCGTCTTCGATTCTGCTTATAACACTATGTTCTTATGAAATGGATGTTCTGAGTTGGTCAGTCCCAATGTGCGGGGTTTCTTTTAGTACGTCGGGAGTGGTATTATATTTAATTTTTCTATATAGCGATCTGTATTTAAGCAATTCATTTAGGTTATCGCCGCGATGCTCGGTTCGGACCGCCAAGCATCTGGCTCCACTGCTAGTGTCCTAAATTTGAATGGCAAACACAAATAAGATTTAGCAATTCGTGTAGACGACCGGGGACTTGCATGATGGGAGCAGCTTTGTTAAACTACGAACGTAAT"
"CGTAAAAAATTACAACGTCCTTTGGCTATCTCTTAAACTCCTGCTAAATGCTCGTGCTTTCCAATTATGTAAGCGTTCCGAGACGGGGTGGTCGATTCTGAGGACAAAGGTCAAGATGGAGCGCATCGAACGCAATAAGGATCATTTGATGGGACGTTTCGTCGACAAAGTCTTGTTTCGAGAGTAACGGCTACCGTCTTCGATTCTGCTTATAACACTATGTTCTTATGAAATGGATGTTCTGAGTTGGTCAGTCCCAATGTGCGGGGTTTCTTTTAGTACGTCGGGAGTGGTATTATATTTAATTTTTCTATATAGCGATCTGTATTTAAGCAATTCATTTAGGTTATCGCCGCGATGCTCGGTTCGGACCGCCAAGCATCTGGCTCCACTGCTAGTGTCCTAAATTTGAATGGCAAACACAAATAAGATTTAGCAATTCGTGTAGACGACCGGGGACTTGCATGATGGGAGCAGCTTTGTTAAACTACGAACGTAAT"


fun main() {
fun main() = printSequence(BASE_SEQUENCE)

printSequence(BASE_SEQUENCE)
}</syntaxhighlight>
</syntaxhighlight>


{{out}}
{{out}}
Line 1,832: Line 1,834:
TOTALS: 500
TOTALS: 500
</pre>
</pre>

=={{header|Lambdatalk}}==
=={{header|Lambdatalk}}==
<syntaxhighlight lang="scheme">
<syntaxhighlight lang="scheme">