FASTA format: Difference between revisions

m
syntax highlighting fixup automation
m (syntax highlighting fixup automation)
Line 27:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">V FASTA =
|‘>Rosetta_Example_1
THERECANBENOSPACE
Line 51:
R r
 
print(fasta_parse(FASTA).map((key, val) -> ‘#.: #.’.format(key, val)).join("\n"))</langsyntaxhighlight>
 
{{out}}
Line 61:
=={{header|Action!}}==
In the following solution the input file [https://gitlab.com/amarok8bit/action-rosetta-code/-/blob/master/source/fasta.txt fasta.txt] is loaded from H6 drive. Altirra emulator automatically converts CR/LF character from ASCII into 155 character in ATASCII charset used by Atari 8-bit computer when one from H6-H10 hard drive under DOS 2.5 is used.
<langsyntaxhighlight Actionlang="action!">PROC ReadFastaFile(CHAR ARRAY fname)
CHAR ARRAY line(256)
CHAR ARRAY tmp(256)
Line 90:
 
ReadFastaFile(fname)
RETURN</langsyntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/FASTA_format.png Screenshot from Atari 8-bit computer]
Line 102:
The simple solution just reads the file (from standard input) line by line and directly writes it to the standard output.
 
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO; use Ada.Text_IO;
 
procedure Simple_FASTA is
Line 129:
end loop;
 
end Simple_FASTA;</langsyntaxhighlight>
 
{{out}}
Line 142:
 
 
<langsyntaxhighlight Adalang="ada">with Ada.Text_IO, Ada.Containers.Indefinite_Ordered_Maps; use Ada.Text_IO;
 
procedure FASTA is
Line 187:
Map.Iterate(Process => Print_Pair'Access); -- print Map
end FASTA;</langsyntaxhighlight>
 
=={{header|Aime}}==
 
<langsyntaxhighlight lang="aime">file f;
text n, s;
 
Line 205:
}
 
o_(n);</langsyntaxhighlight>
{{Out}}
<pre>>Rosetta_Example_1: THERECANBENOSPACE
Line 211:
 
=={{header|ALGOL W}}==
<langsyntaxhighlight lang="algolw">begin
% reads FASTA format data from standard input and write the results to standard output %
% only handles the ">" line start %
Line 236:
readcard( line );
end while_not_eof
end.</langsyntaxhighlight>
{{out}}
<pre>
Line 245:
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">parseFasta: function [data][
result: #[]
current: ø
Line 268:
}
 
inspect.muted parseFasta text</langsyntaxhighlight>
 
{{out}}
Line 278:
 
=={{header|AutoHotkey}}==
<langsyntaxhighlight AutoHotkeylang="autohotkey">Data =
(
>Rosetta_Example_1
Line 291:
Gui, add, Edit, w700, % Data
Gui, show
return</langsyntaxhighlight>
{{out}}
<pre>>Rosetta_Example_1: THERECANBENOSPACE
Line 297:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f FASTA_FORMAT.AWK filename
# stop processing each file when an error is encountered
Line 349:
return
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 360:
{{works with|QBasic|1.1}}
{{works with|QuickBasic|4.5}}
<langsyntaxhighlight lang="qbasic">FUNCTION checkNoSpaces (s$)
FOR i = 1 TO LEN(s$) - 1
IF MID$(s$, i, 1) = CHR$(32) OR MID$(s$, i, 1) = CHR$(9) THEN checkNoSpaces = 0
Line 389:
END IF
LOOP
CLOSE #1</langsyntaxhighlight>
 
==={{header|True BASIC}}===
{{trans|QBasic}}
<langsyntaxhighlight lang="qbasic">DEF EOF(f)
IF END #f THEN LET EOF = -1 ELSE LET EOF = 0
END DEF
Line 426:
LOOP
CLOSE #1
END</langsyntaxhighlight>
 
=={{header|BASIC256}}==
<langsyntaxhighlight BASIC256lang="basic256">open 1, "input.fasta"
 
first = True
Line 461:
next i
return True
end function</langsyntaxhighlight>
 
=={{header|C}}==
<langsyntaxhighlight lang="c">#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Line 501:
free(line);
exit(EXIT_SUCCESS);
}</langsyntaxhighlight>
{{out}}
<pre>Rosetta_Example_1: THERECANBENOSPACE
Line 508:
=={{header|C sharp|C#}}==
 
<langsyntaxhighlight lang="csharp">using System;
using System.Collections.Generic;
using System.IO;
Line 559:
Console.ReadLine();
}
}</langsyntaxhighlight>
 
=={{header|C++}}==
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <fstream>
 
Line 602:
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 610:
 
=={{header|Clojure}}==
<langsyntaxhighlight lang="clojure">(defn fasta [pathname]
(with-open [r (clojure.java.io/reader pathname)]
(doseq [line (line-seq r)]
(if (= (first line) \>)
(print (format "%n%s: " (subs line 1)))
(print line)))))</langsyntaxhighlight>
 
=={{header|Common Lisp}}==
<langsyntaxhighlight lang="lisp">;; * The input file as a parameter
(defparameter *input* #p"fasta.txt"
"The input file name.")
Line 631:
:do (format t "~&~a: " (subseq line 1))
:else
:do (format t "~a" line)))</langsyntaxhighlight>
{{out}}
<pre>Rosetta_Example_1: THERECANBENOSPACE
Line 637:
=={{header|Crystal}}==
If you want to run below code online, then paste below code to [https://play.crystal-lang.org/#/cr <b>playground</b>]
<langsyntaxhighlight lang="ruby">
# create tmp fasta file in /tmp/
tmpfile = "/tmp/tmp"+Random.rand.to_s+".fasta"
Line 664:
# show fasta component
fasta.each { |k,v| puts "#{k}: #{v}"}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 674:
 
=={{header|Factor}}==
<langsyntaxhighlight lang="factor">USING: formatting io kernel sequences ;
IN: rosetta-code.fasta
 
Line 683:
readln rest "%s: " printf [ process-fasta-line ] each-line ;
 
MAIN: main</langsyntaxhighlight>
{{out}}
<pre>
Line 692:
=={{header|Forth}}==
Developed with gforth 0.7.9
<langsyntaxhighlight lang="forth">1024 constant max-Line
char > constant marker
 
Line 708:
cr ;
Test
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 718:
This program sticks to the task as described in the heading and doesn't allow for any of the (apparently) obsolete
practices described in the Wikipedia article :
<langsyntaxhighlight lang="freebasic">' FB 1.05.0 Win64
 
Function checkNoSpaces(s As String) As Boolean
Line 755:
Print : Print
Print "Press any key to quit"
Sleep</langsyntaxhighlight>
 
{{out}}
Line 764:
 
=={{header|Gambas}}==
<langsyntaxhighlight lang="gambas">Public Sub Main()
Dim sList As String = File.Load("../FASTA")
Dim sTemp, sOutput As String
Line 779:
Print sOutput
 
End</langsyntaxhighlight>
Output:
<pre>Rosetta_Example_1: THERECANBENOSPACE
Line 786:
 
=={{header|Go}}==
<langsyntaxhighlight lang="go">package main
 
import (
Line 828:
fmt.Println(err)
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 842:
We parse FASTA by hand (generally not a recommended approach). We use the fact that groupBy walks the list from the head and groups the items by a predicate; here we first concatenate all the fasta strings and then pair those with each respective name.
 
<langsyntaxhighlight lang="haskell">import Data.List ( groupBy )
 
parseFasta :: FilePath -> IO ()
Line 858:
pair :: [String] -> [(String, String)]
pair [] = []
pair (x : y : xs) = (drop 1 x, y) : pair xs</langsyntaxhighlight>
 
{{out}}
Line 868:
We parse FASTA using parser combinators. Normally you'd use something like Trifecta or Parsec, but here we use ReadP, because it is simple and also included in ghc by default. With other parsing libraries the code would be almost the same.
 
<langsyntaxhighlight lang="haskell">import Text.ParserCombinators.ReadP
import Control.Applicative ( (<|>) )
import Data.Char ( isAlpha, isAlphaNum )
Line 885:
name = char '>' *> many (satisfy isAlphaNum <|> char '_') <* newline
code = concat <$> many (many (satisfy isAlpha) <* newline)
newline = char '\n'</langsyntaxhighlight>
 
{{out}}
Line 893:
=={{header|J}}==
Needs chunking to handle huge files.
<langsyntaxhighlight lang="j">require 'strings' NB. not needed for J versions greater than 6.
parseFasta=: ((': ' ,~ LF&taketo) , (LF -.~ LF&takeafter));._1</langsyntaxhighlight>
'''Example Usage'''
<langsyntaxhighlight lang="j"> Fafile=: noun define
>Rosetta_Example_1
THERECANBENOSPACE
Line 906:
parseFasta Fafile
Rosetta_Example_1: THERECANBENOSPACE
Rosetta_Example_2: THERECANBESEVERALLINESBUTTHEYALLMUSTBECONCATENATED</langsyntaxhighlight>
 
Nowadays, most machines have gigabytes of memory. However, if it's necessary to process FASTA content on a system with inadequate memory we can use files to hold intermediate results. For example:
 
<langsyntaxhighlight Jlang="j">bs=: 2
chunkFasta=: {{
r=. EMPTY
Line 937:
end.
r
}}</langsyntaxhighlight>
 
Here, we're using a block size of 2 bytes, to illustrate correctness. If speed matters, we should use something significantly larger.
Line 945:
Thus, if '~/fasta.txt' contains the example file for this task and we want to store intermediate results in the '~temp' directory, we could use:
 
<langsyntaxhighlight Jlang="j"> fasta=: '~temp' chunkFasta '~/fasta.txt'</langsyntaxhighlight>
 
And, to complete the task:
 
<langsyntaxhighlight Jlang="j"> ;(,': ',,&LF)each/"1 fread each fasta
Rosetta_Example_1: THERECANBENOSPACE
Rosetta_Example_2: THERECANBESEVERALLINESBUTTHEYALLMUSTBECONCATENATED</langsyntaxhighlight>
 
=={{header|Java}}==
{{trans|D}}
{{works with|Java|7}}
<langsyntaxhighlight lang="java">import java.io.*;
import java.util.Scanner;
 
Line 981:
System.out.println();
}
}</langsyntaxhighlight>
 
