# Extract sequence from reference genome

**URL:** <https://discuss.hail.is/t/extract-sequence-from-reference-genome/2670>\
**Category:** Feature Requests\
**Created:** [May 17, 2022, 3:49pm UTC](https://discuss.hail.is/t/extract-sequence-from-reference-genome/2670 "2022-05-17T15:49:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjfarrell](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/jjfarrell/32/108_2.png) [@jjfarrell](https://discuss.hail.is/u/jjfarrell)\
**Post date:** [May 17, 2022, 3:49pm UTC](https://discuss.hail.is/t/extract-sequence-from-reference-genome/2670/1 "2022-05-17T15:49:13Z")

</div>

Is there a way to extract a slice of the Hail reference genome?

rg = hl.get\_reference(‘GRCh38’)  
seq=rg.seq(chr19:44905796-44909393)

For SV calls, the ref and alt are often not the sequence but instead place holders DEL,INS, DUP with the SVLEN. It would be useful to be able to update the ref and alt with the actual sequence.

John

---

<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:** [May 17, 2022, 3:52pm UTC](https://discuss.hail.is/t/extract-sequence-from-reference-genome/2670/2 "2022-05-17T15:52:13Z")

</div>

There is! it’s a method on `LocusExpression` called `sequence_context`. This requires you to add sequence to the reference genome first:

[https://hail.is/docs/0.2/genetics/hail.genetics.ReferenceGenome.html#hail.genetics.ReferenceGenome.add\_sequence](https://hail.is/docs/0.2/genetics/hail.genetics.ReferenceGenome.html#hail.genetics.ReferenceGenome.add_sequence)

Then you can use sequence context:

[https://hail.is/docs/0.2/hail.expr.LocusExpression.html#hail.expr.LocusExpression.sequence\_context](https://hail.is/docs/0.2/hail.expr.LocusExpression.html#hail.expr.LocusExpression.sequence_context)

Here it would look like:

```auto
seq=hl.eval(hl.locus('chr19', 44905796).sequence_context(before=0, after=...))

```

---

<div class="post-metadata">

**Author:** ![jjfarrell](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/jjfarrell/32/108_2.png) [@jjfarrell](https://discuss.hail.is/u/jjfarrell)\
**Post date:** [May 17, 2022, 6:59pm UTC](https://discuss.hail.is/t/extract-sequence-from-reference-genome/2670/3 "2022-05-17T18:59:24Z")

</div>

Excellent! I will give it a try.
