Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Major changes to the command line parsing system #135

Merged
merged 1 commit into from
Jan 23, 2015

Conversation

lbergelson
Copy link
Member

using jopt-simple to do the actual parsing. Right now it's just been dropped in to handle decomposing the arguments into key->value pairs.

supports short (-h) and long (--help) styles
supports boolean flags with or without an argument
options are now case sensitive

argument collections can be specified with @ArgumentCollection
NestedOptions removed -> replaced by ArgumentCollection

Option.fullName() is now respected if specified, if it isn't it defaults to use the field name
Overrideable has been removed from Option
Arguments must now be uniquely specified (no arguments targeting multiple fields any more) and no redefining existing ones.
The ability to override a specified option is a useful one, so it might need to be reimplemented at some point.
Collection defaults are now replaced rather than appended too

also opportunistically fixed a broken test in CreateSequenceDictionaryTestusing jopt-simple to do the actual parsing. Right now it's just been dropped in to handle decomposing the arguments into key->value pairs. In future it could also handle more of the argument checking and help formatting.

supports short (-h) and long (--help) styles
supports boolean flags with or without an argument
options are now case sensitive

argument collections can be specified with @ArgumentCollection
NestedOptions removed -> replaced by ArgumentCollection

Option.fullName() is now respected if specified, if it isn't it defaults to use the field name
Overrideable has been removed from Option
Arguments must now be uniquely specified (no arguments targeting multiple fields any more) and no redefining existing ones.
The ability to override a specified option is a useful one, so it might need to be reimplemented at some point.
Collection defaults are now replaced rather than appended too

also opportunistically fixed a broken test in CreateSequenceDictionaryTest

@lbergelson
Copy link
Member Author

jopt-simple docs are here http://pholser.github.io/jopt-simple/

This should close #81, #111 and #67

@coveralls
Copy link
Collaborator

Coverage Status

Coverage decreased (-0.29%) to 63.41% when pulling eb1a39e3e6e5454f59be1d76e8ae9c9ab8dcbbba on lb_unix_style_options into 93aad64 on master.

try {
createOptionDefinitions(field.get(callerOptions));
} catch (final IllegalAccessException e) {
throw new GATKException.CommandLineParserInternalException("BUG: NestedArguments must be public must be public.", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor typo here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh, thanks.

@mattsooknah
Copy link
Contributor

I believe Option.overridable() is needed for some CRAM stuff - @jacarey would know more. That's not to say that it needs to be implemented now, just FYI.

@lbergelson
Copy link
Member Author

It seemed like it was for child parsers to be able to override the master
parsers decision when things are specified in multiple places. I
disallowed specifying the same option in multiple places though for now, so
I didn't think it was necessary. We can reinstate it if necessary.

ArgumentsBuilder args = new ArgumentsBuilder(new Object[]{"Option=" + new File("/path/to"), "OtherOption=" + -1});
Assert.assertEquals(args.getArgsArray(), new String[]{"--Option","/path/to", "--OtherOption", "-1"});
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say either create a separate class with the actual @Tests, or move this whole class to src/test

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, i had meant to do that

On Wed, Jan 21, 2015 at 6:18 PM, Matt Sooknah [email protected]
wrote:

In
src/main/java/org/broadinstitute/hellbender/utils/test/ArgumentsBuilder.java
#135 (comment)
:

  • }
  • @test
  • public void testOneBigString(){
  •    ArgumentsBuilder args = new ArgumentsBuilder();
    
  •    args.add(" Value=1 Value=2 Value=3 Value= 4 ");
    
  •    Assert.assertEquals(args.getArgsList().toArray(), new String[]{"--Value", "1", "--Value", "2",
    
  •            "--Value", "3","--Value", "4"});
    
  • }
  • @test
  • public void testFromArray(){
  •    ArgumentsBuilder args = new ArgumentsBuilder(new Object[]{"Option=" + new File("/path/to"), "OtherOption=" + -1});
    
  •    Assert.assertEquals(args.getArgsArray(), new String[]{"--Option","/path/to", "--OtherOption", "-1"});
    
  • }

I'd say either create a separate class with the actual @tests, or move
this whole class to src/test


Reply to this email directly or view it on GitHub
https://github.com/broadinstitute/hellbender/pull/135/files#r23343682.

@coveralls
Copy link
Collaborator

Coverage Status

Coverage decreased (-0.2%) to 63.5% when pulling 2b3620e42107d0090f3fc270fdfca14ec7d682c7 on lb_unix_style_options into 93aad64 on master.

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should standardize on the style of imports or we'll have those edits all the time. Issue #138

@akiezun
Copy link
Contributor

akiezun commented Jan 22, 2015

looks good, small comments. CommandlineLineParser is a pretty complex beast and I've not reviewed it fully but it's fine for now from me. @droazen should weigh in on this pull req too before you merge.

@coveralls
Copy link
Collaborator

Coverage Status

Coverage decreased (-0.21%) to 63.5% when pulling e48a1360708acbb82b1179a5897c4039b5f067f6 on lb_unix_style_options into 93aad64 on master.

}

