How to extract a subtree of my tree?

I have two related questions.

  1. Technical one: I want to extract my maternal subtree of the tree I have. This includes my mother, every ancestor of hers, and every descendents and relatives (siblings, their spouses, their ancestors, etc.) of her ancestors, up to (but excluding) her marriage with my father. That is, EVERYONE coming from the maternal side, even those not blood-related, except her descendants.
    I want to extract the whole maternal tree to make a new Gramps family tree. That is, I want to maintain vertices (individuals), topology (relationshipts), notes, attributes, sources, etc., and not only a list of persons. Obviously, I cannot maintain shared events with anyone from the paternal side, but that is ok.

  2. Advice request: I am interested in best practices whether it is advised or not to split my tree into paternal and maternal subtrees kept in separate databases.

Apart of the marriage of my father & mother, these trees are known to be absolutely unconnected. Thus, from a topological point of view, it seems reasonable to handle them separately. This would aopproximately halve the number of entries and would minimize name clashes, when common surnames (though unrelated) appear on both sides. Also, I find it cumbersome to implement filters for certain branches of my tree. Is it worth it to keep two trees separately? Obviously, in that case, I’d have to housekeep descendents (me & siblings) in both trees simultaneously, but this seems to be a small price. Any advice on this?

Gramps AIO64-5.1.6-1, Windows 10

1 Like

What about you an any of your descendants? Your tree includes your maternal and paternal branches.

Unless you are creating a new database to give to someone else, I never recommend splitting a single tree into separate smaller branch trees each to be maintained as their own database/tree. You would be maintaining duplicate place records in all trees/databases.

That said, I have a set of filters that selects your criteria.

Filter 1:
Ancestral filters: Ancestors of <person>

Filter 1a:
Family filters: Siblings of <filter> match (Filter 1)

Note: I had two instances where I know of an endline ancestor’s sibling but not their parents. I had these siblings as children of the same family with no parents. The sibling descents were not being included because there were no common ancestors in the tree.

Filter 2:
Descendant filters: Descendants of <filter> match (Filter 1)
General filters: People matching the <filter> (Filter 1)
Descendant filters: Descendants of <filter> match (Filter 1a if needed)
General filters: People matching the <filter> (Filter 1a if needed)
Options: At least one rule must apply

Filter 3:
Family filters: Spouses of <filter> match (Filter 2)

Filter 4:
General filters: People matching the <filter> (Filter 2)
General filters: People matching the <filter> (Filter 3)
Family filters: Spouses of <filter> match (Filter 3)
Family filters: Parents of <filter> match (Filter 3)
Family filters: Siblings of <filter> match (Filter 3)
Family filters: Children of <filter> match (Filter 3)
Options: At least one rule must apply

You can now create an export Gramps (XML) file. In the Export options use Filter 4 as the person filter, Set the reference filter to Do not include records not linked to a selected person.

You would need to do this for both parents to untangle both branches.

If you want to maintain separate raw media file folders for each database create the Export files using the Gramps XML Package output option.


I would not split my tree to work on two separate databases with GRAMPS
to much hassle what I do do, is import (annually) the two trees I have
on Ancestry specifically for DNA purposes as GEDCOM’s (much stripped
out) import them to GRAMPS, clean up, export back to GEDCOM and hence to
Ancestry (other online facilities are available). This way every year or
so you clear the junk that inevitably accumulates without the messing
around online.
Yes the original trees on Ancestry did come from a filtered GRAMPS export.
Why two trees on Ancestry because each tree has only one living person
me or my wife and should help other people to concentrate on the individual.
There is no such thing as absolutely unconnected and at some point with
two you would probably have to merge them again.

  1. I am pretty sure, that if there was any interconnection between my maternal and paternal trees, that was well before the last source I can dig up. This likely applies to many peasant families that were locally bound by land and only ma&pa left (independently) for a more global life from opposite ends of the world.

