Skip to content

Instantly share code, notes, and snippets.

@samuell
Created May 10, 2013 16:57
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save samuell/5555743 to your computer and use it in GitHub Desktop.
program gc;
{$mode objfpc} // Do not forget this ever
uses
Sysutils;
var
FastaFile: TextFile;
CurrentLine: String;
GCCount: Integer;
ATCount: Integer;
TotalBaseCount: Integer;
i: Integer;
c: Char;
GCFraction: Single;
begin
GCCount := 0;
ATCount := 0;
AssignFile(FastaFile, 'Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa');
{$I+} //use exceptions
try
Reset(FastaFile);
repeat
Readln(FastaFile, CurrentLine);
i := 0;
while i < Length(CurrentLine) do
begin
c := CurrentLine[i];
if (c = 'C') or (c = 'G') then
GCCount := GCCount + 1
else if (c = 'A') or (c = 'T') then
ATCount := ATCount + 1;
i := i + 1;
end;
until(EOF(FastaFile));
CloseFile(FastaFile);
except
on E: EInOutError do
begin
Writeln('File handling error occurred. Details: '+E.ClassName+'/'+E.Message);
end;
end;
TotalBaseCount := GCCount + ATCount;
GCFraction := GCCount / TotalBaseCount;
Writeln(FormatFloat('00.0000', GCFraction * 100));
end.
@samuell
Copy link
Author

samuell commented May 10, 2013

Compile flags used:

fpc -Ur -O3 -Xs- -OWall -FWgc_fpc -XX -CX -ogc_fpc gc.pas
fpc -Ur -O3 -Xs- -Owall -Fwgc_fpc -XX -CX -ogc_fpc gc.pas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment