<gh_stars>0

import unittest

# from pyfaidx import Fasta
from liftover import get_lifter

from vcfremapper.remap import get_new_coords, remap
from vcfremapper.variant import Variant

class TestRemap(unittest.TestCase):
    ''' test remapping functions
    '''
    
    @classmethod
    def setUpClass(cls):
        cls.lift = get_lifter('hg19', 'hg38')

    def test_get_new_coords(self):
        ''' check getting new coordinates for a variant
        '''

        data = get_new_coords(self.lift, 'chr1', 1000000)
        self.assertEqual(data, ('chr1', 1064619, '+'))

        # check a pos which swaps strand
        data = get_new_coords(self.lift, 'chr1', 317720)
        self.assertEqual(data, ('chr1', 501616, '-'))
        
        # positions no longer in the new genome build raise errors
        with self.assertRaises(ValueError):
            get_new_coords(self.lift, 'chr1', 1)

        # unprefixed chromosomes can be converted
        data = get_new_coords(self.lift, '1', 1000000)
        self.assertEqual(data, ('chr1', 1064619, '+'))

    def test_remap(self):
        ''' check remapping a variant
        '''

        genome = None
        var = Variant('1\t1000000\t.\tA\tG\t100\tPASS\tAC=100\n')
        var = remap(self.lift, var, genome)
        self.assertEqual(var.chrom, '1')
        self.assertEqual(var.pos, 1064620)

    def test_remap_missing_alt(self):
        ''' check remapping a variant without alts
        '''

        genome = None
        var = Variant('1\t1000000\t.\tA\t.\t100\tPASS\tAC=100\n')
        var = remap(self.lift, var, genome)
        self.assertEqual(var.chrom, '1')
        self.assertEqual(var.pos, 1064620)

    def test_remap_not_in_build(self):
        ''' check a variant where the position is not in the new build
        '''
        genome = None
        var = Variant('1\t1\t.\tA\tG\t100\tPASS\tAC=100\n')
        self.assertIsNone(remap(self.lift, var, genome))

    def test_remap_unknown_chrom(self):
        ''' check a variant where the variant maps to a non-standard chromosome
        '''
        genome = None
        var = Variant('1\t13027995\t.\tA\tG\t100\tPASS\tAC=100\n')
        self.assertIsNone(remap(self.lift, var, genome))

import unittest

# from pyfaidx import Fasta
from liftover import get_lifter

from vcfremapper.remap import get_new_coords, remap
from vcfremapper.variant import Variant

class TestRemap(unittest.TestCase):
    ''' test remapping functions
    '''
    
    @classmethod
    def setUpClass(cls):
        cls.lift = get_lifter('hg19', 'hg38')

    def test_get_new_coords(self):
        ''' check getting new coordinates for a variant
        '''

        data = get_new_coords(self.lift, 'chr1', 1000000)
        self.assertEqual(data, ('chr1', 1064619, '+'))

        # check a pos which swaps strand
        data = get_new_coords(self.lift, 'chr1', 317720)
        self.assertEqual(data, ('chr1', 501616, '-'))
        
        # positions no longer in the new genome build raise errors
        with self.assertRaises(ValueError):
            get_new_coords(self.lift, 'chr1', 1)

        # unprefixed chromosomes can be converted
        data = get_new_coords(self.lift, '1', 1000000)
        self.assertEqual(data, ('chr1', 1064619, '+'))

    def test_remap(self):
        ''' check remapping a variant
        '''

        genome = None
        var = Variant('1\t1000000\t.\tA\tG\t100\tPASS\tAC=100\n')
        var = remap(self.lift, var, genome)
        self.assertEqual(var.chrom, '1')
        self.assertEqual(var.pos, 1064620)

    def test_remap_missing_alt(self):
        ''' check remapping a variant without alts
        '''

        genome = None
        var = Variant('1\t1000000\t.\tA\t.\t100\tPASS\tAC=100\n')
        var = remap(self.lift, var, genome)
        self.assertEqual(var.chrom, '1')
        self.assertEqual(var.pos, 1064620)

    def test_remap_not_in_build(self):
        ''' check a variant where the position is not in the new build
        '''
        genome = None
        var = Variant('1\t1\t.\tA\tG\t100\tPASS\tAC=100\n')
        self.assertIsNone(remap(self.lift, var, genome))

    def test_remap_unknown_chrom(self):
        ''' check a variant where the variant maps to a non-standard chromosome
        '''
        genome = None
        var = Variant('1\t13027995\t.\tA\tG\t100\tPASS\tAC=100\n')
        self.assertIsNone(remap(self.lift, var, genome))
# from pyfaidx import Fasta test remapping functions check getting new coordinates for a variant # check a pos which swaps strand # positions no longer in the new genome build raise errors # unprefixed chromosomes can be converted check remapping a variant check remapping a variant without alts check a variant where the position is not in the new build check a variant where the variant maps to a non-standard chromosome