|
| 1 | +# Models and Region Set objects in Gtars |
| 2 | + |
| 3 | +Gtars has multiple objects (structs/models) for representation of genomic regions and other related data. |
| 4 | + |
| 5 | +### 🟢 Region |
| 6 | + |
| 7 | +Region is Python representation of a genomic region. e.g. `chr1:100-200` + additional information. |
| 8 | + |
| 9 | +#### Example |
| 10 | + |
| 11 | +=== "Python" |
| 12 | + ```python |
| 13 | + from gtars.models import Region |
| 14 | + |
| 15 | + # Create a Region |
| 16 | + genomic_region = Region(chr="chr1", |
| 17 | + start=100, |
| 18 | + end=200, |
| 19 | + rest="peak1") |
| 20 | + print(genomic_region) |
| 21 | + |
| 22 | + ``` |
| 23 | + |
| 24 | +=== "Rust" |
| 25 | + ```rust |
| 26 | + use gtars::models::Region; |
| 27 | + |
| 28 | + // Create a Region |
| 29 | + let genomic_region: Region = Region { chr: "chr1".to_string(), |
| 30 | + start: 100, |
| 31 | + end: 200, |
| 32 | + rest: Some("peak1".to_string()) |
| 33 | + }, |
| 34 | + let identifier = genomic_region.digest(); |
| 35 | + |
| 36 | + println!("{:?}", identifier); |
| 37 | + |
| 38 | + ``` |
| 39 | + |
| 40 | + |
| 41 | +### 🟢 RegionSet |
| 42 | + |
| 43 | +RegionSet is Python representation of a genomic region set, commonly named as BED file. |
| 44 | + |
| 45 | + |
| 46 | +#### Quick example |
| 47 | +Open BED file from URL and get its identifier. |
| 48 | + |
| 49 | +=== "Python" |
| 50 | + ```python |
| 51 | + |
| 52 | + from gtars.models import RegionSet |
| 53 | + |
| 54 | + # Create a RegionSet from a url, or lcoal BED file. |
| 55 | + rs = RegionSet("https://data2.bedbase.org/files/d/a/dafd661aa70590999e0ff9e1980217db.bed.gz") |
| 56 | + |
| 57 | + # Get identifier for the RegionSet |
| 58 | + rs.identifier |
| 59 | + |
| 60 | + print(rs) |
| 61 | + |
| 62 | + ``` |
| 63 | +=== "Rust" |
| 64 | + ```rust |
| 65 | + use gtars::models::RegionSet; |
| 66 | + |
| 67 | + // Create a RegionSet from a url, or lcoal BED file. |
| 68 | + let rs = RegionSet::try_from("https://data2.bedbase.org/files/d/a/dafd661aa70590999e0ff9e1980217db.bed.gz").unwrap(); |
| 69 | + |
| 70 | + // Get identifier for the RegionSet |
| 71 | + let id = rs.identifier(); |
| 72 | + |
| 73 | + println!("{:?}", rs); |
| 74 | + ``` |
| 75 | + |
| 76 | +=== "TypeScript" |
| 77 | + |
| 78 | + ❗ Note: This is test example and may require additional setup to run. |
| 79 | + |
| 80 | + ```typescript |
| 81 | + import init from '@databio/gtars'; |
| 82 | + import { RegionSet } from '@databio/gtars'; |
| 83 | + |
| 84 | + init(); |
| 85 | + |
| 86 | + export type BedEntry1 = [string, number, number, string]; |
| 87 | + |
| 88 | + // Define entries (regions) |
| 89 | + export const entries1: BedEntry1[] = [ |
| 90 | + ['chr1', 100, 200, 'peak1'], |
| 91 | + ['chr2', 150, 250, 'peak2'], |
| 92 | + ['chr3', 300, 400, 'peak3'], |
| 93 | + ]; |
| 94 | + |
| 95 | + // Create a Region |
| 96 | + const rs = new RegionSet(entries1); |
| 97 | + |
| 98 | + console.log(rs); |
| 99 | + |
| 100 | + ``` |
| 101 | + |
| 102 | +❗ Note: RegionSet can be created from a local file path, URL, or by passing a list (vector) or Region objects. |
| 103 | + |
| 104 | +#### Main commands in Python |
| 105 | + |
| 106 | +- Load a BED file from local path or URL |
| 107 | +```python |
| 108 | +rs = RegionSet("path/to/bedfile.bed") |
| 109 | +``` |
| 110 | +- Get number of regions |
| 111 | +```python |
| 112 | +len(rs) |
| 113 | +``` |
| 114 | +- Calculate mean reagion width |
| 115 | +```python |
| 116 | +rs.mean_region_width() |
| 117 | +``` |
| 118 | +- Get last base pair location for each chromosome |
| 119 | +```python |
| 120 | +rs.get_max_end_per_ch() |
| 121 | +``` |
| 122 | +- Get number of base pairs in the region set |
| 123 | +```python |
| 124 | +rs.get_nucleotide_length() |
| 125 | +``` |
| 126 | +- Save the regionSet as a BED file |
| 127 | +```python |
| 128 | +rs.to_bed("path/to/save/bedfile.bed") |
| 129 | +rs.to_bed_gz("path/to/save/bedfile.bed.gz") # gzipped |
| 130 | +``` |
| 131 | +- Save the regionSet as a bigBed file |
| 132 | +```python |
| 133 | +rs.to_bigbed("path/to/save/bedfile.bb", chrom_sizes="path/to/chrom.sizes") |
| 134 | +``` |
0 commit comments