This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compile flags used: