Uncaught exception in exposed API method:

Hello,
I am encountering an error in a tool I am developing:

galaxy.web.framework.decorators ERROR 2022-03-11 05:38:11,051 [p:4087,w:1,m:0] [uWSGIWorker1Core0] Uncaught exception in exposed API method:
Traceback (most recent call last):
File “lib/galaxy/web/framework/decorators.py”, line 295, in decorator
rval = func(self, trans, *args, **kwargs)
File “lib/galaxy/webapps/galaxy/api/tools.py”, line 123, in build
return tool.to_json(trans, kwd.get(‘inputs’, kwd))
File “lib/galaxy/tools/init.py”, line 2111, in to_json
populate_state(request_context, self.inputs, params.dict, state_inputs, state_errors)
File “lib/galaxy/tools/parameters/init.py”, line 316, in populate_state
state[input.name] = input.get_initial_value(request_context, context)
File “lib/galaxy/tools/parameters/basic.py”, line 921, in get_initial_value
value = [optval for _, optval, selected in options if selected]
File “lib/galaxy/tools/parameters/basic.py”, line 921, in
value = [optval for _, optval, selected in options if selected]
ValueError: too many values to unpack (expected 3)

The relevant portion of xml looks as follows:

            <param name="batch" label="Name of the batch variable"  type='select' dynamic_options="mmuphin_get_cols(data)" />
            <param name="covariates" type="text" format="text" value="study_condition" label="Name(s) of covariates to adjust for in the batch correction model"/>


</inputs>
<outputs>
    <data name="output1"  format="csv" label="Adjusted abundance table" />
    <data name="output2"  format="pdf" label="Adjust batch diagnostic" />