<pre>Rosetta_Example_1: THERECANBENOSPACE
Line 989:
=={{header|JavaScript}}==
The code below uses Nodejs to read the file.
<syntaxhighlight lang="javascript">
<lang JavaScript>
const fs = require("fs");
const readline = require("readline");
Line 1,018:
 
readInterface.on("close", () => process.stdout.write("\n"));
</syntaxhighlight>
</lang>
 
<pre>Rosetta_Example_1: THERECANBENOSPACE
Line 1,029:
in each cycle, only as many lines are read as are required to compose an output line. <br>
Notice that an additional ">" must be provided to "foreach" to ensure the final block of lines of the input file are properly assembled.
<syntaxhighlight lang="jq">
<lang jq>
def fasta:
foreach (inputs, ">") as $line
Line 1,040:
;
 
fasta</langsyntaxhighlight>
{{out}}
<langsyntaxhighlight lang="sh">$ jq -n -R -r -f FASTA_format.jq < FASTA_format.fasta
Rosetta_Example_1: THERECANBENOSPACE
Rosetta_Example_2: THERECANBESEVERALLINESBUTTHEYALLMUSTBECONCATENATED</langsyntaxhighlight>
 
=={{header|Julia}}==
{{works with|Julia|0.6}}
 
<langsyntaxhighlight lang="julia">for line in eachline("data/fasta.txt")
if startswith(line, '>')
print(STDOUT, "\n$(line[2:end]): ")
Line 1,055:
print(STDOUT, "$line")
end
end</langsyntaxhighlight>
 
