Skip to content

Commit

Permalink
feature (featurize): added encode and nt count functions
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterDeWeirdt committed Aug 6, 2019
1 parent 5f38482 commit f8c5ab1
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 15 deletions.
69 changes: 69 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions .idea/other.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
with open('HISTORY.rst') as history_file:
history = history_file.read()

requirements = [ ]
requirements = ['pandas', ]

setup_requirements = ['pytest-runner', ]

Expand Down
15 changes: 14 additions & 1 deletion sgrna_modeler/sgrna_modeler.py
Original file line number Diff line number Diff line change
@@ -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

29 changes: 16 additions & 13 deletions tests/test_sgrna_modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down

0 comments on commit f8c5ab1

Please sign in to comment.