<p>If you want to just start incrementally adding lines from the bed file until you hit the one that reproduces the problem, you can do something like this:</p>
<pre><code>for i in <span class="math-container">$(seq 20 30 $</span>(wc -l &lt; ../../test.bed)); do
    head -n <span class="math-container">$i ../../test.bed &gt; slice.bed
    if python rgmatch.py -g ../../hg38.ncbiRefSeq.gtf -b slice.bed -o slice.out
    then
        true
    else
        echo "Failed when running with the $</span>i first lines.&quot;
        break
    fi
done
    
</code></pre>
<p><strong>Explanation</strong></p>
<p><code>seq 20 30 $(wc -l &lt; ../../test.bed)</code> will iterate over all numbers between 20 and the number of lines in your bed file with increments of 30. Next, the <code>head -n $i ../../test.bed &gt; slice.bed</code> will take the first <code>$i</code> lines of the bed file. This way, the loop will run the <code>rgmatch</code> command on the first 20 lines of the file, then the first 50, then the first 80 and so on as long as the command runs successfully. When the <code>rgmatch</code> command fails, it will report the value of <code>$i</code> to help you find the line that caused the problem.</p>

CC BY-SA 4.0
2021-06-03T09:55:13.897Z
Thank you @terdon I will edit the answer and try this.. If not I will appreciate very much your help. Right now I have a work meeting. But after that, I will do everything you said to me. Thank you !
Edmond Geraud Aguilar
CC BY-SA 4.0
2021-06-03T09:59:40.637Z
De res, @EdmondGeraudAguilar! And do feel free to ping me in chat if you need more help.
terdon
CC BY-SA 4.0
2021-06-03T11:23:59.463Z
It works ! I mean, I would that the script makes like a try-catch then store the results.. but I will handle with this. Than you very much
Edmond Geraud Aguilar
CC BY-SA 4.0
2021-06-03T11:27:38.193Z
@EdmondGeraudAguilar it's very easy to extend to whatever you need. But this is why I asked you to edit and explain what commands you want to automate. If you want to keep the results of each run, just change the `rgmatch` output file: `if python rgmatch.py -g ../../hg38.ncbiRefSeq.gtf -b slice.bed -o slice.$i.out; then ...`
terdon
CC BY-SA 4.0
2021-06-03T12:53:57.747Z
For those who may use this function be aware that some start coordinates of transcripts are missing in the GTF files that is the problem
Edmond Geraud Aguilar
CC BY-SA 4.0
2021-06-03T09:45:44.573Z
2021-06-03T09:45:44.573Z
terdon
<p>And thanks in advance. I am debugging a text file which is the one the two inputs on the program RGmatch <a href="https://bitbucket.org/pfurio/rgmatch/src/master/" rel="nofollow noreferrer">https://bitbucket.org/pfurio/rgmatch/src/master/</a>.</p>
<p>The code works. Is that some records give division by zero.</p>
<p>I am doing it by hand.</p>
<p>But is there a way by making a bash script, to see which records show the problem?</p>
<p>I do not want to touch the python code.</p>
<pre><code>python rgmatch.py -g ../../hg38.ncbiRefSeq.gtf -b ../../test.bed -o myassoSort.txt
</code></pre>
<p>I have tried with classical debugging, but my actual question is how to automatize that?</p>
<p>Also there are no empty records. The bed file was created based on refseq.txt from the latest human assembly. And also the GTF file. On the refseq.txt I processed to obtain a bed file.</p>
<p>I have checked if this works on a single record, it does, but not in some specific ones. The error I get is:</p>
<pre><code>  File &quot;rgmatch.py&quot;, line 1311, in &lt;module&gt;
    main()
  File &quot;rgmatch.py&quot;, line 287, in main
    run(gtf, dhs, outputfile)
  File &quot;rgmatch.py&quot;, line 1153, in run
    pctg_area      = (float(region_overlap)/intron_length)*100
ZeroDivisionError: float division by zero
</code></pre>
<p>The record I found so far is this one.</p>
<p><code>chr19    14087850    14090751</code></p>
<p>I did grep on both GTF files and Refseq Files and in both files there is information about the record. Because the program search for areas between region of interest, If I put inside just the record only in GTF file and bed Files no error occurs.</p>
<p><code>grep &quot;14090751&quot; refseq.bed</code></p>
<p><code>692  NM_138352.3 chr19   -   14087850    14090751    14088416    14090420    6   14087850,14088670,14088879,14089067,14089784,14090084,  14088575,14088782,14088976,14089362,14090084,14090751,  0   SAMD1   cmpl    cmpl    0,2,1,0,0,0,</code></p>
<p><code>grep &quot;14090751&quot; hg38.ncbiRefSeq.gtf</code></p>
<pre><code>chr19   ncbiRefSeq.2021-02-10   exon    14090085    14090751    .   -   .   gene_id &quot;SAMD1&quot;; transcript_id &quot;NM_138352.3&quot;; exon_number &quot;1&quot;; exon_id &quot;NM_138352.3.1&quot;; gene_name &quot;SAMD1&quot;;
chr19   ncbiRefSeq.2021-02-10   5UTR    14090421    14090751    .   -   .   gene_id &quot;SAMD1&quot;; transcript_id &quot;NM_138352.3&quot;; exon_number &quot;1&quot;; exon_id &quot;NM_138352.3.1&quot;; gene_name &quot;SAMD1&quot;;
</code></pre>

CC BY-SA 4.0
2021-06-03T09:28:30.723Z
Please include the things I asked for over at [linux.se]. We need to see the actual error message. Also, I call it "classical debugging" but I don't think anyone else will understand the term :) So, please [edit] your question, add the specific error message and then show us the commands that you want to automate. Have you checked it it works with just a _single_ record? Does it work with just the first line of the bed file?
terdon
CC BY-SA 4.0
2021-06-03T09:50:18.437Z
Also, if you still need help, feel free to ping me in the site [chat room](https://chat.stackexchange.com/rooms/58858/bioinformatics) where we can directly debug the issue.
terdon
<python><bash>
Automatize classical debugging in a bash script? (normal debugging by hand)
# Automatize classical debugging in a bash script? (normal debugging by hand)

(Asked by: username_0 on 2021-06-03)

And thanks in advance. I am debugging a text file which is the one the two inputs on the program RGmatch https://bitbucket.org/pfurio/rgmatch/src/master/.
The code works. Is that some records give division by zero.
I am doing it by hand.
But is there a way by making a bash script, to see which records show the problem?
I do not want to touch the python code.
python rgmatch.py -g ../../hg38.ncbiRefSeq.gtf -b ../../test.bed -o myassoSort.txt

I have tried with classical debugging, but my actual question is how to automatize that?
Also there are no empty records. The bed file was created based on refseq.txt from the latest human assembly. And also the GTF file. On the refseq.txt I processed to obtain a bed file.
I have checked if this works on a single record, it does, but not in some specific ones. The error I get is:
  File "rgmatch.py", line 1311, in 
    main()
  File "rgmatch.py", line 287, in main
    run(gtf, dhs, outputfile)
  File "rgmatch.py", line 1153, in run
    pctg_area      = (float(region_overlap)/intron_length)*100
ZeroDivisionError: float division by zero

The record I found so far is this one.
chr19    14087850    14090751
I did grep on both GTF files and Refseq Files and in both files there is information about the record. Because the program search for areas between region of interest, If I put inside just the record only in GTF file and bed Files no error occurs.
grep "14090751" refseq.bed
692  NM_138352.3 chr19   -   14087850    14090751    14088416    14090420    6   14087850,14088670,14088879,14089067,14089784,14090084,  14088575,14088782,14088976,14089362,14090084,14090751,  0   SAMD1   cmpl    cmpl    0,2,1,0,0,0,
grep "14090751" hg38.ncbiRefSeq.gtf
chr19   ncbiRefSeq.2021-02-10   exon    14090085    14090751    .   -   .   gene_id "SAMD1"; transcript_id "NM_138352.3"; exon_number "1"; exon_id "NM_138352.3.1"; gene_name "SAMD1";
chr19   ncbiRefSeq.2021-02-10   5UTR    14090421    14090751    .   -   .   gene_id "SAMD1"; transcript_id "NM_138352.3"; exon_number "1"; exon_id "NM_138352.3.1"; gene_name "SAMD1";

**Tags:** python, bash
> **Comments:**
> **username_1**: Please include the things I asked for over at [linux.se]. We need to see the actual error message. Also, I call it "classical debugging" but I don't think anyone else will understand the term :) So, please [edit] your question, add the specific error message and then show us the commands that you want to automate. Have you checked it it works with just a _single_ record? Does it work with just the first line of the bed file?  
> **username_1**: Also, if you still need help, feel free to ping me in the site [chat room](https://chat.stackexchange.com/rooms/58858/bioinformatics) where we can directly debug the issue.  

---

## 1 answers

### Answer by username_1 on 2021-06-03. Score: 1 | Accepted answer

If you want to just start incrementally adding lines from the bed file until you hit the one that reproduces the problem, you can do something like this:
for i in $(seq 20 30 $(wc -l < ../../test.bed)); do
    head -n $i ../../test.bed > slice.bed
    if python rgmatch.py -g ../../hg38.ncbiRefSeq.gtf -b slice.bed -o slice.out
    then
        true
    else
        echo "Failed when running with the $i first lines."
        break
    fi
done
    

Explanation
seq 20 30 $(wc -l < ../../test.bed) will iterate over all numbers between 20 and the number of lines in your bed file with increments of 30. Next, the head -n $i ../../test.bed > slice.bed will take the first $i lines of the bed file. This way, the loop will run the rgmatch command on the first 20 lines of the file, then the first 50, then the first 80 and so on as long as the command runs successfully. When the rgmatch command fails, it will report the value of $i to help you find the line that caused the problem.

> **Comments:**
> **username_0**: Thank you @terdon I will edit the answer and try this.. If not I will appreciate very much your help. Right now I have a work meeting. But after that, I will do everything you said to me. Thank you !  
> **username_1**: De res, @EdmondGeraudAguilar! And do feel free to ping me in chat if you need more help.  
> **username_0**: It works ! I mean, I would that the script makes like a try-catch then store the results.. but I will handle with this. Than you very much  
> **username_1**: @EdmondGeraudAguilar it's very easy to extend to whatever you need. But this is why I asked you to edit and explain what commands you want to automate. If you want to keep the results of each run, just change the `rgmatch` output file: `if python rgmatch.py -g ../../hg38.ncbiRefSeq.gtf -b slice.bed -o slice.$i.out; then ...`  
> **username_0**: For those who may use this function be aware that some start coordinates of transcripts are missing in the GTF files that is the problem  

---