=={{header|Kotlin}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight lang="scala">// version 1.1.2
 
import java.util.Scanner
Line 1,088:
}
sc.close()
}</langsyntaxhighlight>
 
{{out}}
Line 1,097:
 
=={{header|Lua}}==
<langsyntaxhighlight lang="lua">local file = io.open("input.txt","r")
local data = file:read("*a")
file:close()
Line 1,120:
for k,v in pairs(output) do
print(k..": "..v)
end</langsyntaxhighlight>
 
{{out}}
Line 1,134:
 
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module CheckIt {
Class FASTA_MACHINE {
Line 1,238:
}
checkit
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Mathematica has built-in support for FASTA files and strings
<langsyntaxhighlight Mathematicalang="mathematica">ImportString[">Rosetta_Example_1
THERECANBENOSPACE
>Rosetta_Example_2
Line 1,248:
LINESBUTTHEYALLMUST
BECONCATENATED
", "FASTA"]</langsyntaxhighlight>
{{out}}
<pre>{"THERECANBENOSPACE", "THERECANBESEVERALLINESBUTTHEYALLMUSTBECONCATENATED"}</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">
<lang Nim>
import strutils
 
Line 1,274:
 
fasta(input)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,282:
 
=={{header|Objeck}}==
<langsyntaxhighlight lang="objeck">class Fasta {
function : Main(args : String[]) ~ Nil {
if(args->Size() = 1) {
Line 1,307:
}
}
</syntaxhighlight>
</lang>
 
{{out}}
Line 1,320:
The program reads and processes the input one line at a time, and directly prints out the chunk of data available. The long strings are not concatenated in memory but just examined and processed as necessary: either printed out as is in the case of part of a sequence, or formatted in the case of the name (what I call the label), and managing the new lines where needed.
{{works with|OCaml|4.03+}}
<langsyntaxhighlight lang="ocaml">
(* This program reads from the standard input and writes to standard output.
* Examples of use:
Line 1,361:
let () =
print_fasta stdin
</syntaxhighlight>
</lang>
{{out}}
Rosetta_Example_1: THERECANBENOSPACE
Line 1,367:
 
=={{header|Pascal}}==
<syntaxhighlight lang="pascal">
<lang Pascal>
program FASTA_Format;
// FPC 3.0.2
Line 1,407:
Close(InF);
end.
</syntaxhighlight>
</lang>
 
FASTA_Format < test.fst
Line 1,416:
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">my $fasta_example = <<'END_FASTA_EXAMPLE';
>Rosetta_Example_1
THERECANBENOSPACE
Line 1,434:
print;
}
}</langsyntaxhighlight>
{{out}}
<pre>
Line 1,442:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(notonline)-->
<span style="color: #004080;">bool</span> <span style="color: #000000;">first</span> <span style="color: #0000FF;">=</span> <span style="color: #004600;">true</span>
<span style="color: #004080;">integer</span> <span style="color: #000000;">fn</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">open</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"fasta.txt"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"r"</span><span style="color: #0000FF;">)</span>
Line 1,466:
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #7060A8;">close</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 1,474:
 
=={{header|PicoLisp}}==
<langsyntaxhighlight PicoLisplang="picolisp">(de fasta (F)
(in F
(while (from ">")
Line 1,481:
(prin (line T)) )
(prinl) ) ) )
(fasta "fasta.dat")</langsyntaxhighlight>
{{out}}
<pre>
Line 1,491:
When working with a real file, the content of the <code>$file</code> variable would be: <code>Get-Content -Path .\FASTA_file.txt -ReadCount 1000</code>. The <code>-ReadCount</code> parameter value for large files is unknown, yet sure to be a value between 1,000 and 10,000 depending upon the length of file and length of the records in the file. Experimentation is the only way to know the optimum value.
{{works with|PowerShell|4.0+}}
<syntaxhighlight lang="powershell">
<lang PowerShell>
$file = @'
>Rosetta_Example_1
Line 1,513:
 
$output | Format-List
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 1,521:
 
===Version 3.0 Or Less===
<syntaxhighlight lang="powershell">
<lang PowerShell>
$file = @'
>Rosetta_Example_1
Line 1,543:
 
$output | Format-List
</syntaxhighlight>
</lang>
{{Out}}
<pre>
Line 1,551:
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">EnableExplicit
Define Hdl_File.i,
Frm_File.i,
Line 1,579:
CloseFile(Hdl_File)
Input()
EndIf</langsyntaxhighlight>
{{out}}
<pre>Rosetta_Example_1: THERECANBENOSPACE
Line 1,589:
and I use a generator expression yielding key, value pairs
as soon as they are read, keeping the minimum in memory.
<langsyntaxhighlight lang="python">import io
 
FASTA='''\
Line 1,613:
yield key, val
 
print('\n'.join('%s: %s' % keyval for keyval in fasta_parse(infile)))</langsyntaxhighlight>
 
{{out}}
Line 1,620:
 
=={{header|R}}==
<langsyntaxhighlight lang="rsplus">
library("seqinr")
 
Line 1,633:
cat(attr(aline, 'Annot'), ":", aline, "\n")
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,641:
 
=={{header|Racket}}==
<langsyntaxhighlight lang="racket">
#lang racket
(let loop ([m #t])
Line 1,651:
(current-output-port)))))
(newline)
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
<syntaxhighlight lang="raku" perl6line>grammar FASTA {
 
rule TOP { <entry>+ }
Line 1,675:
for $/<entry>[] {
say ~.<title>, " : ", .<sequence>.made;
}</langsyntaxhighlight>
{{out}}
<pre>Rosetta_Example_1 : THERECANBENOSPACE
Line 1,684:
===version 1===
This REXX version correctly processes the examples shown.
<langsyntaxhighlight lang="rexx">/*REXX program reads a (bio-informational) FASTA file and displays the contents. */
parse arg iFID . /*iFID: the input file to be read. */
if iFID=='' then iFID='FASTA.IN' /*Not specified? Then use the default.*/
Line 1,699:
else $=$ || x
end /*j*/ /* [↓] show output of last file used. */
if $\=='' then say name':' $ /*stick a fork in it, we're all done. */</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default input filename:}}
<pre>
Line 1,712:
::* &nbsp; sequences that contain blanks, tabs, and other whitespace
::* &nbsp; sequence names that are identified with a semicolon &nbsp; [''';''']
<langsyntaxhighlight lang="rexx">/*REXX program reads a (bio-informational) FASTA file and displays the contents. */
parse arg iFID . /*iFID: the input file to be read. */
if iFID=='' then iFID='FASTA2.IN' /*Not specified? Then use the default.*/
Line 1,733:
else $=space($ || translate(x, , '*'), 0)
end /*j*/ /* [↓] show output of last file used. */
if $\=='' then say name':' $ /*stick a fork in it, we're all done. */</langsyntaxhighlight>
<pre>
'''input:''' &nbsp; The &nbsp; '''FASTA2.IN''' &nbsp; file is shown below:
Line 1,766:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
# Project : FAST format
 
Line 1,789:
i = i + 1
end
</syntaxhighlight>
</lang>
Output:
<pre>
Line 1,797:
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">def fasta_format(strings)
out, text = [], ""
strings.split("\n").each do |line|
Line 1,819:
EOS
 
puts fasta_format(data)</langsyntaxhighlight>
 
{{out}}
Line 1,828:
 
=={{header|Run BASIC}}==
<langsyntaxhighlight lang="runbasic">a$ = ">Rosetta_Example_1
THERECANBENOSPACE
>Rosetta_Example_2
Line 1,845:
end if
i = i + 1
wend</langsyntaxhighlight>
{{out}}
<pre>>Rosetta_Example_1: THERECANBENOSPACE
Line 1,854:
This example is implemented using an [https://doc.rust-lang.org/book/iterators.html iterator] to reduce memory requirements and encourage code reuse.
 
<langsyntaxhighlight lang="rust">
use std::env;
use std::io::{BufReader, Lines};
Line 1,918:
}
}
</syntaxhighlight>
</lang>
{{out}}
<pre>Rosetta_Example_1: THERECANBENOSPACE
Line 1,924:
 
=={{header|Scala}}==
<langsyntaxhighlight lang="scala">import java.io.File
import java.util.Scanner
 
Line 1,942:
 
println("~~~+~~~")
}</langsyntaxhighlight>
 
=={{header|Scheme}}==
<langsyntaxhighlight lang="scheme">(import (scheme base)
(scheme file)
(scheme write))
Line 1,960:
(display (string-copy line 1)) (display ": "))
(else ; display the string directly
(display line))))))</langsyntaxhighlight>
{{out}}
<pre>Rosetta_Example_1: THERECANBENOSPACE
Line 1,966:
 
=={{header|Seed7}}==
<langsyntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const proc: main is func
Line 1,992:
end if;
writeln;
end func;</langsyntaxhighlight>
 
{{out}}
Line 2,002:
=={{header|Sidef}}==
{{trans|Ruby}}
<langsyntaxhighlight lang="ruby">func fasta_format(strings) {
var out = []
var text = ''
Line 2,026:
THERECANBESEVERAL
LINESBUTTHEYALLMUST
BECONCATENATED</langsyntaxhighlight>
{{out}}
<pre>
Line 2,034:
 
=={{header|Tcl}}==
<langsyntaxhighlight lang="tcl">proc fastaReader {filename} {
set f [open $filename]
set sep ""
Line 2,049:
}
 
fastaReader ./rosettacode.fas</langsyntaxhighlight>
{{out}}
<pre>
Line 2,058:
=={{header|TMG}}==
Unix TMG: <!-- C port of TMG processes 1.04 GB FASTA file in 38 seconds on a generic laptop -->
<langsyntaxhighlight UnixTMGlang="unixtmg">prog: ignore(spaces)
loop: parse(line)\loop parse(( = {*} ));
line: ( name | * = {} | seqns );
Line 2,071:
spaces: << >>;
 
f: 1;</langsyntaxhighlight>
 
=={{header|uBasic/4tH}}==
<syntaxhighlight lang="text">If Cmd (0) < 2 Then Print "Usage: fasta <fasta file>" : End
If Set(a, Open (Cmd(2), "r")) < 0 Then Print "Cannot open \q";Cmd(2);"\q" : End
 
Line 2,105:
Loop ' if not add the line to current string
 
Return (b@) ' return the string</langsyntaxhighlight>
{{out}}
<pre>Rosetta_Example_1: THERECANBENOSPACE
Line 2,114:
{{trans|Kotlin}}
More or less.
<langsyntaxhighlight lang="ecmascript">import "io" for File
 
var checkNoSpaces = Fn.new { |s| !s.contains(" ") && !s.contains("\t") }
Line 2,153:
}
}
}</langsyntaxhighlight>
 
{{out}}
Line 2,162:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">proc Echo; \Echo line of characters from file to screen
int Ch;
def LF=$0A, EOF=$1A;
Line 2,184:
Echo;
];
]</langsyntaxhighlight>
 
{{out}}
Line 2,194:
 
=={{header|zkl}}==
<langsyntaxhighlight lang="zkl">fcn fasta(data){ // a lazy cruise through a FASTA file
fcn(w){ // one string at a time, -->False garbage at front of file
line:=w.next().strip();
Line 2,201:
})
}.fp(data.walker()) : Utils.Helpers.wap(_);
}</langsyntaxhighlight>
*This assumes that white space at front or end of string is extraneous (excepting ">" lines).
*Lazy, works for objects that support iterating over lines (ie most).
*The fasta function returns an iterator that wraps a function taking an iterator. Uh, yeah. An initial iterator (Walker) is used to get lines, hold state and do push back when read the start of the next string. The function sucks up one string (using the iterator). The wrapping iterator (wap) traps the exception when the function waltzes off the end of the data and provides API for foreach (etc).
FASTA file:
<langsyntaxhighlight lang="zkl">foreach l in (fasta(File("fasta.txt"))) { println(l) }</langsyntaxhighlight>
FASTA data blob:
<langsyntaxhighlight lang="zkl">data:=Data(0,String,
">Rosetta_Example_1\nTHERECANBENOSPACE\n"
">Rosetta_Example_2\nTHERECANBESEVERAL\nLINESBUTTHEYALLMUST\n"
"BECONCATENATED");
foreach l in (fasta(data)) { println(l) }</langsyntaxhighlight>
{{out}}
<pre>
10,351

edits