// This is the object that the caller has provided that contains annotations,
// and into which the values will be assigned.
private final Object callerOptions;

// For child CommandLineParser, this contains the prefix for the option names, which is needed for generating
// the command line. For non-nested, this is the empty string.
private final String prefix;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good riddance to this garbage :)

@vdauwera
Copy link
Contributor

Not sure if this is the right place for me to jump in (so redirect me if not), but question: is there any plan to make it possible to define min/max values for numeric argument values? This is something we got to only in a very basic way in GATK but would be useful to enable in order to save users from themselves. This would involve two levels:

  1. hard min/max values that correspond to limits beyond which values could cause errors/program failures; violation should throw a User Exception;

  2. recommended min/max values that correspond to limits beyond which values do not make sense for a given analysis functionality for standard use cases; violation should log a WARN entry.

for (String stringValue: values) {
final Object value;
try {
if (stringValue.equals("null")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a named constant rather than hardcoded literal.

@droazen
Copy link
Contributor

droazen commented Jan 22, 2015

Review complete. Looks great, just a few relatively minor comments.

@mattsooknah
Copy link
Contributor

@vdauwera General arg checking can be done in customCommandLineValidation, which returns zero or more error messages and prints them to stderr. I suppose log / warn messages could also be put in there.

But it might be nice to have a more specific process for checking values of numeric args.

@droazen
Copy link
Contributor

droazen commented Jan 22, 2015

@vdauwera If you want this (or any other) feature from the old GATK to make it into hellbender, feel free to create a ticket in our github issue tracker -- we can always close as WONTFIX if we deem it impractical or incompatible with the new codebase. I don't think adding minValue/maxValue attributes to @option would be a problem, though.

@vdauwera
Copy link
Contributor

Thanks guys -- will create tickets from now on.

@coveralls
Copy link
Collaborator

Coverage Status

Coverage decreased (-0.21%) to 63.5% when pulling eb6062f11e8c37cf1ab512913dfac04e573bd38b on lb_unix_style_options into 9195042 on master.

-using jopt-simple to do the actual parsing
-supports short (-h) and long (--help) styles
-supports boolean flags with or without an argument
-options are now case sensitive
-argument collections can be specified with @ArgumentCollection
-Option(fullname) is now respected if specified, if it isn't it defaults to use the field name
-several Option values are no longer used, overrideable
-NestedOptions removed -> replaced by ArgumentCollection
-Arguments must now be uniquely specified (no arguments targetting multiple fields any more)
-Collection defaults are now replaced rather than appended too

-opportunistically fixed a broken test in CreateSequenceDictionaryTest
@lbergelson
Copy link
Member Author

I think I've addressed all the comments. Going to merge on travis success.

@coveralls
Copy link
Collaborator

Coverage Status

Coverage decreased (-0.21%) to 63.5% when pulling 8a93d43 on lb_unix_style_options into 9195042 on master.

lbergelson added a commit that referenced this pull request Jan 23, 2015
Major changes to the command line parsing system

Closes #67, #81, #111
@lbergelson lbergelson merged commit 844f9cd into master Jan 23, 2015
@lbergelson lbergelson deleted the lb_unix_style_options branch January 23, 2015 16:11
lucidtronix pushed a commit that referenced this pull request Jul 27, 2021
* revises explore to work with Interpretation
* deletes lingering pdb.set_trace()
* Interpretation enums
* Interpretation for string and continuous
* Tested continuous
* Nitpicks
* adds parenthesis
* Nate's requested changes plus others:

1. If tensor is scaler (`if tm.shape[0] == 1`), isolates the value
inside the numpy array via `tensor = tensor.item`. If not, retain the
value as an array (e.g. categorical labels).

2. In the DataFrame, casts the `fpath`, `generator`, and any tm with
that has `Interpretation.Language` into "string" dtypes (see
https://pandas.pydata.org/pandas-docs/stable/user_guide/text.html). This
may confer some speed benefit in the future compared to the default
`object` dtype.

3. If dropping NaN rows from dataframe (how we obtain intersect of
tensor maps) results in an empty dataframe, skips calculating summary
statistics. Previous attempts to do that threw errors.

* removes import pdb

Co-authored-by: paolodi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants