# Looking for a function to export a matrix table to tsv like export\_samples() in hail0.1

**URL:** <https://discuss.hail.is/t/looking-for-a-function-to-export-a-matrix-table-to-tsv-like-export-samples-in-hail0-1/1519>\
**Category:** Hail Query & hailctl\
**Created:** [July 9, 2020, 6:32pm UTC](https://discuss.hail.is/t/looking-for-a-function-to-export-a-matrix-table-to-tsv-like-export-samples-in-hail0-1/1519 "2020-07-09T18:32:40Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![shuang](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@shuang](https://discuss.hail.is/u/shuang)\
**Post date:** [July 9, 2020, 6:32pm UTC](https://discuss.hail.is/t/looking-for-a-function-to-export-a-matrix-table-to-tsv-like-export-samples-in-hail0-1/1519/1 "2020-07-09T18:32:40Z")

</div>

Hi,  
I want to plot sample QC metrics and I have a workable python plot script which takes tsv file as input.  
In hail0.1 I used:  
`vds.sample_qc().export_samples('output.tsv', 'Sample = s, va.qc.*')`  
to get suitable tsv.

I want to do the same thing with Hail0.2, I found table.export() but not matrix table.

I am wondering do we have a convenient way to do this?

Thanks for any help.

---

<div class="post-metadata">

**Author:** ![kumarveerapen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/kumarveerapen/32/355_2.png) [@kumarveerapen](https://discuss.hail.is/u/kumarveerapen)\
**Post date:** [July 9, 2020, 6:52pm UTC](https://discuss.hail.is/t/looking-for-a-function-to-export-a-matrix-table-to-tsv-like-export-samples-in-hail0-1/1519/2 "2020-07-09T18:52:33Z")

</div>

Hello, Shuang! Thank you for your question 🙂

A few follow up questions –

1. do you have a matrix table instead of a vds?
2. if you have done step 1), you can save your sample qc into a Hail table and then use `table.export()`. A clue to this would be using `mt.col()` in order to get your sample qc into a table.

---

<div class="post-metadata">

**Author:** ![shuang](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@shuang](https://discuss.hail.is/u/shuang)\
**Post date:** [July 9, 2020, 7:16pm UTC](https://discuss.hail.is/t/looking-for-a-function-to-export-a-matrix-table-to-tsv-like-export-samples-in-hail0-1/1519/3 "2020-07-09T19:16:06Z")

</div>

Hi, really thx for answering.

Yes, actually I started from vcf, write into mt and already QCed my data in mt format.

Could I use  
mt = hl.sample\_qc(mt)  
mt.col.sample\_qc.export()

about save my sample\_qc into a separately table.  
do you mean:  
mt = hl.sample\_qc(mt)  
table = mt.col.sample\_qc  
table.export()

---

<div class="post-metadata">

**Author:** ![shuang](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@shuang](https://discuss.hail.is/u/shuang)\
**Post date:** [July 9, 2020, 9:20pm UTC](https://discuss.hail.is/t/looking-for-a-function-to-export-a-matrix-table-to-tsv-like-export-samples-in-hail0-1/1519/5 "2020-07-09T21:20:32Z")

</div>

after I tried:  
`mt = hl.sample_qc(mt, name='sample_qc')`  
`table1 = mt.col.sample_qc`  
`table1.export('gs://path/table1.tsv.bgz')`

It failed in Stage1. Even after I added : `--properties spark.speculation=true`, when submit job to my gcp cluster

> SLF4J: Class path contains multiple SLF4J bindings.  
> SLF4J: Found binding in [jar:file:/usr/lib/spark/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]  
> SLF4J: Found binding in [jar:file:/usr/lib/hadoop/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]

---

<div class="post-metadata">

**Author:** ![johnc1231](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/johnc1231/32/286_2.png) [@johnc1231](https://discuss.hail.is/u/johnc1231)\
**Post date:** [July 9, 2020, 9:23pm UTC](https://discuss.hail.is/t/looking-for-a-function-to-export-a-matrix-table-to-tsv-like-export-samples-in-hail0-1/1519/6 "2020-07-09T21:23:48Z")

</div>

I don’t think that’s the error message. Did more than that get printed? That looks like just a warning.

---

<div class="post-metadata">

**Author:** ![shuang](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@shuang](https://discuss.hail.is/u/shuang)\
**Post date:** [July 10, 2020, 10:17am UTC](https://discuss.hail.is/t/looking-for-a-function-to-export-a-matrix-table-to-tsv-like-export-samples-in-hail0-1/1519/7 "2020-07-10T10:17:52Z")

</div>

Hi It did report red ERROR flag and it report like:

> Last 4096 bytes of stderr :  
> SLF4J: Class path contains multiple SLF4J bindings.  
> SLF4J: Found binding in [jar:file:/usr/lib/spark/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]  
> SLF4J: Found binding in [jar:file:/usr/lib/hadoop/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]  
> SLF4J: See [SLF4J Error Codes](http://www.slf4j.org/codes.html#multiple_bindings) for an explanation.  
> SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]

I tried:

> mt = hl.sample\_qc(mt, name=‘sample\_qc’)  
> mt.col.describe()  
> table1 = mt.col.sample\_qc  
> table1.describe()  
> table1.shwo()

To make sure not the table generating problems. It looks right.  
Problem happened in `table1.shwo()` it report really similar error message. like `table1.export()`

Some result:

> ```
> --------------------------------------------------------
> result of table1.describe() is 
> --------------------------------------------------------
> Type:
> struct {
> dp_stats: struct {
> mean: float64, 
> stdev: float64, 
> min: float64, 
> max: float64
> }, 
> gq_stats: struct {
> mean: float64, 
> stdev: float64, 
> min: float64, 
> max: float64
> }, 
> call_rate: float64, 
> n_called: int64, 
> n_not_called: int64, 
> n_filtered: int64, 
> n_hom_ref: int64, 
> n_het: int64, 
> n_hom_var: int64, 
> n_non_ref: int64, 
> n_singleton: int64, 
> n_snp: int64, 
> n_insertion: int64, 
> n_deletion: int64, 
> n_transition: int64, 
> n_transversion: int64, 
> n_star: int64, 
> r_ti_tv: float64, 
> r_het_hom_var: float64, 
> r_insertion_deletion: float64
> }
> --------------------------------------------------------
> Source:
> <hail.matrixtable.MatrixTable object at 0x7f63ebf06780>
> Index:
> ['column']
> 
> ```

---

<div class="post-metadata">

**Author:** ![shuang](https://avatars.discourse-cdn.com/v4/letter/s/f08c70/32.png) [@shuang](https://discuss.hail.is/u/shuang)\
**Post date:** [July 10, 2020, 11:51am UTC](https://discuss.hail.is/t/looking-for-a-function-to-export-a-matrix-table-to-tsv-like-export-samples-in-hail0-1/1519/8 "2020-07-10T11:51:13Z")

</div>

I think it mush be issue about calling sample\_qc field.  
I tried to use hail0.2 built-in plot function. It report same issue.

> mt = hl.sample\_qc(mt)  
> p = hl.plot.histogram(mt.sample\_qc.call\_rate, range=(.88,1), legend=‘Call Rate’)

---

<div class="post-metadata">

**Author:** ![kumarveerapen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/kumarveerapen/32/355_2.png) [@kumarveerapen](https://discuss.hail.is/u/kumarveerapen)\
**Post date:** [July 16, 2020, 3:37am UTC](https://discuss.hail.is/t/looking-for-a-function-to-export-a-matrix-table-to-tsv-like-export-samples-in-hail0-1/1519/9 "2020-07-16T03:37:51Z")

</div>

@johnc1231 did you have additional thoughts on this?

---

<div class="post-metadata">

**Author:** ![johnc1231](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/johnc1231/32/286_2.png) [@johnc1231](https://discuss.hail.is/u/johnc1231)\
**Post date:** [July 30, 2020, 3:21pm UTC](https://discuss.hail.is/t/looking-for-a-function-to-export-a-matrix-table-to-tsv-like-export-samples-in-hail0-1/1519/10 "2020-07-30T15:21:34Z")

</div>

I would still want to see the whole error message, including the red ERROR flag and the python stack trace.

I’d try updating to version 0.2.52 though, as an issue with sample qc was fixed in that version.
