Skip to content

Commit

Permalink
Merge pull request #70 from Nozdi/issue-63-gc-content
Browse files Browse the repository at this point in the history
[#62] Added functions for gc content
  • Loading branch information
Michał Rostecki committed Sep 24, 2014
2 parents 1501e5b + 583e0e8 commit e07cc13
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/shmir/data/ncbi_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import re

from Bio import Entrez
from designer import errors
import settings
from shmir.designer import errors
from shmir import settings


def get_data(
Expand Down
12 changes: 12 additions & 0 deletions src/shmir/designer/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,15 @@ def check_input(seq_to_be_check):
return check_complementary(ch_seq1[0], ch_seq2[0])
else:
raise errors.InputException('{}'.format(errors.error))


def calculate_gc_content(sequence):
sequence = sequence.upper()
g_count = sequence.count('G')
c_count = sequence.count('C')

return int((float(g_count + c_count) / len(sequence)) * 100)


def validate_gc_content(sequence, min_percent, max_percent):
return min_percent <= calculate_gc_content(sequence) <= max_percent
4 changes: 2 additions & 2 deletions src/shmir/tests/test_ncbi_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
patch
)

from data import ncbi_api
from designer import errors
from shmir.data import ncbi_api
from shmir.designer import errors


class TestGetDataFromNcbi(unittest.TestCase):
Expand Down
27 changes: 27 additions & 0 deletions src/shmir/tests/test_validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import unittest

from shmir.designer.validators import (
calculate_gc_content,
validate_gc_content,
)


class TestValidators(unittest.TestCase):

def test_calculate_gc_content(self):
seq_percent = calculate_gc_content('ACGT')
self.assertEqual(seq_percent, 50)

seq_percent = calculate_gc_content('CCCCGGGG')
self.assertEqual(seq_percent, 100)

seq_percent = calculate_gc_content('ACTTTTTTTA')
self.assertEqual(seq_percent, 10)

def test_validate_gc_content(self):
is_in_range = validate_gc_content('ACGT', 40, 60)
self.assertTrue(is_in_range)

def test_validate_gc_content_not_in_range(self):
not_in_range = validate_gc_content('ACGT', 52, 70)
self.assertFalse(not_in_range)

0 comments on commit e07cc13

Please sign in to comment.