Skip to content

Commit e3b6b7d

Browse files
committed
add option to liftover input to GRCh38 before QC
1 parent 7ce1f30 commit e3b6b7d

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

gwaspy/preimp_qc/preimp_qc.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
__author__ = 'Lindo Nkambule'
22

3-
from gwaspy.preimp_qc.annotations import *
4-
from typing import Tuple, Any, Dict, Union
5-
from gwaspy.utils.read_file import read_infile
3+
64
import argparse
7-
from gwaspy.preimp_qc.report import MyDocument
5+
import hail as hl
6+
import os
87
import shutil
98
import warnings
10-
import os
11-
import hail as hl
9+
10+
from gwaspy.preimp_qc.annotations import *
11+
from gwaspy.preimp_qc.report import MyDocument
12+
from gwaspy.utils.read_file import read_infile
13+
from gwaspy.utils.reference_liftover import liftover_to_grch38
14+
from typing import Tuple, Any, Dict, Union
15+
1216

1317
warnings.simplefilter(action='ignore', category=RuntimeWarning)
1418

@@ -67,7 +71,7 @@ def preimp_qc(input_type: str = None, dirname: str = None, basename: str = None,
6771
cr_diff_thresh: Union[int, float] = 0.02, maf_thresh: Union[int, float] = 0.01, withpna: int = 0,
6872
hwe_th_con_thresh: Union[int, float] = 1e-6, hwe_th_cas_thresh: Union[int, float] = 1e-10,
6973
hwe_th_all_thresh: Union[int, float] = 1e-06, annotations_file: str = None, report: bool = True,
70-
export_type: str = 'hail', out_dir: str = None, reference: str = 'GRCh38'):
74+
liftover: bool = False, export_type: str = 'hail', out_dir: str = None, reference: str = 'GRCh38'):
7175
print('\nRunning QC')
7276

7377
global mt, row_filters, filters, data_type, lambda_gc_pos, lambda_gc_pre, n_sig_var_pre, n_sig_var_pos, man_table_results, remove_fields
@@ -84,7 +88,10 @@ def preimp_qc(input_type: str = None, dirname: str = None, basename: str = None,
8488
hl.default_reference(new_default_reference=reference)
8589

8690
# read input
87-
mt = read_infile(input_type=input_type, dirname=dirname, basename=basename, annotations=annotations_file)
91+
if liftover:
92+
mt = liftover_to_grch38(input_type=input_type, dirname=dirname, basename=basename, annotations=annotations_file)
93+
else:
94+
mt = read_infile(input_type=input_type, dirname=dirname, basename=basename, annotations=annotations_file)
8895

8996
if 'is_case' in mt.col:
9097
gwas_pre, n_sig_var_pre = manhattan(qqtitle='Pre-QC QQ Plot', mantitle='Pre-QC Manhattan Plot').filter(mt)
@@ -373,6 +380,7 @@ def main():
373380
parser.add_argument('--annotations', type=str)
374381
parser.add_argument('--reference', type=str, default='GRCh38')
375382
parser.add_argument('--report', action='store_false')
383+
parser.add_argument('--liftover', action='store_true')
376384
# parser.add_argument('--qc_round', type=str, required=True)
377385

378386
# required for QC
@@ -399,8 +407,8 @@ def main():
399407
mind_thresh=arg.mind, fhet_aut=arg.fhet_aut, fstat_x=arg.fstat_x, fstat_y=arg.fstat_y,
400408
geno_thresh=arg.geno, cr_diff_thresh=arg.midi, maf_thresh=arg.maf, hwe_th_con_thresh=arg.hwe_th_con,
401409
hwe_th_cas_thresh=arg.hwe_th_cas, hwe_th_all_thresh=arg.hwe_th_all, annotations_file=arg.annotations,
402-
report=arg.report, export_type=arg.export_type, out_dir=arg.out_dir, reference=arg.reference,
403-
withpna=arg.withpna)
410+
report=arg.report, liftover=arg.liftover, export_type=arg.export_type, out_dir=arg.out_dir,
411+
reference=arg.reference, withpna=arg.withpna)
404412

405413

406414
if __name__ == '__main__':

gwaspy/utils/reference_liftover.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
import hail as hl
22
from gwaspy.utils.read_file import read_infile
3+
from gwaspy.utils.sample_annotations import add_sample_annotations
34

45

56
def liftover_to_grch38(
67
input_type: str = None,
78
dirname: str = None,
8-
basename: str = None):
9+
basename: str = None,
10+
**kwargs):
911

1012
lifted_over = f'{dirname}{basename}.liftover.grch38.mt'
1113
print('\nLifting over to GRCh38')
1214
mt = read_infile(input_type=input_type, dirname=dirname, basename=basename)
1315

16+
annotations = kwargs.get('annotations')
17+
if annotations:
18+
mt = add_sample_annotations(mt, annotations)
19+
1420
rg37 = hl.get_reference('GRCh37')
1521
rg38 = hl.get_reference('GRCh38')
1622
rg37.add_liftover('gs://hail-common/references/grch37_to_grch38.over.chain.gz', rg38)

0 commit comments

Comments
 (0)