molgenis / NIPTeR

R Package for Non Invasive Prenatal Testing (NIPT) analysis
GNU Lesser General Public License v3.0
40 stars 16 forks source link

Calculate z-score for chrX #9

Closed mdphan closed 6 years ago

mdphan commented 6 years ago

Hi,

Is there a way to calculate z-score for chrX, so that if reference samples are XX then a z-score > 3 would indicate XXX and a z-score < -3 would indicate monoX sample?

Best regards,

Duy

ljohansson commented 6 years ago

Dear Duy,

Unfortunately we did not include Z-score calculations for sex chromosomes in the NIPTeR package, because of issues in creating the control baseline with different percentages of fetal DNA, leading to different percentages of X chromosomes in case of an XY fetus.

Regards, Lennart

mdphan commented 6 years ago

Hi,

Thank you for your quick reply. I realize that the Z-score calculation for chrX is not included in NIPTeR but the gc-correction and chi-squared correction data for chrX are already calculated by NIPTeR so I am hoping that you could point me to a way to extract these data and apply Z-score calculations. I'll use a reference set of only XX fetus to control the baseline. Hope that makes sense.

Cheers,

Duy

ljohansson commented 6 years ago

Dear Duy,

I think the most straightforward way is to make a standard Z-score calculation: First calculate the fractions of the reads mapping X chromosome for all samples ( Sum corrected reads on the X-chromosome / Sum corrected reads on all chromosomes (or all autosomes) ). These reads should be in the NIPTSample object $autosomal_chromosome_reads and $sex_chromosome_reads. Then calculate the Z-score: (fraction X sample - average fraction X control samples ) / (standard deviation fraction X control samples)

In short (sample - mean_controls) / stdev_controls.

I hope this helps.

Regards, Lennart

mdphan commented 6 years ago

Thanks, I think I've got it now.

#Calculate Z score for chrX
    #test sample
    sum_corrected_reads_chrX <- sum(sample_of_interest$sex_chromosome_reads[[1]][1,],sample_of_interest$sex_chromosome_reads[[2]][1,]) # F & R read counts for chrX
    sum_corrected_reads_refchr <- sum(sample_of_interest$autosomal_chromosome_reads[[1]], sample_of_interest$autosomal_chromosome_reads[[2]]) # F & R read counts for all autosomes
    fraction_chrX <- sum_corrected_reads_chrX / sum_corrected_reads_refchr #fractions of the reads mapping X chromosome for test sample
    #Control group
    sum_corrected_reads_chrX_ctrl <- map_dbl(1:length(control_group$samples), function(x) sum(control_group$samples[[x]]$sex_chromosome_reads[[1]][1,], control_group$samples[[x]]$sex_chromosome_reads[[2]][1,]))
    sum_corrected_reads_refchr_ctrl <- map_dbl(1:length(control_group$samples), function(x) sum(control_group$samples[[x]]$autosomal_chromosome_reads[[1]], control_group$samples[[x]]$autosomal_chromosome_reads[[2]]))
    fraction_chrX_ctrl <- sum_corrected_reads_chrX_ctrl / sum_corrected_reads_refchr_ctrl 
    average_fraction_X_ctrl <- mean(fraction_chrX_ctrl)
    sd_fraction_X_ctrl <- sd(fraction_chrX_ctrl)
    #Z-score 
    z_score_X <- (fraction_chrX - average_fraction_X_ctrl)/sd_fraction_X_ctrl

Cheers

Duy

ljohansson commented 6 years ago

Seems correct. Good luck with your calculations.

Cheers, Lennart

GreeshmaThulasi commented 6 years ago

Hi @mdphan , Is the code you mentioned is working? Is it able to pick up the sex chromosomal aneuploidy? Could you please direct me to find a problem of checking sex chromosomal aneuploidy ?

Thanks with regards Greeshma.

mdphan commented 6 years ago

Hi @GreeshmaThulasi,

I believe the code works. However, I find that the false positive rates are quite high for monosomy X. This is also reported by different groups using different methods so it's not NIPTeR specific. Still don't know how to improve this.

Cheers,

Duy

ljohansson commented 6 years ago

An interesting paper in this context:

R. E. Reiss, M. Discenza, J. Foster, L. Dobson, and L. Wilkins-Haug, “Sex chromosome aneuploidy detection by noninvasive prenatal testing: helpful or hazardous?,” Prenat. Diagn., vol. 37, no. 5, pp. 515–520, 2017.

GreeshmaThulasi commented 6 years ago

Hi @mdphan , Here we are only getting z-score of x. But how can we say it as a male, female, XXX, XXY or XYY ? If I'm getting a z-score as 1.5, what can I infer as the sex call of that fetus?