def header(self, handle): self._header = Header() for line in handle: try: self._header.append(line) except ValueError: break self.first = line # make sure all the header data is available within variants Variant.set_header(self._header)
def test_variant_with_samples(self): ''' check that we can construct a Variant with sample data ''' line = '1\t100\t.\tA\tG\t.\t.\tAD=100\tGT:PL\t1/1:80,9,2\n' var = Variant(line) self.assertIsInstance(var.samples, Samples) self.assertEqual(str(var), line) # check it works for variants with multiple samples line = '1\t100\t.\tA\tG\t.\t.\tAC=9\tGT:PL\t1/1:80,9,2\t0/1:9,1,1\n' var = Variant(line) self.assertEqual(str(var), line)
def test_variant_alts(self): ''' check we can set a variant alt alleles ''' line = '1\t100\t.\tA\tG\t.\t.\tAC=100\n' var = Variant(line) var.alts = 'G,C' self.assertEqual(var.alts, ['G', 'C']) var.alts = ['G', 'T'] self.assertEqual(var.alts, ['G', 'T']) var.alts = 'G' self.assertEqual(var.alts, ['G'])
def test_variant_multiallelic(self): ''' check initialising a multiallelic Variant ''' line = '1\t100\t.\tA\tG,C\t.\t.\tAC=100\n' var = Variant(line) self.assertEqual(var.alts, ['G', 'C'])
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_variant_init(self): ''' check initialising a Variant ''' line = '1\t100\t.\tA\tG\t.\t.\tAC=100\n' var = Variant(line) self.assertEqual(var.chrom, '1') self.assertEqual(var.pos, 100) self.assertEqual(var.ref, 'A') self.assertEqual(var.ref, 'A') self.assertEqual(var.alts, ['G']) self.assertIsInstance(var.info, Info) self.assertEqual(var.info, Info('AC=100')) self.assertIsNone(var.samples) self.assertEqual(str(var), line)
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))
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 __next__(self): if self.first is not None: line, self.first = self.first, None # get value and blank self.first return Variant(line) return Variant(next(self.handle))