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
Commits
bf34cd97
Commit
bf34cd97
authored
3 years ago
by
Kathleen Moriarty
Committed by
Kathleen Moriarty
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix: python good practices
parent
1bed9aa4
Branches
Branches containing commit
No related tags found
1 merge request
!17
Issue 7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/read_sequencing.py
+12
-16
12 additions, 16 deletions
src/read_sequencing.py
tests/test_read_sequence.py
+9
-3
9 additions, 3 deletions
tests/test_read_sequence.py
with
21 additions
and
19 deletions
src/read_sequencing.py
+
12
−
16
View file @
bf34cd97
...
...
@@ -3,13 +3,17 @@
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
,
output_file_name
,
num_reads
,
read_len
,
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.
...
...
@@ -24,18 +28,15 @@ def read_sequencing(
ends of the terminal fragments as .txt.
Args:
frag_file_name
(string)
: input file of terminal fragments
output_file_name
(string):
file
name
where to store the output
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
"""
# Import classes
from
random
import
choices
from
typing
import
List
# Read data from terminal fragment file
# Store fragment descriptions in a list
frag_desc
=
[]
# type: List[str]
frag_desc
=
[]
# type: List[str]
with
open
(
frag_file_name
,
'
r
'
)
as
f
:
frag_line
=
f
.
readline
()
...
...
@@ -93,9 +94,4 @@ def read_sequencing(
# Write read to file and original fragment description
fw
.
write
(
frag_desc
[
frag_list
.
index
(
frag
)])
fw
.
write
(
tmp_read
+
"
\n
"
)
read_sequencing
(
frag_file_name
=
"
../tests/resources/test_terminal_fragments.txt
"
,
output_file_name
=
"
reads.txt
"
,
num_reads
=
90
,
read_len
=
10
)
\ No newline at end of file
fw
.
write
(
tmp_read
+
"
\n\n
"
)
This diff is collapsed.
Click to expand it.
tests/test_read_sequence.py
+
9
−
3
View file @
bf34cd97
"""
Test
Issue 7
.
"""
"""
Test
Read Sequencing Functionality
.
"""
# imports from built-in modules
from
pathlib
import
Path
# imports from third-party modules
import
pandas
as
pd
# imports from _this_ package
from
src.read_sequencing
import
read_sequencing
def
test_read_sequencing
(
tmpdir
):
"""
Tests the correct number of reads were generated.
"""
read_sequencing
(
frag_file_name
=
'
./tests/resources/test_terminal_fragments.txt
'
,
frag_file_name
=
Path
(
'
./tests/resources/test_terminal_fragments.txt
'
)
,
num_reads
=
80
,
read_len
=
10
,
output_file_name
=
tmpdir
/
'
reads.txt
'
)
df_out
=
pd
.
read_table
(
tmpdir
/
'
reads.txt
'
,
header
=
None
)
assert
df_out
.
shape
[
0
]
==
80
assert
df_out
.
shape
[
0
]
==
80
*
3
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