Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Terminal fragment selector
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
zavolan_group
tools
Terminal fragment selector
Commits
7d9f2581
Commit
7d9f2581
authored
2 years ago
by
Hugo Madge Leon
Browse files
Options
Downloads
Patches
Plain Diff
remove old code
parent
be213a4e
No related branches found
Branches containing commit
No related tags found
4 merge requests
!30
Hope this doesn't break
,
!29
directories fix
,
!28
Restructure directories
,
!27
remove old code
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
frag_package/fragmentation.py
+64
-36
64 additions, 36 deletions
frag_package/fragmentation.py
frag_package/fragmentation_v2.py
+0
-64
0 additions, 64 deletions
frag_package/fragmentation_v2.py
with
64 additions
and
100 deletions
frag_package/fragmentation.py
+
64
−
36
View file @
7d9f2581
import
random
dna_seq
=
{
"
ATAACATGTGGATGGCCAGTGGTCGGTTGTTACACGCCTACCGCGATGCTGAATGACCCGGACTAGAGTGGCGAAATTTATGGCGTGTGACCCGTTATGC
"
:
100
,
"
TCCATTTCGGTCAGTGGGTCATTGCTAGTAGTCGATTGCATTGCCATTCTCCGAGTGATTTAGCGTGACAGCCGCAGGGAACCCATAAAATGCAATCGTA
"
:
100
}
mean_length
=
12
std
=
1
term_frags
=
[]
for
seq
,
counts
in
dna_seq
.
items
():
for
_
in
range
(
counts
):
n_cuts
=
int
(
len
(
seq
)
/
mean_length
)
cuts
=
random
.
sample
(
range
(
1
,
len
(
seq
)
-
1
),
n_cuts
)
cuts
.
sort
()
cuts
.
insert
(
0
,
0
)
term_frag
=
""
for
i
,
val
in
enumerate
(
cuts
):
if
i
==
len
(
cuts
)
-
1
:
fragment
=
seq
[
val
:
cuts
[
-
1
]]
else
:
fragment
=
seq
[
val
:
cuts
[
i
+
1
]]
if
mean_length
-
std
<=
len
(
fragment
)
<=
mean_length
+
std
:
term_frag
=
fragment
if
term_frag
==
""
:
continue
else
:
term_frags
.
append
(
term_frag
)
with
open
(
'
terminal_frags.txt
'
,
'
w
'
)
as
f
:
for
line
in
term_frags
:
f
.
write
(
line
)
f
.
write
(
'
\n
'
)
import
re
import
numpy
as
np
import
pandas
as
pd
def
fasta_process
(
fasta_file
):
with
open
(
fasta_file
,
"
r
"
)
as
f
:
lines
=
f
.
readlines
()
ident_pattern
=
re
.
compile
(
'
>(\S+)
'
)
seq_pattern
=
re
.
compile
(
'
^(\S+)$
'
)
genes
=
{}
for
line
in
lines
:
if
ident_pattern
.
search
(
line
):
seq_id
=
(
ident_pattern
.
search
(
line
)).
group
(
1
)
elif
seq_id
in
genes
.
keys
():
genes
[
seq_id
]
+=
(
seq_pattern
.
search
(
line
)).
group
(
1
)
else
:
genes
[
seq_id
]
=
(
seq_pattern
.
search
(
line
)).
group
(
1
)
return
genes
def
fragmentation
(
fasta_file
,
counts_file
,
mean_length
,
std
,
a_prob
,
t_prob
,
g_prob
,
c_prob
):
fasta
=
fasta_process
(
fasta_file
)
seq_counts
=
pd
.
read_csv
(
counts_file
,
names
=
[
"
seqID
"
,
"
count
"
])
# nucs = ['A','T','G','C']
# mononuc_freqs = [0.22, 0.25, 0.23, 0.30]
nuc_probs
=
{
'
A
'
:
a_prob
,
'
T
'
:
t_prob
,
'
G
'
:
g_prob
,
'
C
'
:
c_prob
}
# calculated using https://www.nature.com/articles/srep04532#MOESM1
term_frags
=
[]
for
seq_id
,
seq
in
fasta
.
items
():
counts
=
seq_counts
[
seq_counts
[
"
seqID
"
]
==
seq_id
][
"
count
"
]
for
_
in
range
(
counts
):
n_cuts
=
int
(
len
(
seq
)
/
mean_length
)
# non-uniformly random DNA fragmentation implementation based on https://www.nature.com/articles/srep04532#Sec1
# assume fragmentation by sonication for NGS workflow
cuts
=
[]
cut_nucs
=
np
.
random
.
choice
(
list
(
nuc_probs
.
keys
()),
n_cuts
,
p
=
list
(
nuc_probs
.
values
()))
for
nuc
in
cut_nucs
:
nuc_pos
=
[
x
.
start
()
for
x
in
re
.
finditer
(
nuc
,
seq
)]
pos
=
np
.
random
.
choice
(
nuc_pos
)
while
pos
in
cuts
:
pos
=
np
.
random
.
choice
(
nuc_pos
)
cuts
.
append
(
pos
)
cuts
.
sort
()
cuts
.
insert
(
0
,
0
)
term_frag
=
""
for
i
,
val
in
enumerate
(
cuts
):
if
i
==
len
(
cuts
)
-
1
:
fragment
=
seq
[
val
+
1
:
cuts
[
-
1
]]
else
:
fragment
=
seq
[
val
:
cuts
[
i
+
1
]]
if
mean_length
-
std
<=
len
(
fragment
)
<=
mean_length
+
std
:
term_frag
=
fragment
if
term_frag
==
""
:
continue
else
:
term_frags
.
append
(
term_frag
)
return
term_frags
This diff is collapsed.
Click to expand it.
frag_package/fragmentation_v2.py
deleted
100644 → 0
+
0
−
64
View file @
be213a4e
import
re
import
numpy
as
np
import
pandas
as
pd
def
fasta_process
(
fasta_file
):
with
open
(
fasta_file
,
"
r
"
)
as
f
:
lines
=
f
.
readlines
()
ident_pattern
=
re
.
compile
(
'
>(\S+)
'
)
seq_pattern
=
re
.
compile
(
'
^(\S+)$
'
)
genes
=
{}
for
line
in
lines
:
if
ident_pattern
.
search
(
line
):
seq_id
=
(
ident_pattern
.
search
(
line
)).
group
(
1
)
elif
seq_id
in
genes
.
keys
():
genes
[
seq_id
]
+=
(
seq_pattern
.
search
(
line
)).
group
(
1
)
else
:
genes
[
seq_id
]
=
(
seq_pattern
.
search
(
line
)).
group
(
1
)
return
genes
def
fragmentation
(
fasta_file
,
counts_file
,
mean_length
,
std
,
a_prob
,
t_prob
,
g_prob
,
c_prob
):
fasta
=
fasta_process
(
fasta_file
)
seq_counts
=
pd
.
read_csv
(
counts_file
,
names
=
[
"
seqID
"
,
"
count
"
])
# nucs = ['A','T','G','C']
# mononuc_freqs = [0.22, 0.25, 0.23, 0.30]
nuc_probs
=
{
'
A
'
:
a_prob
,
'
T
'
:
t_prob
,
'
G
'
:
g_prob
,
'
C
'
:
c_prob
}
# calculated using https://www.nature.com/articles/srep04532#MOESM1
term_frags
=
[]
for
seq_id
,
seq
in
fasta
.
items
():
counts
=
seq_counts
[
seq_counts
[
"
seqID
"
]
==
seq_id
][
"
count
"
]
for
_
in
range
(
counts
):
n_cuts
=
int
(
len
(
seq
)
/
mean_length
)
# non-uniformly random DNA fragmentation implementation based on https://www.nature.com/articles/srep04532#Sec1
# assume fragmentation by sonication for NGS workflow
cuts
=
[]
cut_nucs
=
np
.
random
.
choice
(
list
(
nuc_probs
.
keys
()),
n_cuts
,
p
=
list
(
nuc_probs
.
values
()))
for
nuc
in
cut_nucs
:
nuc_pos
=
[
x
.
start
()
for
x
in
re
.
finditer
(
nuc
,
seq
)]
pos
=
np
.
random
.
choice
(
nuc_pos
)
while
pos
in
cuts
:
pos
=
np
.
random
.
choice
(
nuc_pos
)
cuts
.
append
(
pos
)
cuts
.
sort
()
cuts
.
insert
(
0
,
0
)
term_frag
=
""
for
i
,
val
in
enumerate
(
cuts
):
if
i
==
len
(
cuts
)
-
1
:
fragment
=
seq
[
val
+
1
:
cuts
[
-
1
]]
else
:
fragment
=
seq
[
val
:
cuts
[
i
+
1
]]
if
mean_length
-
std
<=
len
(
fragment
)
<=
mean_length
+
std
:
term_frag
=
fragment
if
term_frag
==
""
:
continue
else
:
term_frags
.
append
(
term_frag
)
return
term_frags
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