I understand that for all practical matters, keeping one tree is better than two trees (it seems to me that you and other external sources agree on this). I nevertheless want to filter occasionally for one side only, so the thechnical question remains.

  1. Theoretically, if my mother died before her marriage, then my mother’s side would become a completely unconnected subgraph of the whole tree, i.e., one can split it off by removing a single marriage-with-children edge, hence it is a branch. That is what I seek to implement by rules (and not by temporarily removing any relationships).

Mathematically speaking the problem is trivial: find all relatives of Mother except those that are related through Father (excluding descendants too). Even more simply speaking: find all persons that has a strictly smaller distance to Mother than to Father. But in Gramps, I struggle to implement this via filters in an efficient way that does not make redundant passes (which is slow). With the present set of rules, it seems to require a recursive match:

  1. A = Find ancestors of my mother, including my mother (because I want to include her siblings too).
  2. B = Find siblings of all persons in A.
  3. C = Find spouses of all persons in B. This would however find my father too, which I must then exclude (how to do that easily?)
  4. D = Find siblings of C (I want to broaden the horizon to include the siblings of partners too)
  5. iterate potentially ad infinitum as there is no limit how broad a tree can be (spouse of a sibling of a spouse of a sibling of …).

Is there really no simpler mechanism to find people that are connected to the rest of the tree through a single node (mother)?

1 Like

I had similar problem to separate subtrees for a bit another purpose for export. Looks like not only me needs it. So, my proposition to add such high-level filter is still actual

1 Like

My own solution is very difficult, but it can do exactly the same what you need.

I can send these rules settings If another more simple solutions dont work for you.

1 Like

This is a standard set of filters I keep so when I create a NarrWeb for a cousin I just plug in the cousin and I have their branch.

There is the Not Related tool that will find everyone that does NOT have a click path back to the Active person.

To use it for your purpose you would remove your mother from your family’s record. Then run the tool with her as the active person giving you everyone that you cannot use just the Relationships view to click to another person, the click path. The tool will allow you to Tag every person found.

Then it would be easy to create a filter based on the Tag. General filters: People with the <tag>. Set the Options for the filter to Return values that do not match the filter rules.

1 Like

@DaveSch, @Urchello: I appreciate the rule sets, but I find these complicated to create, even more complicated to modify/extend and prone to errors. The more subrules there are in a filter, the more error-prone it will be. Algorithmically, it should be simple, as I said above.

Regarding “remove your mother from your family’s record”: I would rather avoid removing relationships explicitly. Filtering should not involve invasive steps.

With tags, I would explicitly commit persons to clades, which is unnecessary, as the implicit information is already there in the topology. Moreover, tags will quickly become untenable: in theory, one should have as many tags as people in a tree, because each person is a potential “root” to its own branch when filtering.

Can I write my own rules in Python and integrate those?

Yes. Use a rule like the AgeAtDeath rule in the third-party addon repository as a template. This builds a list of people in the prepare method and has a very simple apply method.

You will also need an associated gpr file to register the addon.

For simple tree walking code, the Not Related tool is probably a good starting point.

Also have a look at the librecurse utility code. It may do what you want.

Yes, you can write your own rules. As examples, there are 2 expansion “packs” of addon rule plugins in the plugin manager plus some Rules from the Isotammi project.

You can design rules interactively (and without learning to build interface) with the SuperTool addon. Scrape the parameters of Filter gramplets into a Custom Filter using the Filter+ addon gramplet. (It can be illuminating to scrape the Filter+ parameters and look at the resulting custom filter code.) And easily visualize and change parameters of multi-stage Custom Filters with the FilterParams addon.

Also see:

Could it be simpler, like this:

  1. People with a common ancestor with <filter> match (for the <filter> here, I used a custom filter that uses the Active Person rule, and made either the Father or Mother the active person)

  2. Descendants of <\filter> (again, I used my custom Active Person filter)

  3. Combine the results of the previous two filters in another filter with the option “Exactly one rule must apply”.

I guess you could also add spouses at some point.

