FASTA format: Difference between revisions
→version 2: rewritten
(Added PL/M) |
Walterpachl (talk | contribs) (→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)
If ifid=='' Then
d=''
Do While lines(ifid)\==0
x=strip(linein(ifid),'T') /* read a line (a record) from the input */
/* and strip trailing blanks */
If left(x,1)=='>' Then Do /* a new file id
Call out /* show output name
name=substr(x,2) /* and get the new (or first)
d=''
End
Else
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= when using the default input filename:}}
<pre>
Line 1,928 ⟶ 2,011:
::* sequences that contain blanks, tabs, and other whitespace
::* sequence names that are identified with a semicolon [''';''']
<syntaxhighlight lang="rexx">/*REXX program reads a
name=
data=''
Do While
x=strip(linein(iFID),'T') /*read a line (a record) from the file,*/
Select
When x=='' Then /*
Nop
When left(x,1)==';' Then Do
If name=='' Then name=substr(x,2)
End
When left(x,1)=='>' Then Do
If data\=='' Then
Say name':'
name=substr(x,2)
data=''
End
Otherwise
data=space(data||translate(x, ,'*'),0)
End
End
If data\=='' Then
Say name':' data /* [?] show output of last file used. */
</syntaxhighlight>
<pre>
'''input:''' The '''FASTA2.IN''' 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@ :=
Do
Line 2,363 ⟶ 2,473:
{{trans|Kotlin}}
More or less.
<syntaxhighlight lang="
var checkNoSpaces = Fn.new { |s| !s.contains(" ") && !s.contains("\t") }
|