Skip to main content

GAFBase

Struct GAFBase 

Source
pub struct GAFBase { /* private fields */ }
Expand description

A database connection to a GAF-base database.

This structure stores a database connection and some header information. In multi-threaded applications, each thread should have its own connection. A set of alignments overlapping with a subgraph can be extracted using the crate::ReadSet structure.

§Examples

use gbz_base::{GAFBase, GAFBaseParams, GraphReference};
use gbz_base::utils;
use simple_sds::serialize;

let gaf_file = utils::get_test_data("micb-kir3dl1_HG003.gaf.gz");
let gbwt_file = None; // Build a new GBWT index.
let db_file = serialize::temp_file_name("gaf-base");

// Create a database that requires a reference graph to use.
let graph = GraphReference::None;
let params = GAFBaseParams::default();
let db = GAFBase::create_from_files(&gaf_file, gbwt_file, &db_file, graph, &params);
assert!(db.is_ok());

// Now open it and check some statistics.
let db = GAFBase::open(&db_file);
assert!(db.is_ok());
let db = db.unwrap();
assert_eq!(db.nodes(), 2291);
assert_eq!(db.alignments(), 12439);
assert!(!db.bidirectional_gbwt());

drop(db);
let _ = std::fs::remove_file(&db_file);

Implementations§

Source§

impl GAFBase

Using the database.

Source

pub const VERSION: &'static str = "GAF-base version 3"

Current database version.

Source

pub fn open<P: AsRef<Path>>(filename: P) -> Result<Self, String>

Opens a connection to the database in the given file.

Reads the header information and passes through any database errors.

Source

pub fn filename(&self) -> Option<&str>

Returns the filename of the database or an error if there is no filename.

Source

pub fn file_size(&self) -> Option<String>

Returns the size of the database file in a human-readable format.

Source

pub fn version(&self) -> &str

Returns the version of the database.

Source

pub fn nodes(&self) -> usize

Returns the number of nodes in the graph.

Source

pub fn alignments(&self) -> usize

Returns the number of alignments in the database.

Source

pub fn blocks(&self) -> usize

Returns the number of database rows storing the alignments.

Each row corresponds to an AlignmentBlock.

Source

pub fn bidirectional_gbwt(&self) -> bool

Returns true if the paths are stored in a bidirectional GBWT.

Source

pub fn tags(&self) -> &Tags

Returns all tags stored in the database.

Source

pub fn graph_name(&self) -> Result<GraphName, String>

Returns the stable graph name (pggname) for the graph used as the reference for the alignments.

Returns an error if the tags cannot be parsed.

Source§

impl GAFBase

Creating the database.

Source

pub fn create_from_files( gaf_file: &Path, gbwt_file: Option<&Path>, db_file: &Path, graph: GraphReference<'_, '_>, params: &GAFBaseParams, ) -> Result<(), String>

Creates a new database from the alignments in file gaf_file and stores the database in file db_file.

A unidirectional or bidirectional GBWT index can be provided in file gbwt_file. Path i in the GBWT index corresponds to line i in the GAF file. If a GBWT file is not provided, a new unidirectional index will be built in the background. This will use a significant amount of memory, but it should not be the bottleneck of the construction.

If the parameters indicate that node sequences should be stored in the database, a GBZ-compatible graph must be provided.

§Arguments
  • gaf_file: GAF file storing the alignments. Can be gzip-compressed.
  • gbwt_file: An optional GBWT file storing the target paths.
  • db_file: Output database file.
  • graph: A GBZ-compatible graph for building a reference-free database, or GraphReference::None for a reference-based one.
  • params: Construction parameters.
§Errors

Returns an error, if:

  • The GAF file does not exist.
  • The database already exists.
  • Trying to build a reference-free GAF-base without a graph.
  • The graph is not a valid reference for the alignments.

Passes through any I/O, database, and construction errors.

Source

pub fn create<P: AsRef<Path>, Q: AsRef<Path>>( gaf_file: P, index: Option<Arc<GBWT>>, db_file: Q, graph: GraphReference<'_, '_>, params: &GAFBaseParams, ) -> Result<(), String>

Creates a new database from the alignments in file gaf_file and stores the database in file db_file.

A unidirectional or bidirectional GBWT index can be provided. Path i in the GBWT index corresponds to line i in the GAF file. If a GBWT index is not provided, a new unidirectional index will be built in the background. This will use a significant amount of memory, but it should not be the bottleneck of the construction.

If the parameters indicate that node sequences should be stored in the database, a GBZ-compatible graph must be provided.

§Arguments
  • gaf_file: GAF file storing the alignments. Can be gzip-compressed.
  • index: An optional GBWT index storing the target paths.
  • db_file: Output database file.
  • graph: A GBZ-compatible graph for building a reference-free database, or GraphReference::None for a reference-based one.
  • params: Construction parameters.
§Errors

Returns an error, if:

  • The GAF file does not exist.
  • The database already exists.
  • Trying to build a reference-free GAF-base without a graph.
  • The graph is not a valid reference for the alignments.

Passes through any I/O, database, and construction errors.

Trait Implementations§

Source§

impl Debug for GAFBase

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.