Light weight types for simple inputs

I need to allow as an input to a plugin method an integer in order to denote a study ID. Specifically, I need to provide to a method --i-qiita-study-id <int> or functionally similar. A SemanticType for QiitaStudyID makes sense because it visually looks like an int but it is not an int as operations like addition do not make sense. Is there a light weight way to define a type for an input without defining a format or some of the other surrounding stuff?

One alternative I’m exploring is defining this as a required parameter, and specifying that the parameter is qiime2.plugin.Int.

Best,
Daniel

cc @ebolyen

Hey @wasade,

This is minor, but from personal experience, it's usually easier to treat IDs as strings, since you wouldn't (hopefully) do math with them. This also makes things like leading zeros a non-issue.

It sounds like what you have is really a primitive type (int [or str]), since there isn't a format or anything more complicated backing it.

Semantic Types are really for structured data (often with multiple ways to structure that data) that has an particular meaning. I think your QiitaStudyID fits the latter case, but doesn't work quite as well for the former. Also, there aren't any mechanisms for "skipping" the part where you describe what format you would write out (the canonical format).

Something that might be interesting would be to "alias" a primitive type as a semantic type (essentially a NewType()). But I think that would be confusing, as right now when I see an input is required, I know that I'm supposed to hand it an Artifact of some particular semantic type. If there wasn't an Artifact behind the type, then I have the think harder about if I'm supposed to just type something in or give a file.

I would go with this approach instead. Methods/Visualizations aren't required to have inputs, so you could have a method that just accepts a single int/str and fetches the data (which is then perhaps turned into an artifact?).

Another future thought would be to let developers apply a "NewType" to primitives, but that would probably just make interface implementation a little tricker as you need to work out what the "original" type was (not hard, but it's an extra step).

Hope that helps!

1 Like

Okay, thank you! And great point re: str.