Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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
Owner
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