Mykrobe predictor JSON to TSV Converter
<p>I wanted to ask a question regarding file conversion.</p>

<p>I have a JSON file (after AMR prediction execution) that I want to covert to a TSV file based on Mykrobe-predictor scripts (json_to_tsv.py) and this is my JSON output (<a href="http://bioinfo.cs.ccu.edu.tw/result_TB.json" rel="nofollow">result_TB.json</a>).</p>

<pre><code>./json_to_tsv.py /path/to/JSON_file
</code></pre>

<p>When I pasted a command into the terminal, I got a IndexError at Line 78.</p>

<p><a href="https://github.com/iqbal-lab/Mykrobe-predictor/blob/master/scripts/json_to_tsv.py#L78" rel="nofollow">https://github.com/iqbal-lab/Mykrobe-predictor/blob/master/scripts/json_to_tsv.py#L78</a></p>

<pre><code> def get_sample_name(f):
  return f.split('/')[-2]
</code></pre>

<p>And here is the error I get:</p>

<pre><code>mykrobe_version file plate_name sample drug phylo_group species lineage phylo_group_per_covg species_per_covg lineage_per_covg phylo_group_depth species_depth lineage_depth susceptibility variants (gene:alt_depth:wt_depth:conf) genes (prot_mut-ref_mut:percent_covg:depth)
  Traceback (most recent call last):
  File "./json_to_tsv.py", line 157, in &lt;module&gt;
  sample_name = get_sample_name(f)
  File "./json_to_tsv.py", line 78, in get_sample_name
  return f.split('/')[-2]
  IndexError: list index out of range
</code></pre>

<p>Any suggestions would be appreciated.</p>

<p>Looking at the code I guess they expect to call the converter with something like:</p>

<pre><code>python json_to_tsv.py plate/sample1/sample1.json
</code></pre>

<p>Try copying your JSON file to a directory called <code>sample1</code> inside a directory called <code>plate</code> and see if you get the same error when you call it like in the example above.</p>

<hr>

<p><strong>Update</strong></p>

<p>The problem is indeed as described above.</p>

<p><strong>Doesn't work:</strong></p>

<pre><code>python json_to_tsv.py result_TB.json 
</code></pre>

<blockquote>
  <p>mykrobe_version   file    plate_name  sample  drug    phylo_group species lineage phylo_group_per_covg    species_per_covg    lineage_per_covg    phylo_group_depth   species_depth   lineage_depth   susceptibility  variants
  (gene:alt_depth:wt_depth:conf)    genes
  (prot_mut-ref_mut:percent_covg:depth) </p>

<pre><code>Traceback (most recent call last):   File "json_to_tsv.py", line 157, in &lt;module&gt;
    sample_name = get_sample_name(f)   File "json_to_tsv.py", line 78, in get_sample_name
    return f.split('/')[-2] IndexError: list index out of range
</code></pre>
</blockquote>

<p><strong>Works:</strong></p>

<pre><code>python json_to_tsv.py plate/sample/result_TB.json 
</code></pre>

<blockquote>
  <p>mykrobe_version   file    plate_name  sample  drug    phylo_group species lineage phylo_group_per_covg    species_per_covg    lineage_per_covg    phylo_group_depth   species_depth   lineage_depth   susceptibility  variants (gene:alt_depth:wt_depth:conf) genes (prot_mut-ref_mut:percent_covg:depth)</p>
  
  <p>-1    result_TB   plate   sample  NA</p>
</blockquote>

python json linux bioinformatics