Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LightMotif
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Larralde
LightMotif
Commits
b5ac2896
Commit
b5ac2896
authored
1 year ago
by
Martin Larralde
Browse files
Options
Downloads
Patches
Plain Diff
Add trait to count the number of symbol occurences in an arbitrary collection
parent
0a68afc6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lightmotif/src/seq.rs
+25
-3
25 additions, 3 deletions
lightmotif/src/seq.rs
with
25 additions
and
3 deletions
lightmotif/src/seq.rs
+
25
−
3
View file @
b5ac2896
...
...
@@ -18,6 +18,19 @@ use super::err::InvalidSymbol;
use
super
::
num
::
StrictlyPositive
;
use
super
::
pwm
::
ScoringMatrix
;
// --- SymbolCount -------------------------------------------------------------
/// A trait for counting the number of occurences of a symbol in a sequence.
pub
trait
SymbolCount
<
A
:
Alphabet
>
{
fn
count_symbol
(
&
self
,
symbol
:
<
A
as
Alphabet
>
::
Symbol
)
->
usize
;
}
impl
<
'a
,
A
:
Alphabet
,
T
:
IntoIterator
<
Item
=
&
'a
A
::
Symbol
>
+
Copy
>
SymbolCount
<
A
>
for
T
{
fn
count_symbol
(
&
self
,
symbol
:
<
A
as
Alphabet
>
::
Symbol
)
->
usize
{
self
.into_iter
()
.filter
(|
&&
c
|
c
==
symbol
)
.count
()
}
}
// --- EncodedSequence ---------------------------------------------------------
/// A biological sequence encoded with an alphabet.
...
...
@@ -53,8 +66,8 @@ impl<A: Alphabet> EncodedSequence<A> {
/// Iterate over the symbols in the sequence.
#[inline]
pub
fn
iter
(
&
self
)
->
impl
IntoIterator
<
Item
=
&
A
::
Symbol
>
{
self
.data
.iter
()
pub
fn
iter
(
&
self
)
->
<&
[
A
::
Symbol
]
as
IntoIterator
>
::
IntoIter
{
self
.data
.
as_slice
()
.into_
iter
()
}
/// Convert the encoded sequence to a striped matrix.
...
...
@@ -233,7 +246,7 @@ impl<A: Alphabet, C: StrictlyPositive> AsRef<StripedSequence<A, C>> for StripedS
}
}
impl
<
A
:
Alphabet
,
C
:
Unsigned
+
NonZero
>
Index
<
usize
>
for
StripedSequence
<
A
,
C
>
{
impl
<
A
:
Alphabet
,
C
:
StrictlyPositive
>
Index
<
usize
>
for
StripedSequence
<
A
,
C
>
{
type
Output
=
<
A
as
Alphabet
>
::
Symbol
;
#[inline]
fn
index
(
&
self
,
index
:
usize
)
->
&
Self
::
Output
{
...
...
@@ -244,6 +257,15 @@ impl<A: Alphabet, C: Unsigned + NonZero> Index<usize> for StripedSequence<A, C>
}
}
impl
<
A
:
Alphabet
,
C
:
StrictlyPositive
>
SymbolCount
<
A
>
for
&
StripedSequence
<
A
,
C
>
{
fn
count_symbol
(
&
self
,
symbol
:
<
A
as
Alphabet
>
::
Symbol
)
->
usize
{
self
.data
.iter
()
.map
(|
row
|
SymbolCount
::
<
A
>
::
count_symbol
(
&
row
,
symbol
))
.sum
()
}
}
#[cfg(test)]
mod
test
{
use
typenum
::
consts
::
U2
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment