<p>When trying this on my machine, if I resize the terminal window before running <code>print(data)</code>, I get the full output:</p>
<p><a href="https://i.sstatic.net/cRwQ8.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/cRwQ8.png" alt="screenshot showing both truncated and full output" /></a></p>
<p>You can also force this, even if your terminal is actually smaller, by setting the <code>COLUMNS</code> variable to something larger than the actual size when layching <code>python</code> or <code>ipython</code>. This is a special bash variable that holds the current size of the terminal. From <code>man bash</code>:</p>
<pre><code>   COLUMNS
          Used  by  the select compound command to determine the terminal
          width when printing selection lists.  Automatically set if  the
          checkwinsize  option is enabled or in an interactive shell upon
          receipt of a SIGWINCH.
</code></pre>
<p>So if you set it manually, you can get the entire data frame printed, BUT you don't really want to do that since it won't scroll, it just wraps the text. For example, try:</p>
<pre><code>COLUMNS=300 python
</code></pre>
<p>That will set the size to 300, which results in this:</p>
<p><a href="https://i.sstatic.net/MvZaw.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/MvZaw.png" alt="screenshot of the wrapped text produced when setting the COLUMNS variable" /></a></p>

CC BY-SA 4.0
2022-10-31T15:21:27.917Z
Very good @terdon. Thanks! I tested this with Jupyter notebook and even when adjusting the window size [following this](https://stackoverflow.com/questions/44968486/adjust-width-of-jupyter-terminal) the additional columns are still kept hidden. Most likely, I should change another parameter in Jupyter. But indeed, I could confirm that in Terminal if I adjust the window size (even inside a `screen` session), the columns do show as long as the window size is large enough. Your approach using `COLUMN` variable is very nice!
Amin.A
CC BY-SA 4.0
2022-10-31T15:51:18.457Z
You're welcome. If Jupyter gives you a shell, you can try setting the variable in the shell. Alternatively, you can actually do it in your python code with `os.environ['COLUMNS']="300"` and then run `print(data)` and it might work as expected (confirmed in an `ipython` session, but I don't have a jupyter notebook to test on).
terdon
CC BY-SA 4.0
2022-11-01T04:52:19.343Z
I confirm that setting the environment variable using `os.environ['COLUMNS']="300"` works in a Jupyter notebook too! Thank you very much @terdon.
Amin.A
CC BY-SA 4.0
2022-10-31T13:49:39.010Z
2022-10-31T13:49:39.010Z
terdon
<p>In Pandas, we have <a href="https://pandas.pydata.org/pandas-docs/stable/user_guide/options.html" rel="nofollow noreferrer"><code>pandas.options.display</code></a> to adjust how a DataFrame should be displayed when printed.</p>
<p>I wonder if <code>PyRanges</code> has a similar set of options?</p>
<p>For example, if I have a PyRange object like this:</p>
<pre><code>import pyranges as pr
data = pr.data.ucsc_bed()
</code></pre>
<p>I can do <code>print(data)</code> and get:</p>
<pre><code>+--------------+-----------+-----------+------------+------------+-------+
| Chromosome   | Start     | End       | Feature    | gene_id    | +4    |
| (category)   | (int32)   | (int32)   | (object)   | (object)   | ...   |
|--------------+-----------+-----------+------------+------------+-------|
| chr1         | 12776117  | 12788726  | gene       | AADACL3    | ...   |
| chr1         | 169075927 | 169101957 | gene       | ATP1B1     | ...   |
| chr1         | 6845383   | 7829766   | gene       | CAMTA1     | ...   |
| chr1         | 20915589  | 20945396  | gene       | CDA        | ...   |
| ...          | ...       | ...       | ...        | ...        | ...   |
| chrX         | 152661096 | 152663330 | exon       | PNMA6E     | ...   |
| chrX         | 152661096 | 152666808 | transcript | PNMA6E     | ...   |
| chrX         | 152664164 | 152664378 | exon       | PNMA6E     | ...   |
| chrX         | 152666701 | 152666808 | exon       | PNMA6E     | ...   |
+--------------+-----------+-----------+------------+------------+-------+
Stranded PyRanges object has 5,519 rows and 9 columns from 30 chromosomes.
For printing, the PyRanges was sorted on Chromosome and Strand.
4 hidden columns: transcript_id, Strand, exon_number, transcript_name
</code></pre>
<p>How can I increase the number of columns shown?</p>
<p>Also appreciated if you refer me to a documentation that explains other related display options.</p>
<p><strong>Update:</strong> For future reference, @terdon remark encouraged me to check if such an adjustment is even considered in the <code>PyRanges</code>. I found <a href="https://github.com/biocore-ntnu/pyranges/blob/b8d3f60f454511eb52e591b7d1a6b2708b2f986f/pyranges/tostring2.py#L170" rel="nofollow noreferrer">the line that is responsible</a> for this representation, and indeed the <code>COLUMN</code> environment variable is the only defining parameter. In conclusion, the adjustment that I am looking for is simply not implemented in <code>PyRanges</code>.</p>