</outputs>
<help><![CDATA[

etc. etc. on the xml

The code I invoke in the program looks as follows:

from galaxy import datatypes, model
import sys
import string
import csv
#############################################################
# Progran to read the first row of the metadata
# and populate the fields in the panel
# Written by George Weingart 2022/03/10
#############################################################

def mmuphin_get_cols(data):
if data == “”:
return
fname = data.dataset.file_name
lMetadata_Colnames = list()
f = open(fname)
csv_reader = csv.reader(f)
line_cntr = -1
for line in csv_reader:
line_cntr+=1
if line_cntr > 0:
return lMetadata_Colnames
lMetadata_Colnames = [x for x in line if x]
f.close()
return lMetadata_Colnames

I know the is not advises / deprecated, so maybe someone can provide a better way to do what we need, which is:

We want to populate a field so that it presents a dropbox selection.
The dropbox is populated from the first row of a csv file that the user presents in the

file.
For example:
The first two lines of a sample file are as follows:

“”,“subjectID”,“body_site”,“study_condition”,“disease”,“age_category”,“country”,“non_westernized”,“DNA_extraction_kit”,“number_reads”,“number_bases”,“minimum_read_length”,“median_read_length”,“curator”,“NCBI_accession”,“antibiotics_current_use”,“disease_subtype”,“age”,“gender”,“BMI”,“tnm”,“hdl”,“triglycerides”,“hba1c”,“ldl”,“location”,“ajcc”,“fobt”,“studyID”
“FengQ_2015.metaphlan_bugs_list.stool:SID31004”,“SID31004”,“stool”,“CRC”,“CRC;fatty_liver;hypertension”,“adult”,“AUT”,“no”,“MoBio”,40898340,3649611221,30,93,“Paolo_Manghi;Marisa_Metzger”,“ERR688505;ERR688358”,NA,“carcinoma”,64,“male”,29.35,“t1n0m0”,28,172,5.2,92,NA,NA,NA,“FengQ_2015.metaphlan_bugs_list.stool”
“FengQ_2015.metaphlan_bugs_list.stool:SID31009”,“SID31009”,“stool”,“control”,“fatty_liver;hypertension”,“senior”,“AUT”,“no”,“MoBio”,66107961,6196998053,30,96,“Paolo_Manghi;Marisa_Metzger”,“ERR688506;ERR688359”,NA,NA,68,“male”,32,NA,50,101,NA,157,NA,NA,NA,“FengQ_2015.metaphlan_bugs_list.stool”

We need it to generate a drop down box that looks as follows:

subjectID
body_site
study_condition
disease
age_category
country
non_westernized
DNA_extraction_kit
number_reads
number_bases
minimum_read_length
median_read_length
curator
NCBI_accession
antibiotics_current_use
disease_subtype
age
gender
BMI
tnm
hdl
triglycerides
hba1c
ldl
location
ajcc
fobt
studyID

Can anyone suggest how to do it without the
?

Otherwise, can someone point me at the current problem ?
Thanks!

Hi @george.weingart

Have you seen the tool development tutorials here?

Yes.
Any concrete advice?

Hi @george.weingart

No, I don’t personally have advice for this one except to make sure you are using Planemo for tool development.

There isn’t another tool that I know of that interprets a comment line from a single input dataset to dynamically construct tool form labels directly. It may not be possible, and the tool itself needs to have the input columns defined before manipulations are applied. Tools that may seem to be interpreting metadata are getting that information from a defined datatype, not from the input dataset itself.

You could explore the “tool factory” tool. It is a tool that creates other tools, then the created tool is what is deployed for end users (not the tool factory tool itself). If that seems useful, there are tutorials at that link I sent.

There are also many tools already that can filter any input tabular/csv dataset, but that doesn’t seem to be what you are trying to do. Or, maybe you could consider using that functionality. Meaning, create a workflow that contains filtering tools with some options/parameters pre-set and others adjustable at runtime. That could be shared with others to standardize the functionality.

The Upload tool can also be used to format/filter datasets with the “Rule Builder” functions (interprets comment/metadata lines), but that also doesn’t seem to be the goal and wouldn’t involve a distinct/new “tool”. And for data in a dataset collection, “rules” can also be applied based on the collection’s metadata – but again that doesn’t seem to fit the use case/goal.

Maybe someone else has more advice…

Thank you !
Unfortunately, this does not solve my problem.
I can summarize the issue as follows:

  1. I have a comma delimited file containing many lines.
  2. The first line contains alphabetic headers
  3. I want to populate a param so it is a drop down box, each row contains the name of the corresponding column, so that the User can select a parm which consists of the name of the column he might choose.

All I need is how to code the <param for that.

For example, as I mentioned before:
If the first two lines of my sample file are:

“”,“subjectID”,“body_site”,“study_condition”,“disease”,“age_category”,“country”,“non_westernized”,“DNA_extraction_kit”,“number_reads”,“number_bases”,“minimum_read_length”,“median_read_length”,“curator”,“NCBI_accession”,“antibiotics_current_use”,“disease_subtype”,“age”,“gender”,“BMI”,“tnm”,“hdl”,“triglycerides”,“hba1c”,“ldl”,“location”,“ajcc”,“fobt”,“studyID”
“FengQ_2015.metaphlan_bugs_list.stool:SID31004”,“SID31004”,“stool”,“CRC”,“CRC;fatty_liver;hypertension”,“adult”,“AUT”,“no”,“MoBio”,40898340,3649611221,30,93,“Paolo_Manghi;Marisa_Metzger”,“ERR688505;ERR688358”,NA,“carcinoma”,64,“male”,29.35,“t1n0m0”,28,172,5.2,92,NA,NA,NA,“FengQ_2015.metaphlan_bugs_list.stool”
“FengQ_2015.metaphlan_bugs_list.stool:SID31009”,“SID31009”,“stool”,“control”,“fatty_liver;hypertension”,“senior”,“AUT”,“no”,“MoBio”,66107961,6196998053,30,96,“Paolo_Manghi;Marisa_Metzger”,“ERR688506;ERR688359”,NA,NA,68,“male”,32,NA,50,101,NA,157,NA,NA,NA,“FengQ_2015.metaphlan_bugs_list.stool”

Then, I want to populate the drop down box with:

subjectID
body_site
study_condition
disease
age_category
country
non_westernized
DNA_extraction_kit
number_reads
number_bases
minimum_read_length
median_read_length
curator
NCBI_accession
antibiotics_current_use
disease_subtype
age
gender
BMI
tnm
hdl
triglycerides
hba1c
ldl
location
ajcc
fobt
studyID

So that the User selects one of those values for the process.

Hi Jennaj !
Thanks for your reply.
At the end, I solved it in two steps:

  1. I present the User with a screen to upload his csv file, use python to take the first row, split it and generate a tabulate file, each row contains one of the elements of the split (I called the file ‘metadata_headers’)
  2. I present the User with the screen, but added the following:

<param name="metadata_headers" type="data"  label="Covariates"  format="mmuphin_metadata_headers" help="Name(s) of covariates to adjust for in the batch correction model"/>


<param name="covariates" type="select" optional="true" multiple="true" label="Covariates - Please select from the drop down menu">
 		         <options from_dataset="metadata_headers">
       				 <column name="name" index="0"/>
        			<column name="value" index="0"/>
    			</options>
</param>

It works.
Would be nice if I knew how to do it in one step, but this works.
Thanks again,
George

For some reason the code doesn’t show…
Here it is:

<param name="metadata_headers" type="data"  label="Covariates"  format="mmuphin_metadata_headers" help="Name(s) of covariates to adjust for in the batch correction model"/>

	<param name="batch" type="select" optional="true" multiple="true" label="Batch - Please select from the drop down menu">
                     <options from_dataset="metadata_headers">
                             <column name="name" index="0"/>
                            <column name="value" index="0"/>
                    </options>
            </param>

	<param name="covariates" type="select" optional="true" multiple="true" label="Covariates - Please select from the drop down menu">
	         <options from_dataset="metadata_headers">
   				 <column name="name" index="0"/>
    			<column name="value" index="0"/>
			</options>
		</param>