{"id":16864752,"url":"https://github.com/38/grass-demo","last_synced_at":"2025-04-05T11:41:04.260Z","repository":{"id":66472148,"uuid":"329775307","full_name":"38/grass-demo","owner":"38","description":null,"archived":false,"fork":false,"pushed_at":"2021-09-01T20:17:18.000Z","size":232,"stargazers_count":3,"open_issues_count":9,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-10T22:35:19.226Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/38.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-15T01:15:13.000Z","updated_at":"2022-02-09T17:43:53.000Z","dependencies_parsed_at":"2023-02-22T12:30:47.337Z","dependency_job_id":null,"html_url":"https://github.com/38/grass-demo","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/38%2Fgrass-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/38%2Fgrass-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/38%2Fgrass-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/38%2Fgrass-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/38","download_url":"https://codeload.github.com/38/grass-demo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332511,"owners_count":20921852,"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":[],"created_at":"2024-10-13T14:43:44.525Z","updated_at":"2025-04-05T11:41:04.237Z","avatar_url":"https://github.com/38.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# grass-demo\nGenomic Records AbStractionS\n\n## GRASS Query DSL\n### Introduction\n\nThe GRASS Query DSL allows you use the GRASS library without having a good knowledge about\nRust and GRASS library. The query language is build on top of Rust's procedual macro, and \nit allows user to write simple query language which turns to be Rust code when it gets compiled.\n\n### Basic Syntax\n\nTo use the GRASS Query DSL, you can simply use the macro `grass::grass_query`. \nFor example, you can write a rust source code:\n\n```rust\ngrass::grass_query! {\n\t// your query DSL code here\n}\n```\n\n## Let binding\n\nYou can bind any expression to variables, for example, you can use `open` to load any file on disk,\n`intersect` to get a iterator of intersections, it also can be bind to a variable.\n\nFor instance:\n\n```rust\ngrass::grass_query! {\n\tlet first_file = open(\"a.bed\");\n\tlet second_file = open(\"b.bed\");\n\tlet intersected = intersect(first_file, second_file);\n}\n```\n\n## Calling Method\n\nIn the GRASS DSL, you can call any assocated method / trait method defined by GRASS. \nFor example, you can cast a BAM file to a BED file by calling `as_bed3` trait method.\n\n```rust\ngrass::grass_query!{\n\tlet input_file = open(\"path/to/file.bam\");\n\tinput_file | as_bed3() | cat();\n}\n```\n\n## Open a genomic record file\n\n```rust\n// grass-query-example.rs\ngrass::grass_query!{\n\tlet input_file = open(\"path/to/file.bam\");\n}\n```\n\nnote that the query DSL will automatically detect the file format and generate properate file format handling code.\n\n## Intersect multiple files\n\nFor example, intersect two input bed file and save the result as a bed3 file.\n\n```rust\ngrass::grass_query! {\n\tlet first_file = open(\"a.bed\");\n\tlet second_file = open(\"b.bed\");\n\tintersect(first_file, second_file) | as_bed3() | save(\"intersect-result.bed\");\n}\n```\n\n## Filtering\n\n### You can use `where` to filter the records. \nThe filtering condition you can use `_1`,.... for the first, second, third intervals and `_0` for the overlapped intervals.\n\nFor example, filter out all the intervals that is shorter than 20 bases and save the result to file.\n\n```rust\ngrass::grass_query! {\n\tlet first_file = open(\"a.bed\");\n\tfirst_file | where(_0.length() \u003e 20) | save(\"filtering-result.bed\");\n}\n```\n\n## Mixing GRASS DSL and Rust code\n\nYou can use `grass::grass_query_block` macro for this purpose. \n\n```rust\nuse grass::grass_query_block;\nfn main() {\n\tgrass_query_block! {\n\t\tlet a = open(\"a.bed\");\n\t\tlet b = open(\"b.bed\");\n\t\tlet result = intersect(a, b);\n\t}\n\n\tuse grass::properties::*;\n\n\tfor item in result {\n\t\tprintln!(\"{:?} {} {}\", item.chrom(), item.begin(), item.end());\n\t}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F38%2Fgrass-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F38%2Fgrass-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F38%2Fgrass-demo/lists"}