CC BY-SA 4.0
2022-10-31T09:35:38.667Z
Are you running in an interactive python shell? On what operating system? What happens if you make the terminal window larger? Or if you print to a file? Can you provide a minimal code example that we can run which reproduces the problem?
terdon
CC BY-SA 4.0
2022-10-31T13:03:00.637Z
Thanks @terdon for your reply. I already provided the minimal code example. Just run the code I provided and you get this picture.
Amin.A
CC BY-SA 4.0
2022-10-31T13:04:44.580Z
The only code you have provided is `data = pr.data.ucsc_bed()`. We would need an example file, and the commands to read it into the script etc. Please see https://stackoverflow.com/help/minimal-reproducible-example. Also, please answer my other questions too.
terdon
CC BY-SA 4.0
2022-10-31T13:09:23.753Z
@terdon, please note that `ucsc_bed()` produces a dummy data. I now added `import pyranges as pr`. Just copy-paste this code and you get the output. And regarding your questions: I am answering :). Sorry, I pressed Enter and the comment got posted. I tested this in the terminal and also jupyter notebook, but the output is independent of the environment. It also stays the same irrespective of the size of window.
Amin.A
CC BY-SA 4.0
2022-10-31T13:16:47.647Z
Ah! Thank you, I hadn't realized that. And thanks for the answers! Does it print the whole thing if printed to a file, at least?
terdon
CC BY-SA 4.0
2022-10-31T13:22:26.313Z
Of course. You can always get the `Pandas.DataFrame` using `data.df`, and then display it as you wish. Alternatively, you can export the bed file using `data.to_bed('./test.bed')`. In all cases, all data is exported. Note that my question is related to `display` of the data in the terminal. Not exporting issues. Please consider taking a look at `pandas.options.display` to understand what I mean by difference between exporting the `PyRanges` objects, and displaying `PyRanges` objects.
Amin.A
CC BY-SA 4.0
2022-10-31T13:42:31.413Z
Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/140263/discussion-between-terdon-and-amin-a).
terdon
<pyranges>
How to adjust #columns shown when PyRange is printed?
# How to adjust #columns shown when PyRange is printed?

(Asked by: username_0 on 2022-10-31)

In Pandas, we have pandas.options.display to adjust how a DataFrame should be displayed when printed.
I wonder if PyRanges has a similar set of options?
For example, if I have a PyRange object like this:
import pyranges as pr
data = pr.data.ucsc_bed()

I can do print(data) and get:
+--------------+-----------+-----------+------------+------------+-------+
| Chromosome   | Start     | End       | Feature    | gene_id    | +4    |
| (category)   | (int32)   | (int32)   | (object)   | (object)   | ...   |
|--------------+-----------+-----------+------------+------------+-------|
| chr1         | 12776117  | 12788726  | gene       | AADACL3    | ...   |
| chr1         | 169075927 | 169101957 | gene       | ATP1B1     | ...   |
| chr1         | 6845383   | 7829766   | gene       | CAMTA1     | ...   |
| chr1         | 20915589  | 20945396  | gene       | CDA        | ...   |
| ...          | ...       | ...       | ...        | ...        | ...   |
| chrX         | 152661096 | 152663330 | exon       | PNMA6E     | ...   |
| chrX         | 152661096 | 152666808 | transcript | PNMA6E     | ...   |
| chrX         | 152664164 | 152664378 | exon       | PNMA6E     | ...   |
| chrX         | 152666701 | 152666808 | exon       | PNMA6E     | ...   |
+--------------+-----------+-----------+------------+------------+-------+
Stranded PyRanges object has 5,519 rows and 9 columns from 30 chromosomes.
For printing, the PyRanges was sorted on Chromosome and Strand.
4 hidden columns: transcript_id, Strand, exon_number, transcript_name

