FASTA format: Difference between revisions

→‎version 2: rewritten
(Added PL/M)
(→‎version 2: rewritten)
 
(8 intermediate revisions by 5 users not shown)
Line 704:
=={{header|Delphi}}==
See [https://rosettacode.org/wiki/FASTA_format#Pascal Pascal].
 
=={{header|EasyLang}}==
<syntaxhighlight>
repeat
s$ = input
until s$ = ""
if substr s$ 1 1 = ">"
if stat = 1
print ""
.
stat = 1
print s$
else
write s$
.
.
input_data
>Rosetta_Example_1
THERECANBENOSPACE
>Rosetta_Example_2
THERECANBESEVERAL
LINESBUTTHEYALLMUST
BECONCATENATED
 
</syntaxhighlight>
 
=={{header|F_Sharp|F#}}==
Line 719 ⟶ 744:
THERECANBESEVERALLINESBUTTHEYALLMUSTBECONCATENATED
</pre>
 
=={{header|Factor}}==
<syntaxhighlight lang="factor">USING: formatting io kernel sequences ;
Line 1,381 ⟶ 1,407:
 
fasta(input)
</syntaxhighlight>
{{out}}
<pre>
Rosetta_Example_1: THERECANBENOSPACE
Rosetta_Example_2: THERECANBESEVERALLINESBUTTHEYALLMUSTBECONCATENATED
</pre>
=={{header|Oberon}}==
Works with A2 Oberon.
 
<syntaxhighlight lang="Oberon">
MODULE Fasta;
 
IMPORT Files, Streams, Strings, Commands;
 
PROCEDURE PrintOn*(filename: ARRAY OF CHAR; wr: Streams.Writer);
VAR
rd: Files.Reader;
f: Files.File;
line: ARRAY 1024 OF CHAR;
res: BOOLEAN;
BEGIN
f := Files.Old(filename);
ASSERT(f # NIL);
NEW(rd,f,0);
res := rd.GetString(line);
WHILE rd.res # Streams.EOF DO
IF line[0] = '>' THEN
wr.Ln;
wr.String(Strings.Substring2(1,line)^);
wr.String(": ")
ELSE
wr.String(line)
END;
res := rd.GetString(line)
END
END PrintOn;
 
PROCEDURE Do*;
VAR
ctx: Commands.Context;
filename: ARRAY 256 OF CHAR;
res: BOOLEAN
BEGIN
ctx := Commands.GetContext();
res := ctx.arg.GetString(filename);
PrintOn(filename,ctx.out)
END Do;
 
END Fasta.
</syntaxhighlight>
{{out}}
Line 1,900 ⟶ 1,975:
===version 1===
This REXX version correctly processes the examples shown.
<syntaxhighlight lang="rexx">/*REXX program reads a (bio-informational) FASTA file and displays the contents. */
parseParse argArg iFIDifid . /* iFID: the input file to be read. */
If ifid=='' Then
if iFID=='' then iFID='FASTA.IN' /*Not specified? Then use the default.*/
name= ifid='FASTA.IN' /* Not specified? Then use /*the namedefault of an output file (so far). */
$name='' /* the name of an output file (so far) /*the value of the output file's stuff.*/
d='' do while lines(iFID)\==0 /*process the value FASTAof the output file's contents. */
Do While lines(ifid)\==0 x=strip( linein(iFID), 'T') /* process the FASTA file /*readcontents a line (a record) from the file,*/
x=strip(linein(ifid),'T') /* read a line (a record) from the input */
/*───────── and strip trailing blanks. */
/* and strip trailing blanks */
if left(x, 1)=='>' then do
If left(x,1)=='>' Then Do /* a new file id if $\=='' then say name':' $*/
Call out /* show output name=substr(x, and data 2)*/
name=substr(x,2) /* and get the new (or first) $=output name */
d='' end /* start with empty contents */
End
else $=$ || x
Else end /*j*/ /* a line with data /* [↓] show output of last file used. */
if $\= d=''d||x then say name':' $ /*stick aappend it to output fork in it, we're all done. */</syntaxhighlight>
End
Call out /* show output of last file used. */
Exit
 
out:
If d\=='' Then /* if there ara data */
Say name':' d /* show output name and data */
Return</syntaxhighlight>
{{out|output|text=&nbsp; when using the default input filename:}}
<pre>
Line 1,928 ⟶ 2,011:
::* &nbsp; sequences that contain blanks, tabs, and other whitespace
::* &nbsp; sequence names that are identified with a semicolon &nbsp; [''';''']
<syntaxhighlight lang="rexx">/*REXX program reads a (bio-informational) FASTA file and displays the contents. */
parseParse argArg iFID . /*iFID: the input file to be read. */
ifIf iFID=='' thenThen iFID='FASTA2.IN' /*Not specified? Then use the default.*/
name= '' /*the name of an output file (so far). */
data=''
$= /*the value of the output file's stuff.*/
do while lines(iFID)\==0 /*process the value FASTAof the output file's contentsstuff. */
Do While x=strip( lineinlines(iFID),\==0 'T') /*readprocess athe line (aFASTA record) fromfile contents. the file,*/
x=strip(linein(iFID),'T') /*read a line (a record) from the file,*/
/*───────── and strip trailing blanks. */
if x=='' then iterate /*If the line is all blank, ignore it /*--------- and strip trailing blanks. */
Select
if left(x, 1)==';' then do
When x=='' Then /* ifIf name==''the thenline name=substr(xis all blank,2) */
Nop say x /* ignore it. */
When left(x,1)==';' Then Do
iterate
If name=='' Then name=substr(x,2)
end
if left(Say x, 1)=='>' then do
End
if $\=='' then say name':' $
When left(x,1)=='>' Then Do
name=substr(x, 2)
If data\=='' Then
$=
Say name':' enddata
name=substr(x,2)
else $=space($ || translate(x, , '*'), 0)
data=''
end /*j*/ /* [↓] show output of last file used. */
End
if $\=='' then say name':' $ /*stick a fork in it, we're all done. */</syntaxhighlight>
Otherwise
data=space(data||translate(x, ,'*'),0)
End
End
If data\=='' Then
Say name':' data /* [?] show output of last file used. */
</syntaxhighlight>
<pre>
'''input:''' &nbsp; The &nbsp; '''FASTA2.IN''' &nbsp; file is shown below:
Line 2,243 ⟶ 2,333:
LINESBUTTHEYALLMUST
BECONCATENATED</syntaxhighlight>
{{out}}
<pre>
Rosetta_Example_1: THERECANBENOSPACE
Rosetta_Example_2: THERECANBESEVERALLINESBUTTHEYALLMUSTBECONCATENATED
</pre>
 
=={{header|Smalltalk}}==
Works with Pharo Smalltalk
<syntaxhighlight lang="smalltalk">
FileLocator home / aFilename readStreamDo: [ :stream |
[ stream atEnd ] whileFalse: [
| line |
((line := stream nextLine) beginsWith: '>')
ifTrue: [
Transcript
cr;
show: (line copyFrom: 2 to: line size);
show: ': ' ]
ifFalse: [ Transcript show: line ] ] ]
</syntaxhighlight>
{{out}}
<pre>
Line 2,311 ⟶ 2,421:
Local (4)
 
b@ := Dup("") ' start with an empty string
 
Do
Line 2,363 ⟶ 2,473:
{{trans|Kotlin}}
More or less.
<syntaxhighlight lang="ecmascriptwren">import "io" for File
 
var checkNoSpaces = Fn.new { |s| !s.contains(" ") && !s.contains("\t") }
2,295

edits