Skip to content

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

Merged
pd3 merged 1 commit intosamtools:developfrom
rwk-unil:develop
Mar 5, 2025
Merged

Add support for inverting phase of genotypes with setGT plugin#2367
pd3 merged 1 commit intosamtools:developfrom
rwk-unil:develop

Conversation

@rwk-unil
Copy link
Copy Markdown
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

Comment thread plugins/setGT.c Outdated
" 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
Copy Markdown
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"

Comment thread plugins/setGT.c Outdated
return changed;
}

// inverse phase for a single sample, ngts is the ploidy
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@pd3
Copy link
Copy Markdown
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