Skip to content

Add per-population copy number (PPCN) normalization to anvi-script-gen-function-matrix-across-genomes#2746

Merged
meren merged 4 commits into
merenlab:masterfrom
jessika-fuessel:function-matrix-ppcn-pr
Jul 12, 2026
Merged

Add per-population copy number (PPCN) normalization to anvi-script-gen-function-matrix-across-genomes#2746
meren merged 4 commits into
merenlab:masterfrom
jessika-fuessel:function-matrix-ppcn-pr

Conversation

@jessika-fuessel

Copy link
Copy Markdown
Contributor

I would like to compare functional capacities across metagenomic assemblies using individual functional annotations such as KEGG kofams or NCBI's COGs. But similar to estimating metabolic capacity, the problem when comparing assemblies rather than individual genomes is that each function is most likely present everywhere at least once in complex communities and different samples can contain very different number of populations, either for ecological reasons or differences in sequencing depth. So Iva came up with the per-population-copy-number (PPCN) normalization to be able to compare the metabolic capacities acros metagenomic assemblies by normalizing the frequency of metabolic pathway annotations using the estimated number of populations based on SCGs. I want to do the same thing for functional annotations in an automated way and therefore added a --per-population-copy-number flag to the 'anvi-script-gen-function-matrix-across-genomes' script. When you add the flag, the script generates an additional output with PPCN normalized frequencies of functional annotations of whichever kind you chose.

Same as before, the population counts are estimated from single-copy core genes via anvi'o's NumGenomesEstimator (the mode of SCG hits per domain, summed across Bacteria, Archaea, and Eukarya). You need to provide an external-genomes file for this flag to work and the contig-dbs should contain metagenomic assemblies or long read metagenomes, in which case assembly probably wouldn't be strictly necessary.

One little thing I changed is the column order that 'anvi-script-gen-function-matrix-across-genomes' generates. Currently, the 'key' is the first column, then the contig-dbs with their numbers and then, at the very end, you can find a column with the functional annotation. I think it makes more sense to have that in front as well, especially if you have a large set of contig-dbs.

I created the code with the help of Claude AI

…n-function-matrix-across-genomes

Adds a --per-population-copy-number flag that reports an additional matrix in
which each function's frequency in a metagenomic assembly is divided by the number
of populations estimated to be present in that assembly. Population counts are
estimated from single-copy core genes via anvi'o's NumGenomesEstimator (the mode
of SCG hits per domain, summed across Bacteria, Archaea, and Eukarya), the same
estimate anvi-display-contigs-stats reports. This normalization, introduced by
Iva Veseli (Veseli et al. 2025), makes functional capacity comparable across
metagenomic assemblies of very different community sizes.

The flag works only with an external-genomes file (-e), since the normalization is
meaningful for whole metagenomic assemblies (or long-read metagenomes) but not for
individual genomes or a genomes storage database. Assemblies whose SCGs are too
sparse to estimate a population count are reported as NA rather than dividing by
zero. All matrix outputs also lead with their descriptive columns (key, function,
accession) before the per-genome columns. Help page and CLI help included.
@jessika-fuessel jessika-fuessel force-pushed the function-matrix-ppcn-pr branch from 7b5b2cd to 133e413 Compare July 12, 2026 10:57
@meren meren self-requested a review July 12, 2026 13:21
meren added 2 commits July 12, 2026 15:40
the original flag doesn't matches the anvi'o conventions for parameters, and it does not signal 'extra output will come when you use it' immediately.

Hence the change.
@meren

meren commented Jul 12, 2026

Copy link
Copy Markdown
Member

I made a small change to better follow anvi'o conventions on flags. The parameter is now called --add-per-population-copy-number, and it is changed everywhere.

I also added you to the list of authors of the program.

I will merge it now as it appears to be working. But then I will rename this script from anvi-script-gen-function-matrix-across-genomes to anvi-gen-function-matrix. Simply because with the addition of PPCN-normalized reporting, it does much more than what scripts generally do. Also, this flag already insinuates that this program can be ran on assemblies. So 'genomes' in the name doesn't make much sense anymore.

More later.

@meren meren merged commit d29c268 into merenlab:master Jul 12, 2026
2 checks passed
@meren meren mentioned this pull request Jul 12, 2026
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