From bf34cd9735039fe99f65c8fd0dceabf26ccd5fd1 Mon Sep 17 00:00:00 2001
From: "kathleen.moriarty" <kathleen.moriarty@unibas.ch>
Date: Wed, 8 Dec 2021 17:53:45 +0100
Subject: [PATCH] fix: python good practices

---
 src/read_sequencing.py      | 28 ++++++++++++----------------
 tests/test_read_sequence.py | 12 +++++++++---
 2 files changed, 21 insertions(+), 19 deletions(-)

diff --git a/src/read_sequencing.py b/src/read_sequencing.py
index e7e6581..e229af2 100644
--- a/src/read_sequencing.py
+++ b/src/read_sequencing.py
@@ -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")
diff --git a/tests/test_read_sequence.py b/tests/test_read_sequence.py
index 00caf1f..bae061e 100644
--- a/tests/test_read_sequence.py
+++ b/tests/test_read_sequence.py
@@ -1,16 +1,22 @@
-"""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
-- 
GitLab