How to resolve the algorithm FASTA format step by step in the Pascal programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm FASTA format step by step in the Pascal programming language

Table of Contents

Problem Statement

In bioinformatics, long character strings are often encoded in a format called FASTA.
A FASTA file can contain several strings, each identified by a name marked by a > (greater than) character at the beginning of the line.

Write a program that reads a FASTA file such as: Note that a high-quality implementation will not hold the entire file in memory at once; real FASTA files can be multiple gigabytes in size.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm FASTA format step by step in the Pascal programming language

Source code in the pascal programming language

program FASTA_Format;
// FPC 3.0.2
var InF,
    OutF: Text;
    ch: char;
    First: Boolean=True;
    InDef: Boolean=False;

begin
  Assign(InF,'');
  Reset(InF);
  Assign(OutF,'');
  Rewrite(OutF);
  While Not Eof(InF) do
  begin
    Read(InF,ch);
    Case Ch of
      '>': begin
            if Not(First) then
              Write(OutF,#13#10)
            else
              First:=False;
            InDef:=true;
          end;
      #13: Begin
               if InDef then
               begin
                 InDef:=false;
                 Write(OutF,': ');
               end;
               Ch:=#0;
             end;
      #10: ch:=#0;
      else Write(OutF,Ch);
    end;
  end;
  Close(OutF);
  Close(InF);
end.


  

You may also check:How to resolve the algorithm Walk a directory/Non-recursively step by step in the Smalltalk programming language
You may also check:How to resolve the algorithm Draw a sphere step by step in the REXX programming language
You may also check:How to resolve the algorithm Old lady swallowed a fly step by step in the Lua programming language
You may also check:How to resolve the algorithm Vector step by step in the Nim programming language
You may also check:How to resolve the algorithm Conway's Game of Life step by step in the MiniScript programming language