How to resolve the algorithm Bioinformatics/base count step by step in the Swift programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Bioinformatics/base count step by step in the Swift programming language

Table of Contents

Problem Statement

Given this string representing ordered DNA bases:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Bioinformatics/base count step by step in the Swift programming language

Source code in the swift programming language

import Foundation

let dna = """
          CGTAAAAAATTACAACGTCCTTTGGCTATCTCTTAAACTCCTGCTAAATG
          CTCGTGCTTTCCAATTATGTAAGCGTTCCGAGACGGGGTGGTCGATTCTG
          AGGACAAAGGTCAAGATGGAGCGCATCGAACGCAATAAGGATCATTTGAT
          GGGACGTTTCGTCGACAAAGTCTTGTTTCGAGAGTAACGGCTACCGTCTT
          CGATTCTGCTTATAACACTATGTTCTTATGAAATGGATGTTCTGAGTTGG
          TCAGTCCCAATGTGCGGGGTTTCTTTTAGTACGTCGGGAGTGGTATTATA
          TTTAATTTTTCTATATAGCGATCTGTATTTAAGCAATTCATTTAGGTTAT
          CGCCGCGATGCTCGGTTCGGACCGCCAAGCATCTGGCTCCACTGCTAGTG
          TCCTAAATTTGAATGGCAAACACAAATAAGATTTAGCAATTCGTGTAGAC
          GACCGGGGACTTGCATGATGGGAGCAGCTTTGTTAAACTACGAACGTAAT
          """

print("input:\n\(dna)\n")

let counts =
  dna.replacingOccurrences(of: "\n", with: "").reduce(into: [:], { $0[$1, default: 0] += 1 })

print("Counts: \(counts)")
print("Total: \(counts.values.reduce(0, +))")


  

You may also check:How to resolve the algorithm 99 bottles of beer step by step in the Klong programming language
You may also check:How to resolve the algorithm Sieve of Eratosthenes step by step in the SNOBOL4 programming language
You may also check:How to resolve the algorithm Van der Corput sequence step by step in the Swift programming language
You may also check:How to resolve the algorithm Evolutionary algorithm step by step in the Elena programming language
You may also check:How to resolve the algorithm Environment variables step by step in the Racket programming language