{"id":26880122,"url":"https://github.com/sstadick/rust-lapper","last_synced_at":"2025-04-08T03:18:58.604Z","repository":{"id":35093580,"uuid":"205283819","full_name":"sstadick/rust-lapper","owner":"sstadick","description":"Rust implementation of a fast, easy, interval tree library nim-lapper","archived":false,"fork":false,"pushed_at":"2024-04-02T09:41:09.000Z","size":144,"stargazers_count":58,"open_issues_count":6,"forks_count":8,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-04T19:57:20.125Z","etag":null,"topics":["algorithms","bioinformatics","interval","interval-tree","intervaltree","rust","tree"],"latest_commit_sha":null,"homepage":"https://docs.rs/rust-lapper","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sstadick.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-08-30T01:49:52.000Z","updated_at":"2025-01-22T20:20:28.000Z","dependencies_parsed_at":"2023-02-12T06:31:41.015Z","dependency_job_id":null,"html_url":"https://github.com/sstadick/rust-lapper","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sstadick%2Frust-lapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sstadick%2Frust-lapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sstadick%2Frust-lapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sstadick%2Frust-lapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sstadick","download_url":"https://codeload.github.com/sstadick/rust-lapper/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247767239,"owners_count":20992548,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["algorithms","bioinformatics","interval","interval-tree","intervaltree","rust","tree"],"created_at":"2025-03-31T13:34:49.307Z","updated_at":"2025-04-08T03:18:58.565Z","avatar_url":"https://github.com/sstadick.png","language":"Rust","readme":"# rust-lapper\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/sstadick/rust-lapper/actions?query=workflow%3Aci\"\u003e\u003cimg src=\"https://github.com/sstadick/rust-lapper/workflows/ci/badge.svg\" alt=\"Build Status\"\u003e\u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/crates/l/rust-lapper.svg\" alt=\"license\"\u003e\n  \u003ca href=\"https://crates.io/crates/rust-lapper\"\u003e\u003cimg src=\"https://img.shields.io/crates/v/rust-lapper.svg?colorB=319e8c\" alt=\"Version info\"\u003e\u003c/a\u003e\u003cbr\u003e\n\u003c/p\u003e\n\n[Documentation](https://docs.rs/rust-lapper)\n[Crates.io](https://crates.io/crates/rust-lapper)\n\nThis is a rust port of Brent Pendersen's\n[nim-lapper](https://github.com/brentp/nim-lapper). It has a few notable\ndifferences, mostly that the find and seek methods both return\niterators, so all adaptor methods may be used normally.\n\nThis crate works well for most interval data that does not include very long\nintervals that engulf a majority of other intervals. It is still fairly\ncomparable to other methods. If you absolutely need time guarantees in the\nworst case, see [COItres](https://github.com/dcjones/coitrees) and [IITree](https://docs.rs/bio/0.32.0/bio/data_structures/interval_tree/struct.ArrayBackedIntervalTree.html).\n\nHowever, on more typical datasets, this crate is between 4-10x faster\nthan other interval overlap methods.\n\nIt should also be noted that the `count` method is agnostic to data\ntype, and should be about as fast as it is possible to be on any\ndataset. It is an implementation of the [BITS\nalgorithm](https://academic.oup.com/bioinformatics/article/29/1/1/273289)\n\n## Serde Support\n\n`rust-lapper` supports serialization with serde for `Lapper` and `Interval` objects:\n\n```toml\n[dependencies]\nrust-lapper = { version = \"*\", features = [\"with_serde\"] }\n```\n\nSee `examples/serde.rs` for a brief example.\n\n## Benchmarks\n\nBenchmarking interval tree-ish datastructures is hard\nPlease see the\n[interval_bakeoff](https://github.com/sstadick/interval_bakeoff) project\nfor details on how the benchmarks were run... It's not fully baked yet\nthough, and is finiky to run.\n\nCommand to run:\n\n```\n./target/release/interval_bakeoff fake -a -l RustLapper -l\nRustBio -l NestedInterval -n50000 -u100000\n\n# This equates to the following params:\n# num_intervals\t50000\n# universe_size\t100000\n# min_interval_size\t500\n# max_interval_size\t80000\n# add_large_span\ttrue (universe spanning)\n```\n\nSet A / b Creation Times\n\n| crate/method     | A time   | B time   |\n| ---------------- | -------- | -------- |\n| rust_lapper      | 15.625ms | 31.25ms  |\n| nested_intervals | 15.625ms | 15.625ms |\n| bio              | 15.625ms | 31.25ms  |\n\n100% hit rate (A vs A)\n\n| crate/method                       | mean time  | intersection |\n| ---------------------------------- | ---------- | ------------ |\n| rust_lapper/find                   | 4.78125s   | 1469068763   |\n| rust_lapper/count                  | 15.625ms   | 1469068763   |\n| nested_intervals/query_overlapping | 157.4375s  | 1469068763   |\n| bio/find                           | 33.296875s | 1469068763   |\n\n\nSub 100% hit rate (A vs B)\n\n| crate/method                       | mean time  | intersection |\n| ---------------------------------- | ---------- | ------------ |\n| rust_lapper/find                   | 531.25ms   | 176488436    |\n| rust_lapper/count                  | 15.625ms   | 176488436    |\n| nested_intervals/query_overlapping | 11.109375s | 196090092    |\n| bio/find                           | 4.3125s    | 176488436    |\n\n[nested_intervals](https://docs.rs/nested_intervals/0.2.0/nested_intervals/)\n[rust-bio](https://docs.rs/bio/0.28.2/bio/)\n*Note that rust-bio has a new interval tree structure which should be faster than what is shown here*\n\n## Example\n\n```rust\nuse rust_lapper::{Interval, Lapper};\n\ntype Iv = Interval\u003cusize, u32\u003e;\nfn main() {\n    // create some fake data\n    let data: Vec\u003cIv\u003e = vec![\n        Iv {\n            start: 70,\n            stop: 120,\n            val: 0,\n        }, // max_len = 50\n        Iv {\n            start: 10,\n            stop: 15,\n            val: 0,\n        },\n        Iv {\n            start: 10,\n            stop: 15,\n            val: 0,\n        }, // exact overlap\n        Iv {\n            start: 12,\n            stop: 15,\n            val: 0,\n        }, // inner overlap\n        Iv {\n            start: 14,\n            stop: 16,\n            val: 0,\n        }, // overlap end\n        Iv {\n            start: 40,\n            stop: 45,\n            val: 0,\n        },\n        Iv {\n            start: 50,\n            stop: 55,\n            val: 0,\n        },\n        Iv {\n            start: 60,\n            stop: 65,\n            val: 0,\n        },\n        Iv {\n            start: 68,\n            stop: 71,\n            val: 0,\n        }, // overlap start\n        Iv {\n            start: 70,\n            stop: 75,\n            val: 0,\n        },\n    ];\n\n    // make lapper structure\n    let mut lapper = Lapper::new(data);\n\n    // Iterator based find to extract all intervals that overlap 6..7\n    // If your queries are coming in start sorted order, use the seek method to retain a cursor for\n    // a big speedup.\n    assert_eq!(\n        lapper.find(11, 15).collect::\u003cVec\u003c\u0026Iv\u003e\u003e(),\n        vec![\n            \u0026Iv {\n                start: 10,\n                stop: 15,\n                val: 0\n            },\n            \u0026Iv {\n                start: 10,\n                stop: 15,\n                val: 0\n            }, // exact overlap\n            \u0026Iv {\n                start: 12,\n                stop: 15,\n                val: 0\n            }, // inner overlap\n            \u0026Iv {\n                start: 14,\n                stop: 16,\n                val: 0\n            }, // overlap end\n        ]\n    );\n\n    // Merge overlaping regions within the lapper to simplifiy and speed up quries that only depend\n    // on 'any\n    lapper.merge_overlaps();\n    assert_eq!(\n        lapper.find(11, 15).collect::\u003cVec\u003c\u0026Iv\u003e\u003e(),\n        vec![\u0026Iv {\n            start: 10,\n            stop: 16,\n            val: 0\n        },]\n    );\n\n    // Get the number of positions covered by the lapper tree:\n    assert_eq!(lapper.cov(), 73);\n\n    // Get the union and intersect of two different lapper trees\n    let data = vec![\n        Iv {\n            start: 5,\n            stop: 15,\n            val: 0,\n        },\n        Iv {\n            start: 48,\n            stop: 80,\n            val: 0,\n        },\n    ];\n    let (union, intersect) = lapper.union_and_intersect(\u0026Lapper::new(data));\n    assert_eq!(union, 88);\n    assert_eq!(intersect, 27);\n\n    // Get the depth at each position covered by the lapper\n    for interval in lapper.depth().filter(|x| x.val \u003e 2) {\n        println!(\n            \"Depth at {} - {}: {}\",\n            interval.start, interval.stop, interval.val\n        );\n    }\n\n}\n```\n\n## Release Notes\n\n- `1.1.0`: Added insert functionality thanks to @zaporter\n- `0.4.0`: Addition of the BITS count algorithm.\n- `0.4.2`: Bugfix in to update starts/stops vectors when overlaps merged\n- `0.4.3`: Remove leftover print statement\n- `0.5.0`: Make Interval start/stop generic\n- `1.0.0`: Add serde support via the `with_serde` feature flag\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsstadick%2Frust-lapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsstadick%2Frust-lapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsstadick%2Frust-lapper/lists"}