Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
baseLess
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
Lannoy, Carlos de
baseLess
Commits
c9b50ef2
Commit
c9b50ef2
authored
3 years ago
by
Noordijk, Ben
Browse files
Options
Downloads
Patches
Plain Diff
In silico mixtures can now be made
parent
9eda77b2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
coa_detection/in_silico_mixture.py
+26
-11
26 additions, 11 deletions
coa_detection/in_silico_mixture.py
with
26 additions
and
11 deletions
coa_detection/in_silico_mixture.py
+
26
−
11
View file @
c9b50ef2
...
...
@@ -3,7 +3,7 @@ from pathlib import Path
import
numpy
as
np
import
random
import
matplotlib.pyplot
as
plt
from
pyabf.abfWriter
import
writeABF1
class
InSilicoGenerator
:
def
__init__
(
self
,
file_list
):
...
...
@@ -32,35 +32,48 @@ class InSilicoGenerator:
elif
'
A6
'
in
file
.
name
:
self
.
coa6
.
append
(
AbfData
(
file
))
def
fill_squiggle
(
self
,
coa4_ratio
,
coa5_ratio
,
coa6_ratio
,
unfiltered
=
True
):
def
fill_squiggle
(
self
,
coa4_count
,
coa5_count
,
coa6_count
,
unfiltered
=
True
,
insert_prob
=
0.95
):
"""
:param coa4_
ratio
: number of coa4 events
:param coa5_
ratio
: number of coa5 events
:param coa6_
ratio
: number of coa6 events
:param coa4_
count
: number of coa4 events
:param coa5_
count
: number of coa5 events
:param coa6_
count
: number of coa6 events
"""
current_index
=
0
# Just start with some noise first
# Keep track of how many coa4,5,6 are inserted into the squiggle and what the target count is
count_dict
=
{
4
:
[
0
,
coa4_count
],
5
:
[
0
,
coa5_count
],
6
:
[
0
,
coa6_count
]}
while
current_index
<
len
(
self
.
squiggle
):
fragment_width
=
random
.
randint
(
100
,
3000
)
coa_type
=
random
.
choice
(
self
.
all_coas
)
fragment_id
=
1
# TODO base this on coa type that is chosen
coa_object
=
random
.
choice
(
coa_type
)
positive_example
=
random
.
choice
([
True
,
False
])
fragment_id
=
int
(
coa_object
.
abf_fn
.
stem
[
-
1
])
if
count_dict
[
fragment_id
][
0
]
<
count_dict
[
fragment_id
][
1
]:
positive_example
=
random
.
random
()
>
insert_prob
else
:
positive_example
=
False
if
current_index
+
fragment_width
>
self
.
squiggle_length
:
# Edge case: always fill final bit of squiggle with noise
positive_example
=
False
fragment_width
=
self
.
squiggle_length
-
current_index
if
positive_example
:
squiggle_fragment
=
coa_object
.
get_pos
(
fragment_width
,
unfiltered
=
unfiltered
)
# TODO this might not match up with real data
unfiltered
=
unfiltered
)
count_dict
[
fragment_id
][
0
]
+=
1
else
:
squiggle_fragment
=
coa_object
.
get_neg
(
fragment_width
,
unfiltered
=
unfiltered
)
nb_neg
=
1
,
unfiltered
=
unfiltered
)[
0
]
fragment_id
*=
-
1
end_index
=
current_index
+
fragment_width
self
.
squiggle
[
current_index
:
end_index
]
=
squiggle_fragment
self
.
ground_truth_vector
[
current_index
:
end_index
]
=
fragment_id
current_index
+=
fragment_width
print
(
'
cOA type: [number of events in in silico squiggle, target number]
'
)
print
(
count_dict
)
print
(
'
If it is too far off, change insert_prob
'
)
return
self
.
squiggle
,
self
.
ground_truth_vector
...
...
@@ -69,6 +82,8 @@ if __name__ == '__main__':
Path
(
r
"
/mnt/c/Users/benno/Downloads/zooi/+120mV_cOA5.abf
"
),
Path
(
r
"
/mnt/c/Users/benno/Downloads/zooi/+120mV_cOA6.abf
"
)]
generator
=
InSilicoGenerator
(
files
)
simulated_squiggle
,
ground_truth
=
generator
.
fill_squiggle
(
1
,
2
,
3
)
simulated_squiggle
,
ground_truth
=
generator
.
fill_squiggle
(
30
,
30
,
3
0
)
plt
.
plot
(
simulated_squiggle
)
plt
.
show
()
# simulated_squiggle = np.reshape(simulated_squiggle, (-1, 1))
# writeABF1(simulated_squiggle, r'/mnt/c/Users/benno/PycharmProjects/baseless/coa_detection/output_test.abf', 50000)
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