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
e7e76b1a
Commit
e7e76b1a
authored
1 year ago
by
Martin Larralde
Browse files
Options
Downloads
Patches
Plain Diff
Add proper `Display` trait implementation for `EncodedSequence`
parent
8e940621
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lightmotif/benches/ecoli.rs
+4
-6
4 additions, 6 deletions
lightmotif/benches/ecoli.rs
lightmotif/src/seq.rs
+35
-7
35 additions, 7 deletions
lightmotif/src/seq.rs
lightmotif/tests/dna.rs
+3
-4
3 additions, 4 deletions
lightmotif/tests/dna.rs
with
42 additions
and
17 deletions
lightmotif/benches/ecoli.rs
+
4
−
6
View file @
e7e76b1a
...
...
@@ -3,14 +3,13 @@
extern
crate
lightmotif
;
extern
crate
test
;
use
std
::
str
::
FromStr
;
use
lightmotif
::
abc
::
Dna
;
use
lightmotif
::
pli
::
Pipeline
;
use
lightmotif
::
pli
::
Score
;
use
lightmotif
::
pli
::
StripedScores
;
use
lightmotif
::
pwm
::
CountMatrix
;
use
lightmotif
::
seq
::
EncodedSequence
;
use
lightmotif
::
seq
::
StripedSequence
;
use
lightmotif
::
utils
::
StrictlyPositive
;
use
typenum
::
consts
::
U16
;
use
typenum
::
consts
::
U32
;
...
...
@@ -18,12 +17,11 @@ use typenum::consts::U32;
const
SEQUENCE
:
&
str
=
include_str!
(
"ecoli.txt"
);
fn
bench
<
C
:
StrictlyPositive
,
P
:
Score
<
Dna
,
C
>>
(
bencher
:
&
mut
test
::
Bencher
,
pli
:
&
P
)
{
let
encoded
=
EncodedSequence
::
<
Dna
>
::
from_str
(
SEQUENCE
)
.unwrap
();
let
mut
striped
=
encoded
.to_striped
::
<
C
>
();
let
mut
striped
=
StripedSequence
::
<
Dna
,
C
>
::
encode
(
SEQUENCE
)
.unwrap
();
let
cm
=
CountMatrix
::
<
Dna
>
::
from_sequences
(
&
[
EncodedSequence
::
from_str
(
"GTTGACCTTATCAAC"
)
.unwrap
(),
EncodedSequence
::
from_str
(
"GTTGATCCAGTCAAC"
)
.unwrap
(),
EncodedSequence
::
encode
(
"GTTGACCTTATCAAC"
)
.unwrap
(),
EncodedSequence
::
encode
(
"GTTGATCCAGTCAAC"
)
.unwrap
(),
])
.unwrap
();
let
pbm
=
cm
.to_freq
(
0.1
);
...
...
This diff is collapsed.
Click to expand it.
lightmotif/src/seq.rs
+
35
−
7
View file @
e7e76b1a
//! Linear and striped storage for alphabet-encoded sequences.
use
std
::
fmt
::
Display
;
use
std
::
fmt
::
Formatter
;
use
std
::
fmt
::
Result
as
FmtResult
;
use
std
::
str
::
FromStr
;
use
std
::
string
::
ToString
;
use
typenum
::
marker_traits
::
NonZero
;
use
typenum
::
marker_traits
::
Unsigned
;
...
...
@@ -90,6 +92,15 @@ impl<A: Alphabet> AsRef<[<A as Alphabet>::Symbol]> for EncodedSequence<A> {
}
}
impl
<
A
:
Alphabet
>
Display
for
EncodedSequence
<
A
>
{
fn
fmt
(
&
self
,
f
:
&
mut
Formatter
)
->
FmtResult
{
for
c
in
self
.data
.iter
()
{
write!
(
f
,
"{}"
,
c
.as_char
())
?
;
}
Ok
(())
}
}
impl
<
A
:
Alphabet
>
FromStr
for
EncodedSequence
<
A
>
{
type
Err
=
InvalidSymbol
;
fn
from_str
(
seq
:
&
str
)
->
Result
<
Self
,
Self
::
Err
>
{
...
...
@@ -106,12 +117,6 @@ impl<'a, A: Alphabet> IntoIterator for &'a EncodedSequence<A> {
}
}
impl
<
A
:
Alphabet
>
ToString
for
EncodedSequence
<
A
>
{
fn
to_string
(
&
self
)
->
String
{
self
.to_string
()
}
}
// --- StripedSequence ---------------------------------------------------------
/// An encoded sequence stored in a striped matrix with a fixed column count.
...
...
@@ -124,6 +129,22 @@ pub struct StripedSequence<A: Alphabet, C: StrictlyPositive> {
}
impl
<
A
:
Alphabet
,
C
:
StrictlyPositive
>
StripedSequence
<
A
,
C
>
{
/// Create a new striped sequence from a textual representation.
pub
fn
encode
(
sequence
:
&
str
)
->
Result
<
Self
,
InvalidSymbol
>
{
let
length
=
sequence
.len
();
let
n
=
(
length
+
(
C
::
USIZE
-
1
))
/
C
::
USIZE
;
let
mut
data
=
DenseMatrix
::
new
(
n
);
for
(
i
,
x
)
in
sequence
.chars
()
.enumerate
()
{
data
[
i
%
n
][
i
/
n
]
=
A
::
Symbol
::
from_char
(
x
)
?
;
}
Ok
(
StripedSequence
{
alphabet
:
std
::
marker
::
PhantomData
,
data
,
length
,
wrap
:
0
,
})
}
/// Reconfigure the striped sequence for searching with a motif.
pub
fn
configure
(
&
mut
self
,
motif
:
&
ScoringMatrix
<
A
>
)
{
if
motif
.len
()
>
0
{
...
...
@@ -158,6 +179,13 @@ impl<A: Alphabet, C: StrictlyPositive> From<EncodedSequence<A>> for StripedSeque
}
}
impl
<
A
:
Alphabet
,
C
:
StrictlyPositive
>
FromStr
for
StripedSequence
<
A
,
C
>
{
type
Err
=
InvalidSymbol
;
fn
from_str
(
seq
:
&
str
)
->
Result
<
Self
,
Self
::
Err
>
{
Self
::
encode
(
seq
)
}
}
#[cfg(test)]
mod
test
{
use
typenum
::
consts
::
U2
;
...
...
This diff is collapsed.
Click to expand it.
lightmotif/tests/dna.rs
+
3
−
4
View file @
e7e76b1a
...
...
@@ -8,6 +8,7 @@ use lightmotif::CountMatrix;
use
lightmotif
::
Dna
;
use
lightmotif
::
EncodedSequence
;
use
lightmotif
::
Pipeline
;
use
lightmotif
::
StripedSequence
;
use
typenum
::
consts
::
U1
;
use
typenum
::
consts
::
U16
;
...
...
@@ -35,8 +36,7 @@ const EXPECTED: &[f32] = &[
];
fn
test_score
<
C
:
StrictlyPositive
,
P
:
Score
<
Dna
,
C
>>
(
pli
:
&
P
)
{
let
encoded
=
EncodedSequence
::
<
Dna
>
::
encode
(
SEQUENCE
)
.unwrap
();
let
mut
striped
=
encoded
.to_striped
::
<
C
>
();
let
mut
striped
=
StripedSequence
::
<
Dna
,
C
>
::
encode
(
SEQUENCE
)
.unwrap
();
let
cm
=
CountMatrix
::
<
Dna
>
::
from_sequences
(
PATTERNS
.iter
()
.map
(|
x
|
EncodedSequence
::
encode
(
x
)
.unwrap
()),
...
...
@@ -63,8 +63,7 @@ fn test_score<C: StrictlyPositive, P: Score<Dna, C>>(pli: &P) {
}
fn
test_best_position
<
C
:
StrictlyPositive
,
P
:
Score
<
Dna
,
C
>
+
BestPosition
<
C
>>
(
pli
:
&
P
)
{
let
encoded
=
EncodedSequence
::
<
Dna
>
::
encode
(
SEQUENCE
)
.unwrap
();
let
mut
striped
=
encoded
.to_striped
();
let
mut
striped
=
StripedSequence
::
<
Dna
,
C
>
::
encode
(
SEQUENCE
)
.unwrap
();
let
cm
=
CountMatrix
::
<
Dna
>
::
from_sequences
(
PATTERNS
.iter
()
.map
(|
x
|
EncodedSequence
::
encode
(
x
)
.unwrap
()),
...
...
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