BedFormat

Trait BedFormat 

Source
pub trait BedFormat:
    Sized
    + Debug
    + Send
    + Sync
    + 'static {
    const FIELD_COUNT: usize;
    const SUPPORTS_STANDARD_READER: bool = true;

    // Required method
    fn from_fields(
        fields: &[&str],
        extras: Extras,
        line: usize,
    ) -> ReaderResult<Self>;
}
Expand description

A trait for defining custom BED record types.

This trait is implemented by the built-in BED record types (Bed3, Bed4, etc.) and can be used to define custom BED formats with a different number of fields.

§Example

use genepred::bed::{BedFormat, Bed3};
use genepred::reader::{Reader, ReaderResult};
use genepred::genepred::Extras;

// A custom BED format with only the chromosome and score.
#[derive(Debug, Clone, PartialEq, Eq)]
struct MyBed {
   chrom: Vec<u8>,
   score: u16,
}

impl BedFormat for MyBed {
    const FIELD_COUNT: usize = 2;
    const SUPPORTS_STANDARD_READER: bool = false;

    fn from_fields(fields: &[&str], extras: Extras, line: usize) -> ReaderResult<Self> {
        Ok(Self {
            chrom: fields[0].as_bytes().to_vec(),
            score: fields[1].parse().unwrap(),
        })
    }
}

Required Associated Constants§

Source

const FIELD_COUNT: usize

The number of fields in the BED record.

Provided Associated Constants§

Source

const SUPPORTS_STANDARD_READER: bool = true

Indicates whether the shared Reader implementation can parse this format line-by-line using the standard BED parser.

Required Methods§

Source

fn from_fields( fields: &[&str], extras: Extras, line: usize, ) -> ReaderResult<Self>

Creates a new record from a slice of fields.

§Arguments
  • fields - A slice of strings representing the fields of the BED record.
  • extras - A map of additional column identifiers to their raw byte values, representing any columns beyond the standard BED fields.
  • line - The line number of the record in the input file.
§Returns

A ReaderResult containing the new record, or a ReaderError if the record could not be parsed.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§