diff --git a/lightmotif-io/README.md b/lightmotif-io/README.md index 41a8614675c52cd4ea09ef45a9dd5692eb4e1d70..b366fb7c9d7e59870317ee3dac0f095486d78b0d 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 58a1cac1da01cb11938cdd70a59d686463058fe9..5154cd97959b583923c96722e86f21c5e2f250af 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 1eae03b52ec191018810d61399b2581334b74462..702f42f09756aaf9e40f46a5be485ba86f20c24d 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 8679369eb9994d659a204435c781e3131379f3c0..42b7ef7a0c96705998e30d3e2413569e9839f94e 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());