Skip to content
Snippets Groups Projects
Commit bf34cd97 authored by Kathleen Moriarty's avatar Kathleen Moriarty Committed by Kathleen Moriarty
Browse files

fix: python good practices

parent 1bed9aa4
Branches
No related tags found
1 merge request!17Issue 7
......@@ -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")
"""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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment