Skip to content

Commit

Permalink
Fixed some deprecated BioPython warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
terrycojones committed Jan 31, 2021
1 parent 20d02ec commit 817b667
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
4 changes: 1 addition & 3 deletions bin/trim-primers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import sys
from Bio import SeqIO
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC
from dark.sequence import findPrimerBidiLimits


Expand Down Expand Up @@ -53,5 +52,4 @@ def trimPrimers(primer, verbose):

args = parser.parse_args()

trimPrimers(Seq(args.primer.upper(), IUPAC.unambiguous_dna),
args.verbose)
trimPrimers(Seq(args.primer.upper()), args.verbose)
12 changes: 8 additions & 4 deletions test/test_dna.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import six
from unittest import TestCase

from Bio.Alphabet.IUPAC import IUPACAmbiguousDNA

from dark.dna import (
AMBIGUOUS, BASES_TO_AMBIGUOUS, compareDNAReads, matchToString,
findKozakConsensus, FloatBaseCounts, sequenceToRegex)
from dark.reads import Read, DNARead, DNAKozakRead

# The following are the letters that used to be on
# from Bio.Alphabet.IUPAC import IUPACAmbiguousDNA
# IUPACAmbiguousDNA.letters
# But Bio.Alphabet is now deprecated and will be removed.
AMBIGUOUS_DNA_LETTERS = 'GATCRYWSMKHBVDN'


class TestAmbiguousLetters(TestCase):
"""
Expand All @@ -17,7 +21,7 @@ def testExpectedAmbiguousLetters(self):
"""
The ambiguous DNA letters must match those given by IUPAC.
"""
self.assertEqual(sorted(IUPACAmbiguousDNA.letters), sorted(AMBIGUOUS))
self.assertEqual(sorted(AMBIGUOUS_DNA_LETTERS), sorted(AMBIGUOUS))

def testExpectedLengthOne(self):
"""
Expand All @@ -31,7 +35,7 @@ def testExpectedLengthsGreaterThanOne(self):
The ambiguous DNA letters must be in sets of size greater than one
and less than 5.
"""
for base in set(IUPACAmbiguousDNA.letters) - set('ACGT'):
for base in set(AMBIGUOUS_DNA_LETTERS) - set('ACGT'):
self.assertTrue(5 > len(AMBIGUOUS[base]) > 1)

def testAmbiguousLettersAreAllACGT(self):
Expand Down
38 changes: 18 additions & 20 deletions test/test_sequence.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from unittest import TestCase
from dark.sequence import findPrimer, findPrimerBidi, findPrimerBidiLimits
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC


class TestFindPrimer(TestCase):
Expand All @@ -13,39 +12,39 @@ def testNotFound(self):
"""
If a primer is not found, the empty list must be returned.
"""
seq = Seq('ACGT', IUPAC.unambiguous_dna)
seq = Seq('ACGT')
self.assertEqual([], findPrimer('BLAH', seq))

def testFoundAtStart(self):
"""
If a primer is found at the start of a sequence, a list containing 0
must be returned.
"""
seq = Seq('ACGT', IUPAC.unambiguous_dna)
seq = Seq('ACGT')
self.assertEqual([0], findPrimer('AC', seq))

def testFoundAtEnd(self):
"""
If a primer is found at the end of a sequence, the correct value
must be returned.
"""
seq = Seq('ACGT', IUPAC.unambiguous_dna)
seq = Seq('ACGT')
self.assertEqual([2], findPrimer('GT', seq))

def testFoundMultiple(self):
"""
If a primer is found multiple times, the correct value
must be returned.
"""
seq = Seq('ACGTACGT', IUPAC.unambiguous_dna)
seq = Seq('ACGTACGT')
self.assertEqual([0, 4], findPrimer('ACG', seq))

def testOverlapping(self):
"""
If a primer is present twice but is overlapping, only the first
instance should be returned.
"""
seq = Seq('GAAA', IUPAC.unambiguous_dna)
seq = Seq('GAAA')
self.assertEqual([1], findPrimer('AA', seq))


Expand All @@ -58,7 +57,7 @@ def testNotFound(self):
"""
If a primer is not found, empty lists must be returned.
"""
seq = Seq('ACGT', IUPAC.unambiguous_dna)
seq = Seq('ACGT')
self.assertEqual(([], []), findPrimerBidi('BLAH', seq))

def testFoundStartEnd(self):
Expand All @@ -67,7 +66,7 @@ def testFoundStartEnd(self):
the forward sequence, end of the reverse complement), the
correct value must be returned.
"""
seq = Seq('ACGT', IUPAC.unambiguous_dna)
seq = Seq('ACGT')
self.assertEqual(([0], [2]), findPrimerBidi('AC', seq))

def testFoundEndStart(self):
Expand All @@ -76,31 +75,31 @@ def testFoundEndStart(self):
the forward sequence, start of the reverse complement), the
correct value must be returned.
"""
seq = Seq('ACGT', IUPAC.unambiguous_dna)
seq = Seq('ACGT')
self.assertEqual(([2], [0]), findPrimerBidi('GT', seq))

def testFoundMultiple(self):
"""
If a primer is found multiple times, the correct value
must be returned.
"""
seq = Seq('ACGTACGT', IUPAC.unambiguous_dna)
seq = Seq('ACGTACGT')
self.assertEqual(([0, 4], [1, 5]), findPrimerBidi('ACG', seq))

def testOverlappingForwards(self):
"""
If a primer is present twice forwards but is overlapping, only
the first instance should be returned.
"""
seq = Seq('GAAA', IUPAC.unambiguous_dna)
seq = Seq('GAAA')
self.assertEqual(([1], []), findPrimerBidi('AA', seq))

def testOverlappingBackwards(self):
"""
If a primer is present twice backwards but is overlapping, only
the first instance should be returned.
"""
seq = Seq('GTTT', IUPAC.unambiguous_dna)
seq = Seq('GTTT')
self.assertEqual(([], [1]), findPrimerBidi('AA', seq))


Expand All @@ -114,7 +113,7 @@ def testNotFound(self):
If a primer is not found, the returned offsets must include
the whole sequence.
"""
seq = Seq('ACGT', IUPAC.unambiguous_dna)
seq = Seq('ACGT')
self.assertEqual((0, 4), findPrimerBidiLimits('BLAH', seq))

def testFoundStartEnd(self):
Expand All @@ -123,7 +122,7 @@ def testFoundStartEnd(self):
the forward sequence, end of the reverse complement), the
correct value must be returned.
"""
seq = Seq('ACGT', IUPAC.unambiguous_dna)
seq = Seq('ACGT')
self.assertEqual((2, 2), findPrimerBidiLimits('AC', seq))

def testFoundEndStart(self):
Expand All @@ -132,31 +131,31 @@ def testFoundEndStart(self):
the forward sequence, start of the reverse complement), the
correct value must be returned.
"""
seq = Seq('ACGT', IUPAC.unambiguous_dna)
seq = Seq('ACGT')
self.assertEqual((4, 4), findPrimerBidiLimits('GT', seq))

def testFoundMultiple(self):
"""
If a primer is found multiple times, the correct value
must be returned.
"""
seq = Seq('ACGTACGT', IUPAC.unambiguous_dna)
seq = Seq('ACGTACGT')
self.assertEqual((7, 8), findPrimerBidiLimits('ACG', seq))

def testOverlappingForwards(self):
"""
If a primer is present twice forwards but is overlapping, only
the first instance should be returned.
"""
seq = Seq('GAAA', IUPAC.unambiguous_dna)
seq = Seq('GAAA')
self.assertEqual((3, 4), findPrimerBidiLimits('AA', seq))

def testOverlappingBackwards(self):
"""
If a primer is present twice backwards but is overlapping, only
the first instance should be returned.
"""
seq = Seq('GTTT', IUPAC.unambiguous_dna)
seq = Seq('GTTT')
self.assertEqual((0, 1), findPrimerBidiLimits('AA', seq))

def testLonger(self):
Expand All @@ -166,6 +165,5 @@ def testLonger(self):
seq = Seq('AAAAAAAAAA'
'GGGGGGGGGG'
'AAAAAAAAAA'
'AAAAAAAAAA',
IUPAC.unambiguous_dna)
'AAAAAAAAAA')
self.assertEqual((20, 40), findPrimerBidiLimits('GGGGGGGGGG', seq))

0 comments on commit 817b667

Please sign in to comment.