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;
TotalBaseCount := 0;
AssignFile(FastaFile, 'Homo_sapiens.GRCh37.67.dna_rm.chromosome.Y.fa');
{$I+} //use exceptions
try
Reset(FastaFile);
repeat
Readln(FastaFile, CurrentLine);
for i := 0 to length(CurrentLine) - 1 do
begin
c := CurrentLine[i];
if c in ['A', 'T'] then
inc(ATCount)
else if c in ['G', 'C'] then
begin
inc(GCCount);
end;
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.
Owner

samuell commented May 10, 2013

Compile flags used:

fpc -Ur -O3 -Xs- -OWall -FWgc_mischi -XX -CX -ogc_fpc_mischi gc_mischi.pas
fpc -Ur -O3 -Xs- -Owall -Fwgc_mischi -XX -CX -ogc_fpc_mischi gc_mischi.pas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment