# Parse\_locus() over multiple regions using GRCh38

**URL:** <https://discuss.hail.is/t/parse-locus-over-multiple-regions-using-grch38/993>\
**Category:** Hail Query & hailctl\
**Created:** [June 15, 2019, 6:38pm UTC](https://discuss.hail.is/t/parse-locus-over-multiple-regions-using-grch38/993 "2019-06-15T18:38:25Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![lindsayvm](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/lindsayvm/32/261_2.png) [@lindsayvm](https://discuss.hail.is/u/lindsayvm)\
**Post date:** [June 15, 2019, 6:38pm UTC](https://discuss.hail.is/t/parse-locus-over-multiple-regions-using-grch38/993/1 "2019-06-15T18:38:25Z")

</div>

Hi,

my data is on GRCh38 and I want to filter a set of SNPs from this. Im am looking for something like this:

```python
intervals = [hl.parse_locus(x, reference_genome='GRCh38') for x in ['4:144585304', '15:78575140']]
mt_hits = hl.filter_intervals(mt, intervals, keep = True)

```

which is giving the error: TypeError: filter\_intervals: parameter ‘intervals’: expected expression of type array\<interval\>, found list: [\<LocusExpression of type locus\>, \<LocusExpression of type locus\>]

---

<div class="post-metadata">

**Author:** ![tpoterba](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/tpoterba/32/61_2.png) [@tpoterba](https://discuss.hail.is/u/tpoterba)\
**Post date:** [June 16, 2019, 12:23pm UTC](https://discuss.hail.is/t/parse-locus-over-multiple-regions-using-grch38/993/2 "2019-06-16T12:23:34Z")

</div>

In 0.2.15 or later, doing the following:

```python
intervals = [hl.parse_locus(x, reference_genome='GRCh38') for x in ['4:144585304', '15:78575140']]
mt_hits = mt.filter_rows(hl.literal(intervals).contains(mt.locus))

```

will have the same performance as filter\_intervals, but is much easier to use. See here:

> [@New optimizer pass that extracts point queries and interval filters](https://discuss.hail.is/t/new-optimizer-pass-that-extracts-point-queries-and-interval-filters/979):
>
> [hl.filter\_intervals](https://hail.is/docs/0.2/methods/genetics.html#hail.methods.filter_intervals) is [one of the best ways](https://discuss.hail.is/t/using-filter-intervals-to-query-the-16gb-gnomad-sites-dataset-in-300ms-on-your-laptop/148) to speed up pipelines that only need to look at a small fraction of your data, but the method is quite a pain to use compared to simpler methods like filter\_rows. As of 0.2.15, Hail includes an optimizer pass that tries to rewrite filter / filter\_rows method calls as filter\_intervals when possible. This can make pipelines orders of magnitude faster, since it reduces the amount of data read from disk – and data you don’t read can’t slow you down! You’l…

---

<div class="post-metadata">

**Author:** ![lindsayvm](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/lindsayvm/32/261_2.png) [@lindsayvm](https://discuss.hail.is/u/lindsayvm)\
**Post date:** [June 19, 2019, 7:15pm UTC](https://discuss.hail.is/t/parse-locus-over-multiple-regions-using-grch38/993/3 "2019-06-19T19:15:38Z")

</div>

Thank you, I am now using HAIL version 0.2.15-652d93ae3419, but get this error:  
Error summary: HailException: Invalid locus ‘4:144585304’ found. Contig ‘4’ is not in the reference genome ‘GRCh38’

I have also tried other loci of which I am also sure the should be in GRCh38, but all give the same error.

---

<div class="post-metadata">

**Author:** ![tpoterba](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/tpoterba/32/61_2.png) [@tpoterba](https://discuss.hail.is/u/tpoterba)\
**Post date:** [June 19, 2019, 7:16pm UTC](https://discuss.hail.is/t/parse-locus-over-multiple-regions-using-grch38/993/4 "2019-06-19T19:16:40Z")

</div>

chromosome 4 is identified as `chr4` in GRCh38

---

<div class="post-metadata">

**Author:** ![lindsayvm](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/lindsayvm/32/261_2.png) [@lindsayvm](https://discuss.hail.is/u/lindsayvm)\
**Post date:** [June 19, 2019, 7:17pm UTC](https://discuss.hail.is/t/parse-locus-over-multiple-regions-using-grch38/993/5 "2019-06-19T19:17:22Z")

</div>

Works! Thanks 😄

---

<div class="post-metadata">

**Author:** ![conwei123](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@conwei123](https://discuss.hail.is/u/conwei123)\
**Post date:** [March 16, 2023, 6:28pm UTC](https://discuss.hail.is/t/parse-locus-over-multiple-regions-using-grch38/993/6 "2023-03-16T18:28:55Z")

</div>

@tpoterba I’m doing a very similar thing here where I have a list of locuses I’d like to filter by in the format of ‘1:10556097’ etc. I tried appending a ‘chr’ to each value in the list convert it into what I think would work with GRch38 and that resulted is some more errors with certain locations being out of range and such.

Is there a way to convert a list of locuses to a format that would work with filter\_rows?

Here is my current code:

> #RSIDloc is a list of string values for different locuses  
> intervals = [hl.parse\_locus(x, reference\_genome=‘GRCh38’) for x in RSIDloc]  
> mt = mt.filter\_rows(hl.literal(intervals).contains(mt.locus))  
> mt.show()

This gives the same error:

> Error summary: HailException: Invalid locus ‘1:10556097’ found. Contig ‘1’ is not in the reference genome ‘GRCh38’

---

<div class="post-metadata">

**Author:** ![tpoterba](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/tpoterba/32/61_2.png) [@tpoterba](https://discuss.hail.is/u/tpoterba)\
**Post date:** [March 16, 2023, 6:30pm UTC](https://discuss.hail.is/t/parse-locus-over-multiple-regions-using-grch38/993/7 "2023-03-16T18:30:35Z")

</div>

prepending `chr` is the right thing to do. If you’re getting errors about positions being out of those range, those are important errors – if your position is larger than the size of a chromosome in GRCh38, there’s no way to generate a sensible locus for that string.

---

<div class="post-metadata">

**Author:** ![conwei123](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@conwei123](https://discuss.hail.is/u/conwei123)\
**Post date:** [March 16, 2023, 6:38pm UTC](https://discuss.hail.is/t/parse-locus-over-multiple-regions-using-grch38/993/8 "2023-03-16T18:38:45Z")

</div>

I’m pulling these locus values from values I pulled off the ‘dbSNP\_rsid’ schema/dataset that I used to search rsID values from. I guess I can go through and drop these values manually. Is there a better way to get locus values specifically for the GRCh38 instead of going through GRCh37?

---

<div class="post-metadata">

**Author:** ![danking](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/danking/32/43_2.png) [@danking](https://discuss.hail.is/u/danking)\
**Post date:** [March 20, 2023, 11:48pm UTC](https://discuss.hail.is/t/parse-locus-over-multiple-regions-using-grch38/993/9 "2023-03-20T23:48:51Z")

</div>

I’m not sure I understand what you’re trying to do. It sounds like your loci are actually GRCh37 loci. Why are you trying to parse them as GRCh38 loci? Converting from GRCh37 variants to GRCh38 variants is a nontrivial process. We have some tools to help (look at `hl.liftover`) but you also have to decide what to do about the alleles, if those matter to you.

---

<div class="post-metadata">

**Author:** ![conwei123](https://avatars.discourse-cdn.com/v4/letter/c/bbe5ce/32.png) [@conwei123](https://discuss.hail.is/u/conwei123)\
**Post date:** [March 24, 2023, 6:01pm UTC](https://discuss.hail.is/t/parse-locus-over-multiple-regions-using-grch38/993/10 "2023-03-24T18:01:09Z")

</div>

I was having a bit of a trouble with the hl.liftover function, but I found a way that worked for me. I just used the ‘dbSNP\_rsid’ data set with GRCh38.

> rsid = hl.experimental.load\_dataset(name=‘dbSNP\_rsid’,version=‘154’,reference\_genome=‘GRCh38’)

I then used this hail table to get all the loci I needed from the list of rsid values I had.

I don’t know why I didn’t do this before.
