Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable np.array input #7

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@

name: build

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
on: [push]

jobs:
build:
Expand Down
31 changes: 20 additions & 11 deletions phasedibd/haplotype_alignment.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,28 @@ cdef class HaplotypeAlignment:
Contains test data.
"""

def __init__(self):
def __init__(self, haplotype_array=None, chromosomes=None):

self.chromosomes = ['1']
self.current_chromosome = ''
self.haplotypes = [[0, 1, 0, 1, 0, 1],
[1, 1, 2, 0, 0, 1], # 2 represents missing/invalid allele
[1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 1, 0],
[1, 1, 0, 0, 0, 1],
[0, 1, 0, 1, 1, 0]]
if haplotype_array is None:
# use test data
self.haplotypes = [[0, 1, 0, 1, 0, 1],
[1, 1, 2, 0, 0, 1], # 2 represents missing/invalid allele
[1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 1, 0],
[1, 1, 0, 0, 0, 1],
[0, 1, 0, 1, 1, 0]]
else:
self.haplotypes = haplotype_array

if chromosomes is None:
self.chromosomes = ['1']
else:
self.chromosomes = chromosomes

self.current_chromosome = ''

self.num_all_haplotypes = len(self.haplotypes)
self.num_active_haplotypes = len(self.haplotypes)
self.num_sites = len(self.haplotypes[0])
Expand Down
29 changes: 29 additions & 0 deletions tests/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,35 @@ def test_PBWT_default_haplotypes(self):
#print(ibd_segs)
#print(true_segs)
self.assertTrue(np.all(ibd_segs.eq(true_segs)))

def test_PBWT_default_haplotypes_np_array_input(self):
print("\nTesting non-templated PBWT matches over default haplotypes...")
haplotype_array = np.array([[0, 1, 0, 1, 0, 1],
[1, 1, 2, 0, 0, 1], # 2 represents missing/invalid allele
[1, 1, 1, 1, 1, 1],
[0, 1, 1, 1, 1, 0],
[0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 1, 0],
[1, 1, 0, 0, 0, 1],
[0, 1, 0, 1, 1, 0]])

haplotypes = ibd.HaplotypeAlignment(haplotype_array=haplotype_array)
tpbwt = ibd.TPBWTAnalysis(template=[[1]])
ibd_segs = tpbwt.compute_ibd(haplotypes, L_m=3, L_f=0, missing_site_threshold=1, verbose=False)
true_segs = pd.DataFrame({'chromosome': ['1'] * 3,
'start': [0,0,1],
'end': [3,5,4],
'start_cm': [0,0,1],
'end_cm': [3,5,4],
'start_bp': [0,0,1],
'end_bp': [3,5,4],
'id1': [0,1,2],
'id2': [7,6,3],
'id1_haplotype': [0,0,0],
'id2_haplotype': [0,0,0]})
#print(ibd_segs)
#print(true_segs)
self.assertTrue(np.all(ibd_segs.eq(true_segs)))


def test_vcf_no_map(self):
Expand Down