From bcd472baff09b5a997bcd48f89669d4c39bfd08d Mon Sep 17 00:00:00 2001
From: TheRiPtide <g.zaugg97@gmail.com>
Date: Wed, 15 Dec 2021 11:17:58 +0100
Subject: [PATCH] patch: cli for poly(A) classifier and coverage exclusions

---
 setup.cfg                                     | 10 ++++++-
 src/polyA_classifier/__init__.py              |  1 +
 src/polyA_classifier/cli.py                   | 30 +++++++++++++++++++
 .../polyA_classifier.py                       |  0
 tests/test_poly_a.py                          |  2 +-
 5 files changed, 41 insertions(+), 2 deletions(-)
 create mode 100644 src/polyA_classifier/__init__.py
 create mode 100644 src/polyA_classifier/cli.py
 rename src/{ => polyA_classifier}/polyA_classifier.py (100%)

diff --git a/setup.cfg b/setup.cfg
index 1d48b94..4ae1933 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,3 +1,11 @@
 [flake8]
 max-line-length = 120
-docstring-convention = google
\ No newline at end of file
+docstring-convention = google
+
+[coverage:report]
+exclude_lines =
+    if __name__ == '__main__':
+
+[coverage:run]
+omit =
+    */cli.py
\ No newline at end of file
diff --git a/src/polyA_classifier/__init__.py b/src/polyA_classifier/__init__.py
new file mode 100644
index 0000000..0f5ce03
--- /dev/null
+++ b/src/polyA_classifier/__init__.py
@@ -0,0 +1 @@
+"""Module for classifying poly(A) sequences."""
diff --git a/src/polyA_classifier/cli.py b/src/polyA_classifier/cli.py
new file mode 100644
index 0000000..397ccf8
--- /dev/null
+++ b/src/polyA_classifier/cli.py
@@ -0,0 +1,30 @@
+"""Command-line interface for the poly(A) classifier."""
+
+import sys
+import argparse
+from src.polyA_classifier.polyA_classifier import PolyAClassifier
+
+parser = argparse.ArgumentParser()
+
+parser.add_argument('data', action='store', help='str or list(str) of length 200 chars to classify.')
+parser.add_argument('-p', '--path', action='store', help='Path to state-dict for Net-model.',
+                    default='./models/internal_priming.pth')
+
+
+if __name__ == '__main__':
+
+    args = parser.parse_args()
+
+    if args.data[0] == '[':
+
+        data = args.data[1:-1].replace(' ', '').split(',')
+
+    else:
+
+        data = args.data
+
+    classifier = PolyAClassifier(state_dict_path=args.path)
+
+    result = classifier.classify(data)
+
+    sys.stdout.write(str(result))
diff --git a/src/polyA_classifier.py b/src/polyA_classifier/polyA_classifier.py
similarity index 100%
rename from src/polyA_classifier.py
rename to src/polyA_classifier/polyA_classifier.py
diff --git a/tests/test_poly_a.py b/tests/test_poly_a.py
index 1f3760c..8c95e90 100644
--- a/tests/test_poly_a.py
+++ b/tests/test_poly_a.py
@@ -3,7 +3,7 @@
 import pytest
 import os
 from src.poly_a import generate_poly_a
-from src.polyA_classifier import PolyAClassifier, Net
+from src.polyA_classifier.polyA_classifier import PolyAClassifier, Net
 import linecache
 
 
-- 
GitLab