def test_call_filtered_set(self): site_filters = generate_filter(SOME_CHROMOSOMES_FILTERS) under_test = FilteringVectorGenotypeCallset(site_filters=site_filters, callset=self.callset) actual = under_test.gt(CHROMOSOME_1) self.assertTrue((allel.GenotypeVector([[1, 1]]) == actual).all()) actual = under_test.gt(CHROMOSOME_2) self.assertTrue((allel.GenotypeVector([[0, 0], [2, 0]]) == actual).all())
def test_call_set(self): zarr_group = generate_gt_data(SAMPLE_A, SOME_CHROMOSOMES_GT) under_test = VectorGenotypeCallset(sample=SAMPLE_A, callset=zarr_group) actual = under_test.gt(CHROMOSOME_1) self.assertTrue( (allel.GenotypeVector(CHROMOSOME_1_GT) == actual).all()) actual = under_test.gt(CHROMOSOME_2) self.assertTrue( (allel.GenotypeVector(CHROMOSOME_2_GT) == actual).all())
def test_compute_hom_alt_mismatch(self, value): control, test, expected = value lgt = allel.GenotypeVector([control]) rgt = allel.GenotypeVector([test]) actual = compute_hom_alt_mismatch(control=lgt, test=rgt, recorder=self.recorder) self.assertEqual(expected, actual) self.assertCountEqual( self.recorder.record.call_args_list, [call(HOMOZIGOUS_ALTERNATE_CATEGORY, MISMATCH_CATEGORY, expected)])
def readData(dir): fs=os.listdir(dir) for f in fs: bf=tbf.copy_template(outdir+f+".bloom") try: input=''.join([dir, f]) callset=allel.read_vcf(input, fields=['variants/CHROM','variants/POS', 'calldata/GT'], types={'calldata/GT':'i2'}, fills={'calldata/GT':2}) chrom=callset['variants/CHROM'] pos=callset['variants/POS'] gt=allel.GenotypeArray(callset['calldata/GT']) for i in range(len(chrom)): position='|'.join([chrom[i], str(pos[i])]) gv=allel.GenotypeVector(gt[i]) key1=0 key2=0 if gv[0][0] ==0|gv[0][0] ==1|gv[0][0] ==2 : key1=gv[0][0] print("key1:"+str(key1)) if gv[0][1] ==0|gv[0][1] ==1|gv[0][1] ==2: key2=gv[0][1] sum=key1|key2 key='|'.join([position, str(sum)]) bf.add(key) except Exception as err: print(f) print(err) bf.close()
def setUp(self) -> None: self.callset = MagicMock() self.callset.gt.side_effect = lambda chromosome: allel.GenotypeVector( SOME_CHROMOSOMES_GT[chromosome])
def gt(self, chromosome: str) -> allel.GenotypeVector: gt = self.callset[GT_PATH_FORMAT.format(sample=self.sample, chromosome=chromosome)] return allel.GenotypeVector(gt[:, ONLY_ONE_SAMPLE_IN_VECTOR_GT_ZARR])