Skip to content

bio-cr/fastx.cr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

73 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fastx.cr

test Docs Latest

Small FASTA/FASTQ I/O for Crystal.

Installation

Add this to shard.yml:

dependencies:
  fastx:
    github: bio-cr/fastx.cr

Then run:

shards install

Features

  • Read and write FASTA
  • Read and write FASTQ
  • Auto-handle gzip when the path ends with .gz
  • Iterate with owned String values or lower-allocation borrowed Bytes
  • Stream large records line by line without accumulating full sequences
  • Encode/decode nucleotide bases and FASTQ quality scores

Quick Start

Read FASTA:

require "fastx"

Fastx::Fasta::Reader.open("reads.fa.gz") do |reader|
  reader.each do |header, sequence|
    puts "#{header}\t#{sequence.bytesize}"
  end
end

Read FASTQ:

Fastx::Fastq::Reader.open("reads.fq.gz") do |reader|
  reader.each do |identifier, sequence, quality|
    puts "#{identifier}\t#{sequence.bytesize}\t#{quality.bytesize}"
  end
end

Write FASTA:

Fastx::Fasta::Writer.open("out.fa", line_width: 80) do |writer|
  writer.write("seq1", "ACGTACGT")
end

Write FASTQ:

Fastx::Fastq::Writer.open("out.fq.gz") do |writer|
  writer.write("seq1", "ACGT", "!!!!")
end

Guides

License

MIT License

Packages

 
 
 

Contributors