def chunks_containing_region(self): breakpoints = BedTool(paths.reference + self.params.breakpointsfile) blocks = SnpPartition(self.refpanel, breakpoints, remove_mhc=True) self.A = SnpSubset(self.refpanel, GenomicSubset(self.params.region).bedtool) return [ int(i / self.chunk_size(blocks.ranges())) for i in blocks.indices_containing(self.A.irs) ]
def mult_by_R_ldblocks(V, refpanel, refpanel_indices=None): breakpoints = BedTool(paths.reference + 'pickrell_breakpoints.hg19.eur.bed') blocks = SnpPartition(refpanel, breakpoints, remove_mhc=True) if refpanel_indices is not None: Vwithzeros = np.zeros((refpanel.M, V.shape[1])) Vwithzeros[refpanel_indices] = V else: Vwithzeros = V result = np.zeros(Vwithzeros.shape) for r in blocks.ranges(): print('\tXTXV', r[0], r[1], 'of', refpanel.M) X = refpanel.get_standardized_genotypes(r) result[r[0]:r[1],:] = X.T.dot(X.dot(Vwithzeros[r[0]:r[1],:])) if refpanel_indices is not None: return result[refpanel_indices] / refpanel.N else: return result / refpanel.N
def mult_by_R_ldblocks(V, refpanel, refpanel_indices=None): breakpoints = BedTool(paths.reference + 'pickrell_breakpoints.hg19.eur.bed') blocks = SnpPartition(refpanel, breakpoints, remove_mhc=True) if refpanel_indices is not None: Vwithzeros = np.zeros((refpanel.M, V.shape[1])) Vwithzeros[refpanel_indices] = V else: Vwithzeros = V result = np.zeros(Vwithzeros.shape) for r in blocks.ranges(): print('\tXTXV', r[0], r[1], 'of', refpanel.M) X = refpanel.get_standardized_genotypes(r) result[r[0]:r[1], :] = X.T.dot(X.dot(Vwithzeros[r[0]:r[1], :])) if refpanel_indices is not None: return result[refpanel_indices] / refpanel.N else: return result / refpanel.N
def compute_covariance(self): breakpoints = BedTool(paths.reference + self.params.breakpointsfile) blocks = SnpPartition(self.refpanel, breakpoints, remove_mhc=True) myranges = self.ranges_in_chunk(blocks.ranges()) print('working on', len(myranges), 'ld blocks') return BlockDiag.ld_matrix_blocks(self.refpanel, myranges)
def chunks_containing_region(self): breakpoints = BedTool(paths.reference + self.params.breakpointsfile) blocks = SnpPartition(self.refpanel, breakpoints, remove_mhc=True) self.A = SnpSubset(self.refpanel, GenomicSubset(self.params.region).bedtool) return [int(i / self.chunk_size(blocks.ranges())) for i in blocks.indices_containing(self.A.irs)]