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.



Task

Write a program that reads a FASTA file such as:

>Rosetta_Example_1
THERECANBENOSPACE
>Rosetta_Example_2
THERECANBESEVERAL
LINESBUTTHEYALLMUST
BECONCATENATED


Output:
Rosetta_Example_1: THERECANBENOSPACE
Rosetta_Example_2: THERECANBESEVERALLINESBUTTHEYALLMUSTBECONCATENATED

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.




' FB 1.05.0 Win64
 
Function checkNoSpaces(s As String) As Boolean
  For i As UInteger = 0 To Len(s) - 1
    If s[i] = 32 OrElse s[i] = 9 Then Return False  '' check for spaces or tabs
  Next
  Return True
End Function
 
Open "input.fasta" For Input As # 1
 
Dim As String ln, seq
Dim first As Boolean = True
 
While Not Eof(1)
  Line Input #1, ln
  If Left(ln, 1) = ">"  Then
    If Not first Then Print 
    Print Mid(ln, 2); ": ";       
    If first Then first = False
  ElseIf first Then
    Print: Print "Error : File does not begin with '>'";
    Exit While
  Else
    If checkNoSpaces(ln) Then
      Print ln;
    Else
      Print : Print "Error : Sequence contains space(s)";
      Exit While
    End If
  End If
Wend
 
Close #1
 
Print : Print
Print "Press any key to quit"
Sleep