-
Notifications
You must be signed in to change notification settings - Fork 0
/
uNucleotideCount.pas
46 lines (38 loc) · 1.2 KB
/
uNucleotideCount.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
unit uNucleotideCount;
interface
uses
SysUtils, System.Generics.Collections;
type EInvalidNucleotideException = class(Exception);
type TDNA = class
constructor Create(const ASequence : string); overload;
destructor Destroy; override;
private
FNucleotideCounts : TDictionary<char, integer>;
public
property NucleotideCounts : TDictionary<char, integer> read FNucleotideCounts;
end;
implementation
constructor TDNA.Create(const ASequence : string);
var
i : integer;
begin
inherited Create;
self.FNucleotideCounts := TDictionary<char, integer>.Create;
self.FNucleotideCounts.Add('A',0);
self.FNucleotideCounts.Add('T',0);
self.FNucleotideCounts.Add('C',0);
self.FNucleotideCounts.Add('G',0);
for i := Low(ASequence) to High(ASequence) do
if FNucleotideCounts.ContainsKey(ASequence[i]) then
FNucleotideCounts.Items[ASequence[i]] := FNucleotideCounts.Items[ASequence[i]] + 1
else
begin
raise EInvalidNucleotideException.Create('Invalid nucleotide in strand');
end;
end;
destructor TDNA.Destroy;
begin
self.FNucleotideCounts.Free;
inherited;
end;
end.