From 4b468e06e43c4ee1b75e8ab506be98b433b6423b Mon Sep 17 00:00:00 2001 From: Martin Larralde <martin.larralde@embl.de> Date: Mon, 17 Jun 2024 14:00:18 +0200 Subject: [PATCH] Document methods of `jaspar16::Record` in `lightmotif-io` --- lightmotif-io/README.md | 2 +- lightmotif-io/src/jaspar/mod.rs | 3 +++ lightmotif-io/src/jaspar16/mod.rs | 5 +++++ lightmotif-io/src/transfac/mod.rs | 6 ++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lightmotif-io/README.md b/lightmotif-io/README.md index 41a8614..b366fb7 100644 --- a/lightmotif-io/README.md +++ b/lightmotif-io/README.md @@ -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 diff --git a/lightmotif-io/src/jaspar/mod.rs b/lightmotif-io/src/jaspar/mod.rs index 58a1cac..5154cd9 100644 --- a/lightmotif-io/src/jaspar/mod.rs +++ b/lightmotif-io/src/jaspar/mod.rs @@ -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) } diff --git a/lightmotif-io/src/jaspar16/mod.rs b/lightmotif-io/src/jaspar16/mod.rs index 1eae03b..702f42f 100644 --- a/lightmotif-io/src/jaspar16/mod.rs +++ b/lightmotif-io/src/jaspar16/mod.rs @@ -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) } diff --git a/lightmotif-io/src/transfac/mod.rs b/lightmotif-io/src/transfac/mod.rs index 8679369..42b7ef7 100644 --- a/lightmotif-io/src/transfac/mod.rs +++ b/lightmotif-io/src/transfac/mod.rs @@ -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()); -- GitLab