Skip to content
Snippets Groups Projects
Commit 4b468e06 authored by Martin Larralde's avatar Martin Larralde
Browse files

Document methods of `jaspar16::Record` in `lightmotif-io`

parent ba238696
No related branches found
No related tags found
No related merge requests found
......@@ -24,7 +24,7 @@ PSSM file formats, including:
- [x] [TRANSFAC](https://en.wikipedia.org/wiki/TRANSFAC)-formatted records,
with associated metadata.
- [x] [JASPAR](https://jaspar.elixir.no/docs/) count matrices
(in JASPAR 2016 bracketed format) with their record header.
(in JASPAR 2016 bracketed format or raw format) with their record header.
- [x] [UniPROBE](http://the_brain.bwh.harvard.edu/uniprobe/index.php)
frequency matrices with their record header.
- [ ] [MEME minimal](https://meme-suite.org/meme/doc/meme-format.html) records
......
......@@ -62,6 +62,7 @@ impl AsRef<CountMatrix<Dna>> for Record {
// ---
/// An iterative reader for the JASPAR format.
pub struct Reader<B: BufRead> {
buffer: Vec<u8>,
bufread: B,
......@@ -69,6 +70,7 @@ pub struct Reader<B: BufRead> {
}
impl<B: BufRead> Reader<B> {
/// Create a new `Reader` from a buffered reader.
pub fn new(mut reader: B) -> Self {
let mut buffer = Vec::new();
let start = reader.read_until(b'>', &mut buffer).unwrap_or(1) - 1;
......@@ -121,6 +123,7 @@ impl<B: BufRead> Iterator for Reader<B> {
}
}
/// Read the records from a file in JASPAR format.
pub fn read<B: BufRead>(reader: B) -> self::Reader<B> {
self::Reader::new(reader)
}
......
......@@ -35,14 +35,17 @@ pub struct Record<A: Alphabet> {
}
impl<A: Alphabet> Record<A> {
/// Get the identifier of the record.
pub fn id(&self) -> &str {
&self.id
}
/// Get the description of the record, if any.
pub fn description(&self) -> Option<&str> {
self.description.as_deref()
}
/// Get the count matrix of the record.
pub fn matrix(&self) -> &CountMatrix<A> {
&self.matrix
}
......@@ -56,6 +59,7 @@ impl<A: Alphabet> AsRef<CountMatrix<A>> for Record<A> {
// ---
/// An iterative reader for the JASPAR (2016) format.
pub struct Reader<B: BufRead, A: Alphabet> {
buffer: Vec<u8>,
bufread: B,
......@@ -117,6 +121,7 @@ impl<B: BufRead, A: Alphabet> Iterator for Reader<B, A> {
}
}
/// Read the records from a file in JASPAR (2016) format.
pub fn read<B: BufRead, A: Alphabet>(reader: B) -> self::Reader<B, A> {
self::Reader::new(reader)
}
......
......@@ -25,26 +25,32 @@ pub struct Record<A: Alphabet> {
}
impl<A: Alphabet> Record<A> {
/// The identifier of the record, if any.
pub fn id(&self) -> Option<&str> {
self.id.as_deref()
}
/// The accession of the record, if any.
pub fn accession(&self) -> Option<&str> {
self.accession.as_deref()
}
/// The name of the record, if any.
pub fn name(&self) -> Option<&str> {
self.name.as_deref()
}
/// The description of the record, if any.
pub fn description(&self) -> Option<&str> {
self.description.as_deref()
}
/// The raw data found in the matrix.
pub fn data(&self) -> Option<&DenseMatrix<f32, A::K>> {
self.data.as_ref()
}
/// The raw data found in the matrix.
pub fn to_counts(&self) -> Option<CountMatrix<A>> {
if let Some(data) = &self.data {
let mut counts = DenseMatrix::<u32, A::K>::new(data.rows());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment