[med-svn] [python-pymummer] 01/04: Imported Upstream version 0.8.1

Sascha Steinbiss satta at debian.org
Wed Aug 24 13:49:17 UTC 2016


This is an automated email from the git hooks/post-receive script.

satta pushed a commit to branch master
in repository python-pymummer.

commit 3c283d8309060ae2810eda99868d7e185e71a155
Author: Sascha Steinbiss <satta at debian.org>
Date:   Wed Aug 24 13:44:56 2016 +0000

    Imported Upstream version 0.8.1
---
 pymummer/alignment.py            | 36 +++++++++++++++++++++++++++++
 pymummer/tests/alignment_test.py | 49 ++++++++++++++++++++++++++++++++++++++++
 setup.py                         |  2 +-
 3 files changed, 86 insertions(+), 1 deletion(-)

diff --git a/pymummer/alignment.py b/pymummer/alignment.py
index ac066bb..d18f6ef 100644
--- a/pymummer/alignment.py
+++ b/pymummer/alignment.py
@@ -169,3 +169,39 @@ class Alignment:
             return min(self.qry_start, self.qry_end) + distance, False
         else:
             return max(self.qry_start, self.qry_end) - distance, False
+
+
+    def ref_coords_from_qry_coord(self, qry_coord, variant_list):
+        '''Given a qryerence position and a list of variants ([variant.Variant]),
+           works out the position in the ref sequence, accounting for indels.
+           Returns a tuple: (position, True|False), where second element is whether
+           or not the qry_coord lies in an indel. If it is, then
+           returns the corresponding start position
+           of the indel in the ref'''
+        if self.qry_coords().distance_to_point(qry_coord) > 0:
+            raise Error('Cannot get ref coord in ref_coords_from_qry_coord because given qry_coord ' + str(qry_coord) + ' does not lie in nucmer alignment:\n' + str(self))
+
+        indel_variant_indexes = []
+
+        for i in range(len(variant_list)):
+            if variant_list[i].var_type not in {variant.INS, variant.DEL}:
+                continue
+            if variant_list[i].qry_start <= qry_coord <= variant_list[i].qry_end:
+                return variant_list[i].ref_start, True
+            elif variant_list[i].qry_start < qry_coord:
+                indel_variant_indexes.append(i)
+
+        distance = qry_coord - min(self.qry_start, self.qry_end)
+
+        for i in indel_variant_indexes:
+            if variant_list[i].var_type == variant.DEL:
+                distance += len(variant_list[i].ref_base)
+            else:
+                assert variant_list[i].var_type == variant.INS
+                distance -= len(variant_list[i].qry_base)
+
+        if self.on_same_strand():
+            return min(self.ref_start, self.ref_end) + distance, False
+        else:
+            return max(self.ref_start, self.ref_end) - distance, False
+
diff --git a/pymummer/tests/alignment_test.py b/pymummer/tests/alignment_test.py
index 0db2701..a4ad0f3 100644
--- a/pymummer/tests/alignment_test.py
+++ b/pymummer/tests/alignment_test.py
@@ -241,3 +241,52 @@ class TestNucmer(unittest.TestCase):
             aln.ref_start, aln.ref_end = aln.ref_end, aln.ref_start
 
 
+    def test_ref_coords_from_qry_coord_test_same_strand(self):
+        '''Test ref_coords_from_qry_coord on same strand'''
+        aln = alignment.Alignment('\t'.join(['1', '101', '100', '200', '100', '100', '100.00', '300', '300', '1', '1', 'ref', 'qry']))
+        snp0 = snp.Snp('\t'.join(['40', 'T', 'A', '140', 'x', 'x', '300', '300', 'x', 'x', 'ref', 'qry'])) # snp
+        snp0 = variant.Variant(snp0)
+        snp1 = snp.Snp('\t'.join(['40', '.', 'A', '140', 'x', 'x', '300', '300', 'x', 'x', 'ref', 'qry'])) # del from ref
+        snp2 = snp.Snp('\t'.join(['40', '.', 'C', '141', 'x', 'x', '300', '300', 'x', 'x', 'ref', 'qry'])) # del from ref
+        del1 = variant.Variant(snp1)
+        del2 = variant.Variant(snp1)
+        self.assertTrue(del2.update_indel(snp2))
+        snp3 = snp.Snp('\t'.join(['50', 'A', '.', '150', 'x', 'x', '300', '300', 'x', 'x', 'ref', 'qry'])) # del from qry
+        snp4 = snp.Snp('\t'.join(['51', 'C', '.', '150', 'x', 'x', '300', '300', 'x', 'x', 'ref', 'qry'])) # del from qry
+        snp5 = snp.Snp('\t'.join(['52', 'G', '.', '150', 'x', 'x', '300', '300', 'x', 'x', 'ref', 'qry'])) # del from qry
+        ins1 = variant.Variant(snp3)
+        ins2 = variant.Variant(snp3)
+        self.assertTrue(ins2.update_indel(snp4))
+        self.assertTrue(ins2.update_indel(snp5))
+
+        tests = [
+            (99, [], (0, False)),
+            (100, [], (1, False)),
+            (199, [], (100, False)),
+            (119, [del1], (20, False)),
+            (149, [], (50, False)),
+            (149, [del1], (49, False)),
+            (149, [del2], (48, False)),
+            (159, [], (60, False)),
+            (159, [ins1], (61, False)),
+            (159, [ins2], (63, False)),
+            (159, [del1, ins1], (60, False)),
+            (159, [del1, ins2], (62, False)),
+            (159, [del2, ins1], (59, False)),
+            (159, [del2, ins2], (61, False)),
+            (139, [del1], (39, True)),
+            (139, [snp0], (40, False)),
+            (149, [ins1], (49, True)),
+        ]
+
+        for qry_coord, variant_list, expected in tests:
+            got = aln.ref_coords_from_qry_coord(qry_coord, variant_list)
+            self.assertEqual(expected, got)
+            # if we reverse the direction of hit in query and qryerence, should get the same answer
+            aln.ref_start, aln.ref_end = aln.ref_end, aln.ref_start
+            aln.qry_start, aln.qry_end = aln.qry_end, aln.qry_start
+            got = aln.ref_coords_from_qry_coord(qry_coord, variant_list)
+            self.assertEqual(expected, got)
+            aln.ref_start, aln.ref_end = aln.ref_end, aln.ref_start
+            aln.qry_start, aln.qry_end = aln.qry_end, aln.qry_start
+
diff --git a/setup.py b/setup.py
index 8a4e483..2778e8d 100644
--- a/setup.py
+++ b/setup.py
@@ -26,7 +26,7 @@ if not found_all_progs:
 
 setup(
     name='pymummer',
-    version='0.7.1',
+    version='0.8.1',
     description='Wrapper for MUMmer',
     packages = find_packages(),
     author='Martin Hunt, Nishadi De Silva',

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/python-pymummer.git



More information about the debian-med-commit mailing list