From f8c5ab1fe16a7db4e657fcdc1cdf550ee7d851ae Mon Sep 17 00:00:00 2001 From: PeterDeWeirdt Date: Tue, 6 Aug 2019 18:05:06 -0400 Subject: [PATCH] feature (featurize): added encode and nt count functions --- .gitignore | 69 ++++++++++++++++++++++++++++++++++ .idea/other.xml | 7 ++++ setup.py | 2 +- sgrna_modeler/sgrna_modeler.py | 15 +++++++- tests/test_sgrna_modeler.py | 29 +++++++------- 5 files changed, 107 insertions(+), 15 deletions(-) create mode 100644 .idea/other.xml diff --git a/.gitignore b/.gitignore index 84229f4..1d4af07 100644 --- a/.gitignore +++ b/.gitignore @@ -100,3 +100,72 @@ ENV/ # mypy .mypy_cache/ + +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser diff --git a/.idea/other.xml b/.idea/other.xml new file mode 100644 index 0000000..640fd80 --- /dev/null +++ b/.idea/other.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/setup.py b/setup.py index 0b6e2d7..8a6f243 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,7 @@ with open('HISTORY.rst') as history_file: history = history_file.read() -requirements = [ ] +requirements = ['pandas', ] setup_requirements = ['pytest-runner', ] diff --git a/sgrna_modeler/sgrna_modeler.py b/sgrna_modeler/sgrna_modeler.py index 7fbbae4..826fd84 100644 --- a/sgrna_modeler/sgrna_modeler.py +++ b/sgrna_modeler/sgrna_modeler.py @@ -1,3 +1,16 @@ # -*- coding: utf-8 -*- - +import numpy as np """Main module.""" +nt_codes = {'A':[1,0,0,0], + 'C':[0,1,0,0], + 'G':[0,0,1,0], + 'T':[0,0,0,1]} +def encode_seqs(seqs): + # 3d array with samples x position x nt + encoded_seqs = np.array([[nt_codes.get(x) for x in seq] for seq in seqs]) + return encoded_seqs + +def get_nt_count(encoded_seqs, nt): + counts = np.sum(encoded_seqs[:,:,nt_codes.get(nt).index(1)], axis = 1) + return counts + diff --git a/tests/test_sgrna_modeler.py b/tests/test_sgrna_modeler.py index 05ca99d..be07646 100644 --- a/tests/test_sgrna_modeler.py +++ b/tests/test_sgrna_modeler.py @@ -5,19 +5,22 @@ import pytest - -from sgrna_modeler import sgrna_modeler - - -@pytest.fixture -def response(): - """Sample pytest fixture. - - See more at: http://doc.pytest.org/en/latest/fixture.html - """ - # import requests - # return requests.get('https://github.com/audreyr/cookiecutter-pypackage') - +import numpy as np +from sgrna_modeler import sgrna_modeler as sm + +seqs = ['ACT','ACT','GCT','AAT','AAA'] + +def test_encoding(): + encoded = sm.encode_seqs(seqs) + np.testing.assert_array_equal(encoded[3,:,:], + np.array([[1,0,0,0], + [1,0,0,0], + [0,0,0,1]])) + +def test_nt_counts(): + encoded = sm.encode_seqs(seqs) + A_content = sm.get_nt_count(encoded, 'A') + np.testing.assert_array_equal(A_content, np.array([1,1,0,2,3])) def test_content(response): """Sample pytest test function with the pytest fixture as an argument."""