I hope that in the future this library will be able to read and write FASTA and FASTQ, but currently it can only read FASTA.
NOTE: Currently the standard Crystal library does not open bgzip well; it can only handle gzip files.
-
Add the dependency to your
shard.yml
:dependencies: fastx: github: kojix2/fastx.cr
-
Run
shards install
# Create a Reader instance for your FASTA file
reader = Fastx::Fasta::Reader.new("path_to_your_file.fa")
# Go through each sequence in the file
reader.each do |name, sequence|
puts "Name: #{name}"
puts "Sequence: #{sequence.to_s}"
end
# Always remember to close the reader
reader.close
High-level API
Fastx.open("path_to_your_file.fa") do |reader|
reader.as(Fastx::Fasta::Reader) # Necessary in the current situation
.each do |name, sequence|
puts "Name: #{name}"
puts "Sequence: #{sequence.to_s}"
end
end
This library is in development.
- Fork it (https://github.com/kojix2/fastx/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request