From 817b667c6b62a912ec93a0a1aea21a9268e7b1ca Mon Sep 17 00:00:00 2001 From: terrycojones Date: Sun, 31 Jan 2021 13:36:17 +0100 Subject: [PATCH] Fixed some deprecated BioPython warnings. --- bin/trim-primers.py | 4 +--- test/test_dna.py | 12 ++++++++---- test/test_sequence.py | 38 ++++++++++++++++++-------------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/bin/trim-primers.py b/bin/trim-primers.py index d661d275..4408d767 100755 --- a/bin/trim-primers.py +++ b/bin/trim-primers.py @@ -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 @@ -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) diff --git a/test/test_dna.py b/test/test_dna.py index f7b16c9e..c689d90c 100644 --- a/test/test_dna.py +++ b/test/test_dna.py @@ -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): """ @@ -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): """ @@ -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): diff --git a/test/test_sequence.py b/test/test_sequence.py index 508b3c0c..e06c58e2 100644 --- a/test/test_sequence.py +++ b/test/test_sequence.py @@ -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): @@ -13,7 +12,7 @@ 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): @@ -21,7 +20,7 @@ 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): @@ -29,7 +28,7 @@ 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): @@ -37,7 +36,7 @@ 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): @@ -45,7 +44,7 @@ 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)) @@ -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): @@ -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): @@ -76,7 +75,7 @@ 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): @@ -84,7 +83,7 @@ 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): @@ -92,7 +91,7 @@ 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): @@ -100,7 +99,7 @@ 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)) @@ -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): @@ -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): @@ -132,7 +131,7 @@ 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): @@ -140,7 +139,7 @@ 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): @@ -148,7 +147,7 @@ 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): @@ -156,7 +155,7 @@ 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): @@ -166,6 +165,5 @@ def testLonger(self): seq = Seq('AAAAAAAAAA' 'GGGGGGGGGG' 'AAAAAAAAAA' - 'AAAAAAAAAA', - IUPAC.unambiguous_dna) + 'AAAAAAAAAA') self.assertEqual((20, 40), findPrimerBidiLimits('GGGGGGGGGG', seq))