Skip to content

Add support for inverting phase of genotypes with setGT plugin #2367

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

Merged
merged 1 commit into from
Mar 5, 2025

Conversation

rwk-unil
Copy link
Contributor

Hello,
I added an option to invert the phase of diploid genotypes in the setGT plugin.
So 0|1 becomes 1|0.

This is useful when one wants to invert the whole phase of a file, or selected samples, or based on a filter.

The function only inverts the phase of diploid genotypes (checks ngt==2 and if bcf_int32_vector_end is present).
Phase flag is set correctly per BCF specs. Note unphased genotypes are also swapped so 0/1 becomes 1/0.

I hope we can get this merged, let me know if there are any changes you would like me to make.

Best regards,
Rick

plugins/setGT.c Outdated
@@ -113,6 +114,7 @@ const char *usage(void)
" X .. allele with bigger read depth as determined from FMT/AD\n"
" p .. phase genotype (0/1 becomes 0|1)\n"
" u .. unphase genotype and sort by allele (1|0 becomes 0/1)\n"
" i .. inverse phase of genotype (0|1 becomes 1|0)\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a native speaker, but I think a better description would be "invert the genotype phase"

plugins/setGT.c Outdated
@@ -364,6 +367,21 @@ static inline int unphase_gt(int32_t *ptr, int ngts)
return changed;
}

// inverse phase for a single sample, ngts is the ploidy
Copy link
Member

@pd3 pd3 Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

invert, not inverse, here and everywhere..

@pd3
Copy link
Member

pd3 commented Feb 24, 2025

Thank you for the pull request. Please add a test, see test/test.pl, and fix the language, then it can be merged.

@rwk-unil
Copy link
Contributor Author

@pd3 thank you for your response, I fixed the language and added a test case.

Best regards,
Rick

@pd3 pd3 merged commit 8682b1b into samtools:develop Mar 5, 2025
6 of 7 checks passed
@pd3
Copy link
Member

pd3 commented Mar 5, 2025

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants