Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,28 @@
with Ada.Text_IO; use Ada.Text_IO;
procedure Simple_FASTA is
Current: Character;
begin
Get(Current);
if Current /= '>' then
raise Constraint_Error with "'>' expected";
end if;
while not End_Of_File loop -- read name and string
Put(Get_Line & ": "); -- read name and write directly to output
Read_String:
loop
exit Read_String when End_Of_File; -- end of input
Get(Current);
if Current = '>' then -- next name
New_Line;
exit Read_String;
else
Put(Current & Get_Line);
-- read part of string and write directly to output
end if;
end loop Read_String;
end loop;
end Simple_FASTA;

View file

@ -0,0 +1,46 @@
with Ada.Text_IO, Ada.Containers.Indefinite_Ordered_Maps; use Ada.Text_IO;
procedure FASTA is
package Maps is new Ada.Containers.Indefinite_Ordered_Maps
(Element_Type => String, Key_Type => String);
Map: Maps.Map; -- Map holds the full file (as pairs of name and value)
function Get_Value(Previous: String := "") return String is
Current: Character;
begin
if End_Of_File then
return Previous; -- file ends
else
Get(Current); -- read first character
if Current = '>' then -- ah, a new name begins
return Previous; -- the string read so far is the value
else -- the entire line is part of the value
return Get_Value(Previous & Current & Get_Line);
end if;
end if;
end Get_Value;
procedure Print_Pair(Position: Maps.Cursor) is
begin
Put_Line(Maps.Key(Position) & ": " & Maps.Element(Position));
-- Maps.Key(X) is the name and Maps.Element(X) is the value at X
end Print_Pair;
Skip_This: String := Get_Value;
-- consumes the entire file, until the first line starting with '>'.
-- the string Skip_This should be empty, but we don't verify this
begin
while not End_Of_File loop -- read the file into Map
declare
Name: String := Get_Line;
-- reads all characters in the line, except for the first ">"
Value: String := Get_Value;
begin
Map.Insert(Key => Name, New_Item => Value);
-- adds the pair (Name, Value) to Map
end;
end loop;
Map.Iterate(Process => Print_Pair'Access); -- print Map
end FASTA;

View file

@ -4,35 +4,35 @@
void main()
{
FILE * fp;
char * line = NULL;
size_t len = 0;
ssize_t read;
FILE * fp;
char * line = NULL;
size_t len = 0;
ssize_t read;
fp = fopen("fasta.txt", "r");
if (fp == NULL)
exit(EXIT_FAILURE);
fp = fopen("fasta.txt", "r");
if (fp == NULL)
exit(EXIT_FAILURE);
int state = 0;
while ((read = getline(&line, &len, fp)) != -1) {
/* Delete trailing newline */
if (line[read - 1] == '\n')
line[read - 1] = 0;
/* Handle comment lines*/
if (line[0] == '>') {
if (state == 1)
printf("\n");
printf("%s: ", line+1);
state = 1;
} else {
/* Print everything else */
printf("%s", line);
}
}
printf("\n");
int state = 0;
while ((read = getline(&line, &len, fp)) != -1) {
/* Delete trailing newline */
if (line[read - 1] == '\n')
line[read - 1] = 0;
/* Handle comment lines*/
if (line[0] == '>') {
if (state == 1)
printf("\n");
printf("%s: ", line+1);
state = 1;
} else {
/* Print everything else */
printf("%s", line);
}
}
printf("\n");
fclose(fp);
if (line)
free(line);
exit(EXIT_SUCCESS);
fclose(fp);
if (line)
free(line);
exit(EXIT_SUCCESS);
}

View file

@ -0,0 +1,54 @@
! FASTA format
! tested with Intel ifx (IFX) 2025.2.1 20250806 on Kubuntu 25.10
! GNU Fortran (Ubuntu 15.2.0-4ubuntu4) 15.2.0 on Kubuntu 25.10
! VSI Fortran x86-64 V8.6-001 on OpenVMS x86_64 V9.2-3
! No Non-standard features used, should compile on any fairly recent Fortran.
! U.B., January 2026
!==============================================================================
program fasta
integer, parameter :: maxlineLength=200 ! Assume no input line is longer than this.
! Wikipedia article on FASTA: typically no more than 80
character (len=maxlineLength) :: inLine ! Line to read
integer :: l ! Length of read line
logical :: first=.true.
! going to read from a text file named "fasta.txt", located in the current working directory.
open(unit=10, file='fasta.txt', status='old', action='read', iostat=io_stat)
if (io_stat /= 0) then
print *, "Error opening file"
stop
end if
!-- Start the main I/O loop.
!-- For simplicity, handle only lines starting with ">" as these introduce new sequences.
!-- Any other lines are simply written to output without interpretation or checks.
!
do ! Loop ends at ERROR or EOF
read (10,'(A)', iostat=io_stat) inLine ! not Q format, so its ok for both intel and GNU
l = len_trim (inLine) ! use this instead of Q format
if (io_stat < 0) exit ! EOF: Normal end of this loop
if (io_stat > 0) then
print *, "Read error" ! ERROR: never seen this error condition
exit
end if
if (inLine (1:1) .eq. '>') then ! New sequence begins here
if (first) then ! First sequence: DO not terminate previous output, there is none.
first = .false.
write (*,'(1x,A, ": ")', advance='no') inLine (:l) ! Without terminating previous line
else ! Second or later: terminate previous output line
write (*,'(/,1x,A, ": ")', advance='no')inLine (:l)
endif
else if (first) then
! It is required that the 1st character of the very first line is a '>', anything else
! would be an error here.
print *, 'ERROR: 1st char is not >'
stop
else
! Within the sequence: Append to current line
write (*,'(A)', advance='no') inLine (:l)
end if
end do
write (*,*) ! Terminate last line
end program fasta

View file

@ -0,0 +1,27 @@
include resources "fasta.txt" // your fasta file
void local fn ReadFASTAFile( url as CFURLRef )
open @"I", 1, url
CFStringRef dta = @""
while ( !eof(1) )
CFStringRef string = line input 1
if ( !len(string) ) then continue
if ( fn StringHasPrefix( string, @">" ) )
if ( len(dta) )
print dta
dta = @""
end if
dta = concat( dta, mid( string, 1 ), @": " )
else
dta = concat( dta, string )
end if
wend
if ( len(dta) ) then print dta
close 1
end fn
CFURLRef url
url = fn BundleURLForResource( fn BundleMain, @"fasta", @"txt", NULL ) // your fasta file name and extension
if ( url ) then fn ReadFASTAFile( url )
HandleEvents

View file

@ -7,18 +7,18 @@ local key = nil
-- iterate through lines
for line in data:gmatch("(.-)\r?\n") do
if line:match("%s") then
error("line contained space")
elseif line:sub(1,1) == ">" then
key = line:sub(2)
-- if key already exists, append to the previous input
output[key] = output[key] or ""
elseif key ~= nil then
output[key] = output[key] .. line
end
if line:match("%s") then
error("line contained space")
elseif line:sub(1,1) == ">" then
key = line:sub(2)
-- if key already exists, append to the previous input
output[key] = output[key] or ""
elseif key ~= nil then
output[key] = output[key] .. line
end
end
-- print result
for k,v in pairs(output) do
print(k..": "..v)
print(k..": "..v)
end

View file

@ -4,36 +4,36 @@ 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;
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
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
ctx: Commands.Context;
filename: ARRAY 256 OF CHAR;
res: BOOLEAN
BEGIN
ctx := Commands.GetContext();
res := ctx.arg.GetString(filename);
PrintOn(filename,ctx.out)
ctx := Commands.GetContext();
res := ctx.arg.GetString(filename);
PrintOn(filename,ctx.out)
END Do;
END Fasta.

View file

@ -0,0 +1,19 @@
my $fasta_example = <<'END_FASTA_EXAMPLE';
>Rosetta_Example_1
THERECANBENOSPACE
>Rosetta_Example_2
THERECANBESEVERAL
LINESBUTTHEYALLMUST
BECONCATENATED
END_FASTA_EXAMPLE
my $num_newlines = 0;
while ( < $fasta_example > ) {
if (/\A\>(.*)/) {
print "\n" x $num_newlines, $1, ': ';
}
else {
$num_newlines = 1;
print;
}
}

View file

@ -0,0 +1,23 @@
#!/usr/bin/perl
use strict; # https://rosettacode.org/wiki/FASTA_format
use warnings;
my $fasta_example = <<''; # end at first empty line
>Rosetta_Example_1
THERECANBENOSPACE
>Rosetta_Example_2
THERECANBESEVERAL
LINESBUTTHEYALLMUST
BECONCATENATED
open my $fh, '<', \$fasta_example or die "$! on open";
local $/ = "\n>"; # to read one sequence at a time
while( <$fh> )
{
chomp;
print s/^>//r # remove a leading '>' if present
=~ s/\n/: /r # change the first newline to ': '
=~ tr/\n//dr, # remove the rest of the newlines
"\n"; # and put one newline at the end
}

View file

@ -0,0 +1,21 @@
$file = @'
>Rosetta_Example_1
THERECANBENOSPACE
>Rosetta_Example_2
THERECANBESEVERAL
LINESBUTTHEYALLMUST
BECONCATENATED
'@
$lines = $file.Replace("`n","~").Split(">").ForEach({$_.TrimEnd("~").Split("`n",2,[StringSplitOptions]::RemoveEmptyEntries)})
$output = New-Object -TypeName PSObject
foreach ($line in $lines)
{
$name, $value = $line.Split("~",2).ForEach({$_.Replace("~","")})
$output | Add-Member -MemberType NoteProperty -Name $name -Value $value
}
$output | Format-List

View file

@ -0,0 +1,21 @@
$file = @'
>Rosetta_Example_1
THERECANBENOSPACE
>Rosetta_Example_2
THERECANBESEVERAL
LINESBUTTHEYALLMUST
BECONCATENATED
'@
$lines = $file.Replace("`n","~").Split(">") | ForEach-Object {$_.TrimEnd("~").Split("`n",2,[StringSplitOptions]::RemoveEmptyEntries)}
$output = New-Object -TypeName PSObject
foreach ($line in $lines)
{
$name, $value = $line.Split("~",2) | ForEach-Object {$_.Replace("~","")}
$output | Add-Member -MemberType NoteProperty -Name $name -Value $value
}
$output | Format-List

View file

@ -0,0 +1,61 @@
Rebol [
title: "Rosetta code: FASTA format"
file: %FASTA_format.r3
url: https://rosettacode.org/wiki/FASTA_format
]
;; Parses a FASTA-format file in chunks, returning a flat block of [header sequence] pairs.
;; FASTA format alternates between header lines (starting with ">") and sequence data lines.
decode-fasta: function [
source [file! url!] "Source file or URL to read from"
chunk-size [integer!] "Number of bytes to read per iteration"
][
out: copy []
port: open/read source ;; open the source as a streaming read port
;; Stream through the file chunk by chunk to avoid loading it all into memory
while [not empty? data: read/string/part port chunk-size][
;; If the previous iteration had an incomplete (trailing) line, prepend it
;; to the current chunk so it is parsed as a whole line this time
if rest [insert data rest]
parse data [
any [
;; Match everything up to the next newline as one line, then skip the LF
copy line: to LF skip (
either line/1 == #">" [
;; Header line - strip the leading ">" and add a new entry to out;
;; also capture the new 'val' reference for subsequent sequence appends
repend out [remove line val: copy ""]
][
;; Sequence line - append its content to the current entry's value
append val line
]
)
]
;; Capture any trailing bytes that did not end with LF (incomplete line);
;; 'rest' will be prepended to the next chunk at the top of the loop
copy rest: to end
]
]
close port ;; Be nice and close the port when done reading
;; The final trailing bytes are part of the last value
if all [val rest] [append val rest]
;; Insert a new-line marker before every other element (i.e. before each header),
;; making the flat block easier to read when printed with 'probe'
new-line/skip out true 2
]
;; Prepare a test file
write %data.fasta
{>Rosetta_Example_1
THERECANBENOSPACE
>Rosetta_Example_2
THERECANBESEVERAL
LINESBUTTHEYALLMUST
BECONCATENATED}
;; Run the decoder on a local FASTA file, reading 10 bytes at a time, and print the result
probe decode-fasta %data.fasta 10

View file

@ -1,10 +1,10 @@
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 ] ] ]
[ stream atEnd ] whileFalse: [
| line |
((line := stream nextLine) beginsWith: '>')
ifTrue: [
Transcript
cr;
show: (line copyFrom: 2 to: line size);
show: ': ' ]
ifFalse: [ Transcript show: line ] ] ]

View file

@ -9,6 +9,6 @@ seqns: smark string(nonl) scopy * [f=0];
none: <<>>;
nonl: !<<
>>;
spaces: << >>;
spaces: << >>;
f: 1;

View file

@ -2,12 +2,12 @@ proc fastaReader {filename} {
set f [open $filename]
set sep ""
while {[gets $f line] >= 0} {
if {[string match >* $line]} {
puts -nonewline "$sep[string range $line 1 end]: "
set sep "\n"
} else {
puts -nonewline $line
}
if {[string match >* $line]} {
puts -nonewline "$sep[string range $line 1 end]: "
set sep "\n"
} else {
puts -nonewline $line
}
}
puts ""
close $f

View file

@ -8,15 +8,15 @@ BECONCATENATED"
)
fn main() {
mut i := 0
for i <= data.len {
if data.substr_ni(i, i + 17) == ">Rosetta_Example_" {
print("\n" + data.substr_ni(i, i + 18) + ": ")
i = i + 17
}
else {
if data.substr_ni(i, i + 1) > "\x20" {print(data[i].ascii_str())}
}
i++
}
mut i := 0
for i <= data.len {
if data.substr_ni(i, i + 17) == ">Rosetta_Example_" {
print("\n" + data.substr_ni(i, i + 18) + ": ")
i = i + 17
}
else {
if data.substr_ni(i, i + 1) > "\x20" {print(data[i].ascii_str())}
}
i++
}
}