I think that it might be useful to start with creating some rules related to Families.

  1. Find “Progenitor families of <person/family/filter>” rule
    with 2 parameters: number of generations limit (default 5 generations), checkbox “include only preferred parents” (default as selected)
    (This is somewhat similar to the “End of Line” report – as it returns ONLY the last known ancestors family in each line within the generation limit.)
  2. Find “Descendant families of <person/family/filter>” rule
    with 2 parameters: number of generations limit (default 2 generations), checkbox “include only biological descendant families” (default as selected)
  3. Find “Family members of <person/family/filter>” rule
    with 2 parameters: “include only biological descendants” (default as selected), checkbox “include spouses of descendants” (default as selected)
    Rule exists in Rule expansions: People who are part of families matching <filter>
1 Like

yeah, @emyoulation . This is something similar what I meant.
And one more idea… What about ability create special directory “custom_filters” which could be fullfilled via commits. It will be the most usefull sets of filters. But I think custom filters should be grouped in the app interface.

But now they all are listed in one long list. This is not very convenient to use.


The Rules have sub-categories.

Defining an evolutionary path to integrate improved or expanded Rules is worth exploring.

For instance a built-in variation of the 2nd suggested Rule exists as:

But it does not allow specifying a Person or (Person/Family) filter. Nor does it optionally allow the Generations to be limited. Nor optionally limit to Biological descendants.

So an add-on could be developed based on the built-in. And, after it is tested and optimized, the add-on might replace the built-in.

1 Like

Having the same problem, I wrote GitHub - azrdev/gramps_personfilter_excludesubtree – though I have not yet found the time/motivation to try to upstream it


This looks promising!

In the simplest case, where the two subparts of the tree are only connected through a single link (e.g. Mother-Father), it is sufficient to find all relatives of Mother by traversing the tree, and stopping whenever Father is encountered. If I understand your code, this is exactly what it can perform.

But for this, one has to be sure that no other links exist between the maternal and paternal sides. For complex trees however, one cannot excluded prior filtering that there are other connections existing, in which case everyone would be included in the resulting list (except the explicitly excluded ones), due to the additional link(s). Your method allows to specify a list of such persons (links), where the algorithm should stop, am I right? But this requires explicit knowledge about all the interactions of the two interconnected subgraphs.

A more general (though computationally more intensive) method would be to define that anyone closer to M than to F is on the Maternal side. Given two distance matrices D_M, D_F of all individuals computed against M and F, respectively, D_M_i would give the shortest distance of person i to M, and D_F_i the shortest distance from i to F. Then select only those i for which it is true that D_M_i < D_F_i.

Can this be implemented? Does Gramps calculate or maintain a distance matrix of individuals?

You might want to check to see if the mother and father are distant cousins with the 5.1 unreleased Consanguinity addon gramplet by @ukulelehans.

Yes, you can make sure, that they are not cousins with this addon. But what if they are? The issue remains how to identify the maternal part of your tree in case there are multiple relationships.

Whether using that approach or any other, it should be possible to code a filter rule such as “People who are more closely related to <person1> than to <person2>”, perhaps with a checkbox indicating whether people who are equally distant should be included or excluded. (Is it really that simple, or would you give different weight to otherwise equally distant people depending on other factors, in order to break the tie?) You could submit a feature request and maybe one of the developers would take it up.

That’s changing the requirements. The requirement was simply “one has to be sure that no other links exist between the maternal and paternal sides”.

I just had to do this for a brother-in-law. He wanted what research had been found on his side of the Tree.

So I created a tag (Keep) then a series of People filters and applied the “Keep” tag to the filter wit the Add/Remove Tag addon tool:

  • The direct ancestors of my sister
  • The siblings or the children of people Tagged with “Keep”

Then I disconnected my sister from our parents.

Then another filter for the People related to my brother-in-law and applied the “Keep” tag again.

Now create a filter for People with a “Keep” tag. Export the them to a Gramps XML.

That trimmed the Tree from 43,643 to 3,059 people.