Skip to content

Instantly share code, notes, and snippets.

@samuell
Created May 10, 2013 16:55
  • 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/5555731 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;
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.
@samuell
Copy link
Author

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