How can I increase the number of columns shown?
Also appreciated if you refer me to a documentation that explains other related display options.
Update: For future reference, @terdon remark encouraged me to check if such an adjustment is even considered in the PyRanges. I found the line that is responsible for this representation, and indeed the COLUMN environment variable is the only defining parameter. In conclusion, the adjustment that I am looking for is simply not implemented in PyRanges.

**Tags:** pyranges
> **Comments:**
> **username_1**: Are you running in an interactive python shell? On what operating system? What happens if you make the terminal window larger? Or if you print to a file? Can you provide a minimal code example that we can run which reproduces the problem?  
> **username_0**: Thanks @terdon for your reply. I already provided the minimal code example. Just run the code I provided and you get this picture.  
> **username_1**: The only code you have provided is `data = pr.data.ucsc_bed()`. We would need an example file, and the commands to read it into the script etc. Please see https://stackoverflow.com/help/minimal-reproducible-example. Also, please answer my other questions too.  
> **username_0**: @terdon, please note that `ucsc_bed()` produces a dummy data. I now added `import pyranges as pr`. Just copy-paste this code and you get the output. And regarding your questions: I am answering :). Sorry, I pressed Enter and the comment got posted. I tested this in the terminal and also jupyter notebook, but the output is independent of the environment. It also stays the same irrespective of the size of window.  
> **username_1**: Ah! Thank you, I hadn't realized that. And thanks for the answers! Does it print the whole thing if printed to a file, at least?  
> **username_0**: Of course. You can always get the `Pandas.DataFrame` using `data.df`, and then display it as you wish. Alternatively, you can export the bed file using `data.to_bed('./test.bed')`. In all cases, all data is exported. Note that my question is related to `display` of the data in the terminal. Not exporting issues. Please consider taking a look at `pandas.options.display` to understand what I mean by difference between exporting the `PyRanges` objects, and displaying `PyRanges` objects.  
> **username_1**: Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/140263/discussion-between-terdon-and-amin-a).  

---

## 1 answers

### Answer by username_1 on 2022-10-31. Score: 2 | Accepted answer

When trying this on my machine, if I resize the terminal window before running print(data), I get the full output:

You can also force this, even if your terminal is actually smaller, by setting the COLUMNS variable to something larger than the actual size when layching python or ipython. This is a special bash variable that holds the current size of the terminal. From man bash:
   COLUMNS
          Used  by  the select compound command to determine the terminal
          width when printing selection lists.  Automatically set if  the
          checkwinsize  option is enabled or in an interactive shell upon
          receipt of a SIGWINCH.

So if you set it manually, you can get the entire data frame printed, BUT you don't really want to do that since it won't scroll, it just wraps the text. For example, try:
COLUMNS=300 python

That will set the size to 300, which results in this:

> **Comments:**
> **username_0**: Very good @terdon. Thanks! I tested this with Jupyter notebook and even when adjusting the window size [following this](https://stackoverflow.com/questions/44968486/adjust-width-of-jupyter-terminal) the additional columns are still kept hidden. Most likely, I should change another parameter in Jupyter. But indeed, I could confirm that in Terminal if I adjust the window size (even inside a `screen` session), the columns do show as long as the window size is large enough. Your approach using `COLUMN` variable is very nice!  
> **username_1**: You're welcome. If Jupyter gives you a shell, you can try setting the variable in the shell. Alternatively, you can actually do it in your python code with `os.environ['COLUMNS']="300"` and then run `print(data)` and it might work as expected (confirmed in an `ipython` session, but I don't have a jupyter notebook to test on).  
> **username_0**: I confirm that setting the environment variable using `os.environ['COLUMNS']="300"` works in a Jupyter notebook too! Thank you very much @terdon.  

---

