Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>import itertools def search(lines, terms): results = [[t] for t in terms] lines = iter(lines) for l in lines: for i,t in enumerate(terms): if t in l: results[i].append(lines.next().strip()) break return results def format(results): s = [] rows = list(itertools.izip_longest(*results, fillvalue="")) for row in rows: s.append("\t".join(row)) s.append('\n') return ''.join(s)</code></pre> <p>And here's how to call the functions:</p> <pre><code>example = """> &lt;Enzymologic: Ki nM 1> 257000 > &lt;Enzymologic: IC50 nM 1> n/a > &lt;ITC: Delta_G0 kJ/mole 1> n/a > &lt;Enzymologic: Ki nM 1> 5000 > &lt;Enzymologic: EC50/IC50 nM 1> 1000""" def test(): terms = ["> &lt;Enzymologic: IC50 nM 1>", "> &lt;Enzymologic: Ki nM 1>"] lines = example.split('\n') result = search(lines, terms) print format(result)</code></pre> <pre>>>> test() > &lt;Enzymologic: IC50 nM 1> > &lt;Enzymologic: Ki nM 1> n/a 257000</pre> <p>The above example separates each column by a single tab. If you need fancier formatting (as per your example), the format function gets a bit more complicated:</p> <pre><code>import math def format(results): maxcolwidth = [0] * len(results) rows = list(itertools.izip_longest(*results, fillvalue="")) for row in rows: for i,col in enumerate(row): w = int(math.ceil(len(col)/8.0))*8 maxcolwidth[i] = max(maxcolwidth[i], w) s = [] for row in rows: for i,col in enumerate(row): s += col padding = maxcolwidth[i]-len(col) tabs = int(math.ceil(padding/8.0)) s += '\t' * tabs s += '\n' return ''.join(s)</code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload