FASTA format: Difference between revisions

no edit summary
No edit summary
Line 404:
online run crystal code in [https://play.crystal-lang.org/#/cr <b>playground</b>]
<lang ruby>
# create tmp fasta file in /tmp/
tmpfile = "/tmp/tmp"+Random.rand.to_s+".fasta"
File.write(tmpfile, ">Rosetta_Example_1
THERECANBENOSPACE
>Rosetta_Example_2
THERECANBESEVERAL
LINESBUTTHEYALLMUST
BECONCATENATED")
 
# read tmp fasta file and store to hash
ref = ARGV[0]tmpfile
 
id = seq = ""
fasta = {} of String => String
 
File.each_line(ref) do |line|
if line.starts_with?(">")
Line 421 ⟶ 429:
end
end
 
fasta[id] = seq.sub(/\s/, "")
 
# show fasta component
fasta.each do |k,v|
puts "#{k}: #{v}"