Tool that returns text output?

Hello!

I want to write a tool that returns “text” output, similar to e. g. “Compose text parameter value”. I wrote some test xml like mentioned tool:

<tool id="scripts_test" name="scripts_test" version="1.0a" profile="19.05" tool_type="expression">
  <description>xml for testing tool syntax</description>
  <expression type="ecma5.1">
      {return {'output': "32233"}}
  </expression>
  <inputs>
    <param name="sample" type="text" label="sample_id"/>
  </inputs>
  <outputs>
    <data name="out" type="text" from="output" label="output text11"/>
  </outputs>
</tool>

But it returns ordinary file of type “data”.

I also tried ordinary “command” kind of tool with exactly the same result:

<tool id="scripts_test" name="scripts_test" version="1.0a">
  <description>xml for testing tool syntax</description>
  <command detect_errors="aggressive">
      pwd; echo "test1111" &gt; '$out'
  </command>
  <stdio>
    <regex match="^$" source="stdout" level="warning" description="Empty exit code" />
  </stdio>
  <inputs>
    <param name="sample" type="text" label="sample_id"/>
  </inputs>
  <outputs>
    <data name="out" type="text" label="output text11"/>
  </outputs>
</tool>

I searched Galaxy Tool XML File — Galaxy Project 21.09 documentation and https://planemo.readthedocs.io/ and found nothing about “text” output nor “expression” kind of tools.

So i have the following questions:

  • What should i write in my xml to return “text” instead of file?
  • Can i achieve this with “command” tool?
  • Is it possible to write “expression” in other language rather than ecma5.1, e. g. python?
  • Is it possible to execute some shell command from such expression and get its result?

Thanks in advance.

1 Like

Hi @wormball,

Not an expert in these kind of tools, I have only written one once. I’m not sure if there is much documentation. You can try looking at these two examples:

The first thing I notice is they are defining the output with an <output> tag rather than <data>. Maybe this helps?

Regarding your other questions, as far as I know this only works with JS, not Python or bash. Also, I guess you realise already, but these kind of tools are only really useful within workflows.

(Edit: it seems from galaxy/xml.py at dev · galaxyproject/galaxy · GitHub that ecma5.1 is the only accepted value for the expression type.)

Best wishes,

Simon

4 Likes

Thanks Simon! I replaced “data” with “output”, and it worked.

<tool id="scripts_test" name="scripts_test" version="1.0a" profile="19.05" tool_type="expression">
  <description>xml for testing tool syntax</description>
  <expression type="ecma5.1">
      {return {'output': "32233"}}
  </expression>
  <inputs>
    <param name="sample" type="text" label="sample_id"/>
  </inputs>
  <outputs>
    <output name="out" type="text" from="output" label="output text11"/>
  </outputs>
</tool>

However i still can not get “text” output from “command” tool. I found that this generates no error:

<tool id="scripts_test" name="scripts_test" version="1.0a">
  <description>xml for testing tool syntax</description>
  <command detect_errors="aggressive">
      echo "test1111"
  </command>
  <inputs>
    <param name="sample" type="text" label="sample_id"/>
  </inputs>
  <outputs>
    <output name="out" type="text" from="output" label="output text11"/>
  </outputs>
</tool>

, however it leaves the output empty. If i echo “{‘output’: ‘test1111’}” or delete from=“output”, the result is the same. If i echo to $out or to $output, it reports error like “Unable to finish job” or “cannot find ‘output’”.

Now i have something like this:

<tool id="scripts_test" name="scripts_test" version="1.0a" profile="19.05" tool_type="expression">
  <description>xml for testing tool syntax</description>
  <expression type="ecma5.1">
      {
      let a = $job;
      return {'output': a};
      }
  </expression>
  <inputs>
    <param name="sample" type="text" label="sample_id"/>
    <param name="table" type="data" label="test file"/>
  </inputs>
  <outputs>
    <output name="out" type="text" from="output" label="output text11"/>
  </outputs>
</tool>

I ran it and got this:

{"sample": "erger", "table": {"file_ext": "tsv", "file_size": 4207, "name": "star_fusion on data 41", "metadata": {"dbkey": "?", "data_lines": 6, "comment_lines": 1, "columns": 19, "column_types": ["str", "int", "int", "float", "float", "str", "str", "str", "str", "str", "str", "str", "str", "float", "str", "float", "str", "float", "str"], "column_names": ["__pd__FusionName", "JunctionReadCount", "SpanningFragCount", "est_J", "est_S", "SpliceType", "LeftGene", "LeftBreakpoint", "RightGene", "RightBreakpoint", "JunctionReads", "SpanningFrags", "LargeAnchorSupport", "FFPM", "LeftBreakDinuc", "LeftBreakEntropy", "RightBreakDinuc", "RightBreakEntropy", "annots"], "delimiter": "__tc__"}, "src": {"src": "hda", "id": 526}}}

However i still have no idea on how to read the actual file content.

Hi @wormball,

{
      let a = $job.table;
      return {'output': a};
}

might be a good start? I’m not sure if this will return the text directly.

Unfortunately this returns only “table” part of mentioned json.

@wormball if I understand you correctly, then you’re trying to create an expression tool quite similar to the existing: galaxy/parse_values_from_file.xml at master · galaxyproject/galaxy · GitHub
If it’s not doing exactly what you want, it might at least serve as a starting point?

1 Like