SeqKit Documentation

repository·master·Indexed 23 days ago

https://github.com/shenwei356/seqkit

A cross-platform, ultrafast, and dependency-free toolkit for manipulating FASTA and FASTQ sequence files. SeqKit supports various compressed formats (gzip, xz, zstd, bzip2, lz4) and provides a wide range of subcommands for format conversion, searching, set operations, editing, and ordering. It also includes a BAM toolbox with tools like AlnContext for sequence context filtering, AccStats for alignment accuracy, and BamDump for extracting BAM record properties to TSV.

Tokens
55.2K
Snippets
77
Records
262
Agent score
78%

What's inside SeqKit

  1. Overview of SeqKit features

    master

    SeqKit is a cross-platform, ultrafast toolkit designed for FASTA/Q file manipulation.

    Key capabilities include:

    • Format Support: Seamlessly parses both FASTA and FASTQ formats.
    • Compression & I/O: Supports gzip, xz, zstd, bzip2, and lz4 compressed files. It works with both input/output files and STDIN/STDOUT, making it ideal for shell piping.
    • Reproducibility: Commands like sample and shuffle allow for a configurable random seed to ensure reproducible results.
    • Customization: Supports custom sequence ID extraction using regular expressions.
    • Shell Integration: Supports Bash/Zsh autocompletion.
  2. Overview of SeqKit commands and functionality

    master

    SeqKit is a cross-platform toolkit for FASTA/Q file manipulation. It is organized into several functional categories of subcommands:

    Basic Operations

    • faidx: Create FASTA index and extract subsequences.
    • scat: Real-time recursive concatenation and streaming of fastx files.
    • seq: Transform sequences (extract ID, filter by length, remove gaps, reverse complement, etc.).
    • sliding: Extract subsequences in sliding windows.
    • stats: Simple statistics for FASTA/Q files.
    • subseq: Get subsequences by region/gtf/bed, including flanking sequences.
    • translate: Translate DNA/RNA to protein sequence.
    • watch: Monitor and view online histograms of sequence features.

    Format Conversion

    • convert: Convert FASTQ quality encoding (Sanger, Solexa, Illumina).
    • fa2fq: Retrieve FASTQ records from a FASTA file.
    • fq2fa: Convert FASTQ to FASTA.
    • fx2tab: Convert FASTA/Q to tabular format (includes length, GC content, etc.).
    • tab2fx: Convert tabular format back to FASTA/Q.

    Searching

    • amplicon: Extract amplicons via primers.
    • fish: Look for short sequences in larger sequences using local alignment.
    • grep: Search by ID/name/sequence/motifs.
    • locate: Locate subsequences/motifs.

    Set Operations

    • common: Find shared sequences across multiple files.
    • duplicate: Duplicate sequences N times.
    • head: Print first N records or records meeting a total length threshold.
    • head-genome: Print sequences of the first genome with common prefixes.
    • pair: Match paired-end reads from two FASTQ files.
    • range: Print records in a specific range (start:end).
    • rmdup: Remove duplicated sequences.
    • sample / sample2: Sample sequences by number or proportion.
    • split / split2: Split sequences into files by various criteria.

    Editing and Ordering

    • concat: Concatenate sequences with the same ID from multiple files.
    • mutate: Edit sequences (point mutation, insertion, deletion).
    • rename: Rename duplicated IDs.
    • replace: Replace name/sequence using regular expressions.
    • restart: Reset start position for circular genomes.
    • sana: Sanitize broken single-line FASTQ files.
    • shuffle: Shuffle sequences.
    • sort: Sort sequences by ID, name, sequence, or length.

    Miscellaneous

    • bam: Monitor BAM record features.
    • merge-slides: Merge sliding windows.
    • sum: Compute message digest for sequences.
  3. What is SeqKit?

    master

    SeqKit is a cross-platform, ultrafast toolkit designed for manipulating FASTA and FASTQ files. It is a comprehensive tool for nucleotide and protein sequence processing, supporting common tasks such as converting, searching, filtering, deduplication, splitting, shuffling, sampling, and more.

    Key advantages include:

    • Cross-platform: Provides executable binaries for Windows, Linux, and macOS.
    • Zero dependencies: Can be used directly without pre-configured environments or additional packages.
    • High performance: Demonstrates competitive execution time and memory usage compared to other bioinformatics tools.
    • Versatile I/O: Supports reading from STDIN and handling gzipped files (both reading and writing).
  4. Overview of SeqKit subcommands

    master

    SeqKit provides a wide range of subcommands categorized by their primary function. These include basic operations, format conversions, searching, set operations, editing, ordering, BAM processing, and miscellaneous utilities.

    Command Categories

    • Basic operation: seq, stats, subseq, sliding, faidx, translate, watch, scat.
    • Format conversion: fq2fa, fx2tab, fa2fq, tab2fx, convert.
    • Searching: grep, locate, amplicon, fish.
    • Set operation: sample, sample2, rmdup, common, duplicate, split, split2, head, head-genome, range, pair.
    • Edit: replace, rename, concat, restart, mutate, sana.
    • Ordering: sort, shuffle.
    • BAM processing: bam.
    • Miscellaneous: sum, merge-slides.
  5. Compare SeqKit features with other bioinformatics tools

    master

    SeqKit provides a comprehensive set of features for FASTA/Q manipulation. Compared to other common tools like seqtk, fasta_utilities, or fastx_toolkit, SeqKit supports a wider range of functions including:

    • Format Support: Multi-line FASTA, FASTQ, and Multi-line FASTQ.
    • Sequence Operations: Searching by motifs, locating motifs, sampling, shuffling, and removing duplicates.
    • Sequence Transformation: Transcription, translation, and cleaning bases.
    • File Handling: Reading from STDIN, reading/writing gzipped files, and cross-platform compatibility.
    • Advanced Filtering: Filtering by size (indirectly) and renaming headers.
  6. Quick Guide to SeqKit Subcommands

    master

    SeqKit provides a wide range of subcommands categorized by functionality:

    • Basic operations: seq, stats, subseq, sliding, faidx, translate, watch, sana, scat
    • Format conversion: fq2fa, fa2fq, fx2tab, tab2fx, convert
    • Searching: grep, locate, amplicon, fish
    • Set operations: sample, sample2, rmdup, common, duplicate, split, split2, head, head-genome, range, pair
    • Editing: concat, replace, restart, mutate, rename
    • Ordering: sort, shuffle
    • BAM processing: bam
    • Others: sum, merge-slides
  7. Compression support and levels in SeqKit

    master

    SeqKit supports high-speed reading and writing of compressed files. It uses the pgzip package for gzip, which is significantly faster than piping to pigz or gzip manually.

    Supported Formats and Compression Levels

    FormatRangeDefaultNotes
    gzip1-95Uses pgzip
    xzNANANot supported
    zstd1-42Roughly equals zstd 1, 3, 7, 11
    bzip21-96Supported since v2.4.0

    Use the --compress-level flag to adjust these values.

  8. How sequence type detection works

    master

    By default, seqkit seq automatically detects the sequence type (DNA, RNA, or Protein) based on the characters present in the file. You can verify this using seqkit stats.

    If you need to force a specific sequence type, use the -t or --seq-type flag. Note that this flag only takes effect on the seq and locate subcommands. When -t is used, the -v (--validate-seq) flag is automatically enabled to ensure the sequence matches the specified alphabet.

    Example of forcing DNA type:

    echo -e ">seq\nabcdefghijklmnpqrstvwyz" | seqkit seq -t dna
  9. Use FASTA Indexing for Large Files

    master

    For commands like subseq, split, sort, and shuffle, SeqKit can use a FASTA index to enable rapid access and reduce memory usage. This is particularly useful when using the --two-pass (-2) flag for large files.

    Important: The .seqkit.fai index files created by SeqKit are different from samtools .fai files; SeqKit uses the full sequence header as the key instead of just the ID.

  10. Understand SeqKit strand-sensitivity and multi-threading

    master

    When using SeqKit subcommands, you may encounter settings for strand-sensitivity and multi-threading:

    Strand-sensitivity

    • + only: The command only processes the positive/forward strand.
    • + and -: The command searches on both strands.
    • + or/and -: The behavior depends on the specific flags, options, or arguments provided by the user.

    Multi-threads

    SeqKit uses multiple threads to accelerate processing. While the default of 4 threads is sufficient for most commands, certain commands can benefit significantly from additional threads. Look for the symbol in the subcommand reference table to identify which commands support multi-threading.

  11. Understand how `seqkit sample` handles sampling by proportion and amount

    master

    The seqkit sample command supports two modes of sampling:

    1. Sampling by proportion (-p / --proportion): SeqKit returns a record if a generated random number in the range [0, 1) is less than the specified proportion P.
    2. Sampling by amount (-n / --number): SeqKit first calculates the total number of records, computes the equivalent proportion P, and then performs sampling by proportion.

    Important Note on Accuracy: Because SeqKit uses pseudorandom numbers, the actual number of sampled records when using the amount (-n) flag may not exactly equal the requested number N. This behavior is influenced by the random seed provided via the -s or --rand-seed flag.

  12. How sequence region indexing works in `seqkit split`

    master

    When using the -r/--by-region flag, regions are defined using a 1-based index. You can use positive indices for the start of the sequence or negative indices to count from the end.

    Indexing Examples:

    TypeIndex ExampleResulting Subsequence
    1-based index1:1First base
    1-based index2:4Bases 2 through 4
    1-based index1:-1All bases except the last one
    Negative index-4:-24th to 2nd base from the end
    Negative index-1:-1The very last base
    Mixed2:-2From base 2 up to the 2nd to last base