Skip to content

Commit 84cb2be

Browse files
committed
PS/HP
preserving phaseset/haplotype information in sample table This is going to break all the tests
1 parent 0371326 commit 84cb2be

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

tdb/create.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@
2222
"allele_length": pa.uint16(),
2323
"sequence": pa.binary(),
2424
"spanning_reads": pa.uint16(),
25+
"phase_set": pa.uint32(),
26+
"haplotype": pa.uint16(),
2527
"length_range_lower": pa.uint16(),
2628
"length_range_upper": pa.uint16(),
2729
"average_methylation": pa.float32()}
2830

2931
L_COLUMNS = ["LocusID", "chrom", "start", "end"]
3032
A_COLUMNS = ["LocusID", "allele_number", "allele_length", "sequence"]
31-
S_COLUMNS = ["LocusID", "allele_number", "spanning_reads", "length_range_lower",
32-
"length_range_upper", "average_methylation"]
33+
S_COLUMNS = ["LocusID", "allele_number", "spanning_reads", "phase_set", "haplotype",
34+
"length_range_lower", "length_range_upper", "average_methylation"]
3335

3436
L_SCHEMA = pa.schema({key: DTYPES[key] for key in L_COLUMNS})
3537
A_SCHEMA = pa.schema({key: DTYPES[key] for key in A_COLUMNS})
@@ -82,15 +84,18 @@ def sample_extract(locus_id, fmt, o_alleles, n_alleles):
8284
"""
8385
ret = []
8486
gts = [_ for _ in fmt['GT'] if _ is not None]
85-
view = zip(gts, fmt['SD'], fmt['ALLR'],
86-
fmt.get('AM', [None] * len(gts)))
87-
for an, sd, allr, am in view:
88-
if an is None:
89-
continue
87+
view = zip(gts,
88+
fmt['SD'],
89+
fmt['ALLR'],
90+
fmt.get('AM', [None] * len(gts)),
91+
range(len(gts))# if fmt.phased else [None, None]
92+
)
93+
for an, sd, allr, am, hp in view:
9094
# Map allele number to new, deduplicated allele number
9195
an = n_alleles.index(o_alleles[an])
9296
lrl, lru = map(int, allr.split('-'))
93-
ret.append([locus_id, an, sd, lrl, lru, am])
97+
ps = fmt.get('PS', None)
98+
ret.append([locus_id, an, sd, ps, hp, lrl, lru, am])
9499
return ret
95100

96101

0 commit comments

Comments
 (0)