Bioinformatics/base count: Difference between revisions
Content added Content deleted
Walterpachl (talk | contribs) (→{{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<String></code>, where each <code>String</code> has a defined chunk size. |
For the first part, we can leverage the built-in <code>String.chunked</code> to transform a <code>String</code> into a <code>List<String></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"> |
<syntaxhighlight lang="kotlin"> |
||
⚫ | |||
fun printSequence(sequence: String, width: Int = 50) { |
|||
⚫ | |||
println("$label: $v") |
|||
⚫ | |||
} |
|||
⚫ | |||
println("SEQUENCE:") |
println("SEQUENCE:") |
||
sequence.chunked(width). |
sequence.chunked(width).forEachIndexed() { i, chunk -> |
||
printWithLabel(i*width + |
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 = |
|||
"CGTAAAAAATTACAACGTCCTTTGGCTATCTCTTAAACTCCTGCTAAATGCTCGTGCTTTCCAATTATGTAAGCGTTCCGAGACGGGGTGGTCGATTCTGAGGACAAAGGTCAAGATGGAGCGCATCGAACGCAATAAGGATCATTTGATGGGACGTTTCGTCGACAAAGTCTTGTTTCGAGAGTAACGGCTACCGTCTTCGATTCTGCTTATAACACTATGTTCTTATGAAATGGATGTTCTGAGTTGGTCAGTCCCAATGTGCGGGGTTTCTTTTAGTACGTCGGGAGTGGTATTATATTTAATTTTTCTATATAGCGATCTGTATTTAAGCAATTCATTTAGGTTATCGCCGCGATGCTCGGTTCGGACCGCCAAGCATCTGGCTCCACTGCTAGTGTCCTAAATTTGAATGGCAAACACAAATAAGATTTAGCAATTCGTGTAGACGACCGGGGACTTGCATGATGGGAGCAGCTTTGTTAAACTACGAACGTAAT" |
|||
fun main() |
fun main() = printSequence(BASE_SEQUENCE) |
||
printSequence(BASE_SEQUENCE) |
|||
</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"> |