Skip to content

Placing on a tree

Ali Osman Berk Şapcı edited this page Sep 26, 2026 · 3 revisions

Phylogenetic placement on a backbone tree

Since the references in a given index also share an evolutionary history, finding a placement on a phylogeny (or, less ideally, on a taxonomy) might provide better downstream performance and interpretability. krepp place subcommand performs phylogenetic placement on a backbone tree, which is either used to build the target index or specified during the query time (both using the -t,--nwk-file option) as follows:

krepp place -i /path/to/index -q /path/to/query.fastq -t /path/to/backbone.nwk --num-threads 16 -o /path/to/output.jplace

The output, by default, is an information-rich JSON, namely the jplace format (version 3) (see the description here). Each placed read is a list entry under the placements field. For each placed read, n field stands for the read ID, and p is another list of potentially multiple placements represented by several values:

  1. edge_num: the placement edge, the jplace file contains a Newick tree decorated with edge numbers in curly brackets
  2. pendant_length: the branch length for the placement edge, can be negative.
  3. distal_length: the length from the distal (away from the root) edge to the placement location (mid-point by default)
  4. likelihood: the likelihood of the distance estimation (not comparable across placements)
  5. like_weight_ratio: weight of placements if there are multiple equally good placements for a sequence
  6. distance: estimated distance to the clade under the placement edge

krepp does not report unplaced sequences, but the total number of queries can be found in the metadata field of the jplace file. We recommend gappa for analyzing and visualizing jplace files. Several other tools, such as tax2tree and treeio, can also process jplace files.

Alternatively, you can use --tabular option to report placements in a tab-separated format, where each row corresponds to a placement, and hence, a read can appear in multiple rows. The format is quite intuitive:

# software: krepp       version: v0.10.2 invocation :krepp place -i index_toy/ -q query_toy.fq --tabular
# (G001917855:0.4290{0},(G001918235:0.5280{1},(((((G000526415:0.1764{2},G001306135:0.2276{3})N1779:0.0365{4},(G000016665:0.1683{5},(G000735195:0.0276{6},G000018865:0.0229{7})N2640:0.1610{8
})N1780:0.0609{9})N1532:0.1058{10},G000021685:0.3879{11})N1303:0.0337{12},(G002010545:0.3919{13},((G001050235:0.1711{14},G001306055:0.1635{15})N5461:0.1783{16},G001567105:0.2932{17})N2355:
0.1933{18})N1304:0.0560{19})N1099:0.0288{20},(G000702505:0.1445{21},G001914715:0.1983{22})N1305:0.2353{23},(G001796575:0.3977{24},G001795015:0.4213{25},((G001796415:0.2756{26},(G002010445:
0.3607{27},G001795205:0.3152{28})N3984:0.0458{29})N3292:0.0233{30},(((G000025025:0.0115{31},G001889305:0.0109{32})N4334:0.0068{33},G000830905:0.0305{34})N3987:0.0117{35},((G000741845:0.003
9{36},G001610775:0.0001{37})N5905:0.0014{38},G000341695:0.0022{39})N4337:0.0167{40})N3634:0.2994{41})N2954:0.1317{42})N1788:0.1622{43})N916:0.0295{44})N736:0.0348{45})N432:0.0257{46};
SEQ_ID  DISTAL_NODE     EDGE_NUM        LWR     DIST
||61435-4122    G000341695      39      1.0000  0.0933
||61435-4949    G000341695      39      0.1582  0.0505
||61435-4949    G000741845      36      0.2696  0.0326
||61435-4949    N5905   38      0.2240  0.0427
||61435-4949    N4337   40      0.1900  0.0468
||61435-4949    G001610775      37      0.1582  0.0505
||61435-317     N3634   41      0.0821  0.0162

The first commented line is for the version information, together with the command used. The second line is the decorated Newick tree as it would appear in a jplace file. DISTAL_NODE is the label of the distal node (including internal nodes) under the placement edge (NA if the node is not labeled). EDGE_NUM is the same as edge_num in the jplace format.

By default, krepp assigns edge numbers ({i} decorations) by post-order traversal of the tree as specified by jplace. If you prefer to fix the edge numbering yourself (e.g., to keep a decoration consistent across multiple place runs or with other tools), you can also use a jplace-style decorated tree with -t (e.g., (RefA:0.1{10},RefB:0.2{11}){12};).

Configuring the placement algorithm

The default algorithm reports all placements with distances indistinguishable from the distance of the closest tip (--multi). If --no-multi is given, krepp reports only the best placement, which corresponds to the edge above the largest clade among potential placements.

The placement algorithm applies a more aggressive filtering compared to krepp dist. This is controlled by the --filter option, which is on by default. It leaves query sequences without sufficient evidence unplaced. krepp considers a placement weak if the number of k-mer matches below the Hamming distance $\tau$ (the option --tau, default: 2) is $\leq 1$. One can give the --no-filter flag to disable the filtering, or relax it by increasing the --tau.

Placing on a taxonomy

krepp is not primarily designed for taxonomic classification, but since its placement algorithm is branch length agnostic, it can place queries on a taxonomic tree, which is essentially a multifurcating tree without branch lengths. To do so, use the -l (--lineage-file) option instead of the -t (--nwk-file). This option expects taxonomic lineages in Greengenes2/GTDB format (see an example here). The lineage file is supposed to be a mapping between reference IDs as they appear in the index and their taxonomic labels at fixed ranks. By default, krepp converts these lineages into a multifurcating Newick tree and outputs a jplace file (alternatively, use --tabular).

More ideally, if you have a phylogeny and you are still interested in the taxonomic composition of your sample, you can decorate a Newick tree using tax2tree. Then, with the --tabular flag, you can obtain placements on taxonomic lineages which would be in the DISTAL_NODE column.

Summarizing placements

If you would like to summarize all the placements to derive sequence abundances across the nodes of the given backbone tree, use the --summarize option. This outputs both the weighted raw counts and normalized abundances. Each placed read gets a count value of 1, shared across all placed edges, and unplaced reads are ignored in the normalization. Note that these abundances cannot be interpreted as taxonomic abundance profiles as they are not aggregated. In other words, placements on an edge (or a taxonomic group) are not counted toward its parents.

Clone this wiki locally

⌂ 换网址