def test_locations_distance_different_chrom(self): loc1 = Location(chrom='chr4', pos=1337) loc2 = Location(chrom='chr7', pos=1001) distance = loc1 - loc2 inverse_distance = loc2 - loc1 self.assertEqual(distance, None) self.assertEqual(inverse_distance, None)
def test_locations_distance_same_chrom(self): loc1 = Location(chrom='chr7', pos=1337) loc2 = Location(chrom='chr7', pos=1001) distance = loc1 - loc2 inverse_distance = loc2 - loc1 self.assertEqual(distance, 1337 - 1001) self.assertEqual(inverse_distance, 1001 - 1337)
def test_location_shift(self): loc = Location(chrom='chr1', pos=42) shift = -2 shifted_loc1 = loc + shift shifted_loc2 = loc.shift(shift) self.assertIsInstance(shifted_loc1, Location) self.assertEqual(shifted_loc1.pos, loc.pos + shift) self.assertEqual(shifted_loc1, shifted_loc2)
def test_parse_vcf_line(self): line = '\t'.join([ 'chr1', '16688', '.', 'G', 'A', '.', 'map_qual;normal_artifact;strand_bias', 'AS_FilterStatus=map_qual,strand_bias;AS_SB_TABLE=327,30|0,13;DP=380;ECNT=3;GERMQ=93;MBQ=37,34;MFRL=260,332;MMQ=22,22;MPOS=21;NALOD=-1.391e+00;NLOD=43.74;POPAF=6.00;ROQ=80;TLOD=7.68', 'GT:AD:AF:DP:F1R2:F2R1:SB', '0/0:180,4:0.026:184:99,1:80,3:165,15,0,4', '0/1:177,9:0.052:186:98,4:77,5:162,15,0,9' ]) vcfrow = _parse_vcf_line(line) self.assertEqual(vcfrow.loc, Location(chrom='chr1', pos=16688)) self.assertEqual(vcfrow.id, '.') self.assertEqual(vcfrow.ref, 'G') self.assertEqual(vcfrow.alt, 'A') self.assertEqual(vcfrow.qual, '.') self.assertEqual(vcfrow.filter, 'map_qual;normal_artifact;strand_bias') self.assertEqual( vcfrow.info, Info( 'AS_FilterStatus=map_qual,strand_bias;AS_SB_TABLE=327,30|0,13;DP=380;ECNT=3;GERMQ=93;MBQ=37,34;MFRL=260,332;MMQ=22,22;MPOS=21;NALOD=-1.391e+00;NLOD=43.74;POPAF=6.00;ROQ=80;TLOD=7.68' )) self.assertEqual(vcfrow.format, 'GT:AD:AF:DP:F1R2:F2R1:SB') self.assertEqual(vcfrow.samples, [ '0/0:180,4:0.026:184:99,1:80,3:165,15,0,4', '0/1:177,9:0.052:186:98,4:77,5:162,15,0,9' ])
def setUp(self): self.loc = Location(chrom='chr1', pos=42) self.vcfrow = VCFrow(loc=self.loc, id='1234', ref='A', alt='G', qual='.', filter='PASS', info='info', format='format', samples=['sample1', 'sample2'])
def _parse_vcf_line(line: str) -> VCFrow: elements = line.split('\t') loc = Location(chrom=elements[0], pos=int(elements[1])) return VCFrow(loc=loc, id=elements[2], ref=elements[3], alt=elements[4], qual=elements[5], filter=elements[6], info=Info(elements[7]), format=elements[8], samples=elements[9:])
def setUp(self): loc1 = Location(chrom='chr2', pos=21) loc2 = Location(chrom='chr16', pos=50) self.vcfrow1 = VCFrow(loc=loc1, id='id1', ref='G', alt='A', qual='.', filter='PASS', info='info', format='format', samples=['sample1', 'sample2']) self.vcfrow2 = VCFrow(loc=loc2, id='id2', ref='T', alt='ATTGC', qual='.', filter='PASS', info='info', format='format', samples=['sample1', 'sample2']) self.vcf = VCF(rows=[self.vcfrow1, self.vcfrow2])
def test_location(self): loc = Location(chrom='chr1', pos=42) self.assertEqual(loc.chrom, 'chr1') self.assertEqual(loc.pos, 42)
def test_location_greater_than_sex_chrom(self): loc1 = Location(chrom='Y', pos=42) loc2 = Location(chrom='4', pos=1001) self.assertEqual(loc2 > loc1, False)
def test_location_less_than_sex_chrom(self): loc1 = Location(chrom='7', pos=42) loc2 = Location(chrom='X', pos=1001) self.assertEqual(loc1 < loc2, True)
def test_location_less_than_different_chrom(self): loc1 = Location(chrom='chr7', pos=42) loc2 = Location(chrom='chr20', pos=1001) self.assertEqual(loc1 < loc2, True)
def test_location_less_than_same_chrom(self): loc1 = Location(chrom='chr7', pos=1337) loc2 = Location(chrom='chr7', pos=1001) self.assertEqual(loc2 < loc1, True) self.assertEqual(loc1 > loc2, True)
def test_location_shift_error(self): loc = Location(chrom='chr1', pos=42) shift = 'not_valid' with self.assertRaises(LocationShiftError): loc + shift