genomic_region
Genomic Region processing¶
gentropy.common.genomic_region.KnownGenomicRegions
¶
Bases: Enum
Known genomic regions in the human genome in string format.
Source code in src/gentropy/common/genomic_region.py
20 21 22 23 | |
gentropy.common.genomic_region.GenomicRegion
¶
Genomic regions of interest.
Source code in src/gentropy/common/genomic_region.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
__init__(chromosome: str, start: int, end: int) -> None
¶
Class constructor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chromosome
|
str
|
Chromosome. |
required |
start
|
int
|
Start position. |
required |
end
|
int
|
End position. |
required |
Source code in src/gentropy/common/genomic_region.py
29 30 31 32 33 34 35 36 37 38 39 | |
from_known_genomic_region(region: KnownGenomicRegions) -> GenomicRegion
classmethod
¶
Get known genomic region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region
|
KnownGenomicRegions
|
Known genomic region. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
GenomicRegion |
GenomicRegion
|
Genomic region object. |
Examples:
>>> print(GenomicRegion.from_known_genomic_region(KnownGenomicRegions.MHC))
6:25726063-33400556
Source code in src/gentropy/common/genomic_region.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
from_string(region: str) -> GenomicRegion
classmethod
¶
Parse region string to chr:start-end.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region
|
str
|
Genomic region expected to follow chr##:#,###-#,### format or ##:####-#####. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
GenomicRegion |
GenomicRegion
|
Genomic region object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the end and start positions cannot be casted to integer or not all three values value error is raised. |
Examples:
>>> print(GenomicRegion.from_string('chr6:28,510,120-33,480,577'))
6:28510120-33480577
>>> print(GenomicRegion.from_string('6:28510120-33480577'))
6:28510120-33480577
>>> print(GenomicRegion.from_string('6:28510120'))
Traceback (most recent call last):
...
ValueError: Genomic region should follow a ##:####-#### format.
>>> print(GenomicRegion.from_string('6:28510120-foo'))
Traceback (most recent call last):
...
ValueError: Start and the end position of the region has to be integer.
Source code in src/gentropy/common/genomic_region.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | |
LiftOver¶
gentropy.common.genomic_region.LiftOverSpark
¶
LiftOver class for mapping genomic coordinates to an other genome build.
The input is a Spark DataFrame with a chromosome and position column. This classs can also map regions, if a start and end positions are provided.
Logic:
- The mapping is dropped if the mapped chromosome is not on the same as the source.
- The mapping is dropped if the mapping is ambiguous (more than one mapping is available).
- If regions are provided, the mapping is dropped if the new region is reversed (mapped_start > mapped_end).
- If regions are provided, the mapping is dropped if the difference of the length of the mapped region and original is larger than a threshold.
- When lifting over intervals, only unique coordinates are lifted, they joined back to the original dataframe.
Source code in src/gentropy/common/genomic_region.py
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
__init__(chain_file: str, max_difference: int = 100) -> None
¶
Initialize the LiftOver object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chain_file
|
str
|
Path to the chain file |
required |
max_difference
|
int
|
The maximum tolerated difference in the resulting length. Defaults to 100. |
100
|
Source code in src/gentropy/common/genomic_region.py
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
convert_coordinates(df: DataFrame, chrom_name: str, pos_name: str) -> DataFrame
¶
Converts genomic coordinates to coordinates on an other build.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
Spark Dataframe with chromosome and position columns. |
required |
chrom_name
|
str
|
Name of the chromosome column. |
required |
pos_name
|
str
|
Name of the position column. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
DataFrame |
DataFrame
|
Spark Dataframe with the mapped position column. |
Source code in src/gentropy/common/genomic_region.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 | |
convert_intervals(df: DataFrame, chrom_col: str, start_col: str, end_col: str, filter: bool = True) -> DataFrame
¶
Convert genomic intervals to liftover coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
spark Dataframe with chromosome, start and end columns. |
required |
chrom_col
|
str
|
Name of the chromosome column. |
required |
start_col
|
str
|
Name of the start column. |
required |
end_col
|
str
|
Name of the end column. |
required |
filter
|
bool
|
If True, filter is applied on the mapped data, otherwise return everything. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
DataFrame |
DataFrame
|
Liftovered intervals |
Source code in src/gentropy/common/genomic_region.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
gentropy.common.genomic_region.liftover_loci(variant_index: Table, chain_path: str, dest_reference_genome: str) -> Table
¶
Liftover a Hail table containing variant information from GRCh37 to GRCh38 or vice versa.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variant_index
|
Table
|
Variants to be lifted over |
required |
chain_path
|
str
|
Path to chain file for liftover |
required |
dest_reference_genome
|
str
|
Destination reference genome. It can be either GRCh37 or GRCh38. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Table |
Table
|
LD variant index with coordinates in the new reference genome |
Warning
This function assumes hail is initialized in Session.
Source code in src/gentropy/common/genomic_region.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |