Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scRNA-seq-simulation
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
pipelines
scRNA-seq-simulation
Merge requests
!17
Issue 7
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
Issue 7
issue_7
into
main
Overview
30
Commits
37
Pipelines
10
Changes
3
3 unresolved threads
Hide all comments
Closed
Kathleen Moriarty
requested to merge
issue_7
into
main
3 years ago
Overview
30
Commits
37
Pipelines
10
Changes
3
3 unresolved threads
Hide all comments
Expand
0
0
Merge request reports
Compare
main
version 9
31915d91
3 years ago
version 8
59e66531
3 years ago
version 7
301e9f23
3 years ago
version 6
ce67ac87
3 years ago
version 5
d715c366
3 years ago
version 4
66c502ef
3 years ago
version 3
36474d3f
3 years ago
version 2
eea24234
3 years ago
version 1
8ce34674
3 years ago
main (base)
and
version 4
latest version
89da273b
37 commits,
3 years ago
version 9
31915d91
36 commits,
3 years ago
version 8
59e66531
35 commits,
3 years ago
version 7
301e9f23
34 commits,
3 years ago
version 6
ce67ac87
33 commits,
3 years ago
version 5
d715c366
31 commits,
3 years ago
version 4
66c502ef
13 commits,
3 years ago
version 3
36474d3f
13 commits,
3 years ago
version 2
eea24234
11 commits,
3 years ago
version 1
8ce34674
6 commits,
3 years ago
3 files
+
134
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
src/read_sequencing.py
0 → 100644
+
98
−
0
Options
"""
Read Sequencing.
Simulate the sequencing of reads on the template of terminal fragments and simulates reads of these fragments.
Author: Kathleen Moriarty
"""
# Imports from built-in modules
from
random
import
choices
from
typing
import
List
from
pathlib
import
Path
def
read_sequencing
(
frag_file_name
:
Path
,
output_file_name
:
Path
=
Path
.
cwd
()
/
'
output_reads.txt
'
,
num_reads
:
int
=
1000
,
read_len
:
int
=
80
,
)
->
None
:
"""
Reads a fasta-formatted file of terminal fragments and simulates reads.
Simulate the sequencing of reads on the template of terminal
fragments. Reads are copies of fixed length starting
from the 5
'
end of fragments. If the desired read length
is larger than the fragment length, sequencing would in
principle proceed into the 3
'
adaptor and then would perhaps
yield random bases. For simplicity, here we assume that random
nucleotides are introduced in this case. Saves a fasta-formatted
file of reads of identical length, representing 5’
ends of the terminal fragments as .txt.
Args:
frag_file_name: input file path of terminal fragments
output_file_name: output file path where to store the output
num_reads: number of total reads to simulate
read_len: integer of identical read length
"""
# Read data from terminal fragment file
# Store fragment descriptions in a list
frag_desc
=
[]
# type: List[str]
with
open
(
frag_file_name
,
'
r
'
)
as
f
:
frag_line
=
f
.
readline
()
# Store all fragments as a list to parse later
frag_list
=
[]
# type: List[str]
# Store combined fragment lines
frag_str
=
""
while
frag_line
!=
""
:
# To stop when the end of file is reached
if
frag_line
.
startswith
(
'
>
'
):
# Determine if this is the first fragment in the file
# Ignore the description line (starting with >) of the first fragment
if
not
(
len
(
frag_list
)
==
0
and
frag_str
==
""
):
# Not the first fragment. Append to list.
frag_list
.
append
(
frag_str
)
frag_str
=
""
# Store description line for output file
frag_desc
.
append
(
frag_line
)
else
:
frag_str
=
frag_str
+
frag_line
.
rstrip
(
"
\n
"
)
# Read next line
frag_line
=
f
.
readline
()
frag_list
.
append
(
frag_str
)
# Store list of random nucleotides from which to sample when read length is too short
nucleotides
=
[
'
A
'
,
'
C
'
,
'
G
'
,
'
T
'
]
# Calculate sum of all lengths to determine the relative abundance for that fragment
sum_frags
=
sum
(
map
(
len
,
frag_list
))
# Open the file to save the reads
with
open
(
output_file_name
,
'
w
'
)
as
fw
:
# Loop through fasta fragments that start with 5'
for
frag
in
frag_list
:
# Determine number of reads to create from this fragment
# This might not always provide an exact number of reads that were asked
# TODO resolve this issue
num_frag_reads
=
round
((
len
(
frag
)
/
sum_frags
)
*
num_reads
)
for
i
in
range
(
0
,
num_frag_reads
):
# If the read length is less than the required length given by the parameter,
# then add random nucleotides
if
len
(
frag
)
<
read_len
:
# Calculate number of random nucleotides to add to the end of the read
diff
=
read_len
-
len
(
frag
)
# Select random nucleotides from list of possible
rand_samp
=
choices
(
nucleotides
,
k
=
diff
)
# Add the random list to the read and save
tmp_read
=
frag
[
0
:
len
(
frag
)]
+
''
.
join
(
rand_samp
)
else
:
# Save subset of fragment as read
tmp_read
=
frag
[
0
:
read_len
]
# Write read to file and original fragment description
fw
.
write
(
frag_desc
[
frag_list
.
index
(
frag
)])
fw
.
write
(
tmp_read
+
"
\n\n
"
)
Loading