Anonymous user
Bioinformatics/Sequence mutation: Difference between revisions
Changing the representation of a DNA sequence from a sequence of Base to a string, as requested. Updated procedures to work with a string rather than a sequence.
(Changing the representation of a DNA sequence from a sequence of Base to a string, as requested. Updated procedures to work with a string rather than a sequence.) |
|||
Line 1,419:
type
# Enumeration type for bases.
Base {.pure.} = enum A, C, G, T, Other = "other"
# Sequence of bases.
DnaSequence =
# Kind of mutation.
Mutation = enum mutSwap, mutDelete, mutInsert
const MaxBaseVal = ord(Base.high) - 1 # Maximum base value.
#---------------------------------------------------------------------------------------------------
template toChar(base: Base): char = ($base)[0]
#---------------------------------------------------------------------------------------------------
Line 1,434 ⟶ 1,440:
## Create a DNA sequence of given length.
result =
for _ in 1..length:
result.add($Base(rand(
#---------------------------------------------------------------------------------------------------
Line 1,455 ⟶ 1,461:
let newBase = Base(rand(ord(Base.Other) - 1))
echo fmt"Changing base at position {idx + 1} from {dnaSeq[idx]} to {newBase}"
dnaSeq[idx] = newBase.toChar
of mutDelete:
echo fmt"Deleting base {dnaSeq[idx]} at position {idx + 1}"
dnaSeq.delete(idx, idx)
of mutInsert:
let newBase = Base(rand(ord(Base.Other) - 1))
echo fmt"Inserting base {newBase} at position {idx + 1}"
dnaSeq.insert($newBase, idx)
#---------------------------------------------------------------------------------------------------
Line 1,472 ⟶ 1,478:
var counts: array[Base, Natural] # Count of bases.
for
inc counts[
# Display the SQ line.
|