-
Notifications
You must be signed in to change notification settings - Fork 369
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
UpdateVcfSequenceDictionary handles stdout #741
Conversation
@yfarjoun Please review. |
@@ -59,7 +59,7 @@ | |||
@Option(shortName = StandardOptionDefinitions.INPUT_SHORT_NAME, doc = "Input VCF") | |||
public File INPUT; | |||
|
|||
@Option(shortName = StandardOptionDefinitions.OUTPUT_SHORT_NAME, doc = "Output VCF to be written.") | |||
@Option(shortName = StandardOptionDefinitions.OUTPUT_SHORT_NAME, doc = "Output VCF to be written to a file or stdout") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted the change.
@@ -89,7 +91,15 @@ protected int doWork() { | |||
if (CREATE_INDEX) | |||
builder.setOption(Options.INDEX_ON_THE_FLY); | |||
|
|||
final VariantContextWriter vcfWriter = builder.setOutputFile(OUTPUT).build(); | |||
// handle stdout | |||
if ( OUTPUT.getPath().equals(STD_OUT) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stdout would be specified with O=/dev/stdout
. How about:
builder.setOutputStream(new FileOutputStream(OUTPUT, false));
instead of the if/else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's cleaner but how can the stdout be redirected to a file for validation by a test? With System.out
, it's easy by using System.setOut(PrintStream out)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yfarjoun I like the code change suggestion but it would it would be tough to validate the output. I can bypass that check in my test.Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you need the if statement here at all, as @nh13 said. please remove it and wrap OUTPUT with a FileOutputStream (and remove the STD_OUT constant)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
/** | ||
* @author George Grant | ||
*/ | ||
public class UpdateVcfSequenceDictionaryTest { | ||
private static final File TEST_DATA_PATH = new File("testdata/picard/vcf/"); | ||
private static final File OUTPUT_DATA_PATH = IOUtil.createTempDir("UpdateVcfSequenceDictionaryTest", null); | ||
private static final File STD_OUT_FILE = new File(OUTPUT_DATA_PATH, "stdout.vcf"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not so sure about these tests, @yfarjoun
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The intent is to redirect stdout into a file, so it could be verified. Do you have a better idea for verification?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant to say I didn't review the tests, sorry for the confusion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should be calling System.setOut(PrintStream out)
from the test and not modify the code in UpdateVcfSequenceDictionary.
so the test would be something like
File STD_OUT_FILE = new File(OUTPUT_DATA_PATH, "stdout.vcf");
Stream stdout = new OutputStream(STD_OUT_FILE);
System.setOut(stdout);
//run test
//close stream if needed
//examine file.
something isn't right. The value of OUTPUT has to be the string "/dev/stdout" Then you should be setting the output stream to point to a file using System.setOut() |
@yfarjoun How about this? OUTPUT=/dev/stdout. |
outputFile.deleteOnExit(); | ||
|
||
// Stream standard output a file | ||
if ( outputFileName.equals(UpdateVcfSequenceDictionary.STD_OUT) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use a local variable for STD_OUT.
final UpdateVcfSequenceDictionary updateVcfSequenceDictionary = new UpdateVcfSequenceDictionary(); | ||
updateVcfSequenceDictionary.INPUT = input; | ||
updateVcfSequenceDictionary.SEQUENCE_DICTIONARY = samSequenceDictionaryVcf; | ||
updateVcfSequenceDictionary.OUTPUT = outputFile; | ||
|
||
Assert.assertEquals(updateVcfSequenceDictionary.instanceMain(new String[0]), 0); | ||
|
||
if ( outputFileName.equals(UpdateVcfSequenceDictionary.STD_OUT) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a bit fewer spaces
if (outputFileName.equals(UpdateVcfSequenceDictionary.STD_OUT)) {
outputFile.deleteOnExit(); | ||
|
||
// Stream standard output a file | ||
if ( outputFileName.equals(UpdateVcfSequenceDictionary.STD_OUT) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here (fewer spaces)
back to you @ronlevine |
@ronlevine I have uploaded a branch with hat I would imagine would be a "clean" solution to the following branch (sorry about the |
@yfarjoun Please take a look at my changes. I took a look at your branch and incorporated the file stream redirection by file descriptor for stdout. Thanks, that solved the file validation problem. Note that only
because |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few small comments and we'll be good to go.
outputFile.deleteOnExit(); | ||
|
||
final UpdateVcfSequenceDictionary updateVcfSequenceDictionary = new UpdateVcfSequenceDictionary(); | ||
|
||
FileOutputStream stream = null; // placed outside of if statement so it's not destroyed before executing updateVcfSequenceDictionary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be final. (just set to null in the else branch)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
stream = new FileOutputStream(STD_OUT_FILE); | ||
|
||
// Ugliness required to write to m a stream given as a string on the commandline. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is that m
in my original comment? in any case, it's a typo, please fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, just a case of my fat fingers when changing the read from
in your original comment to write to
.
4163292
to
f196cb1
Compare
Squashed and rebased. Let me know if it's OK to merge. |
@yfarjoun OK to merge? |
yes. I'm fine with it. 👍 from me. In the future, please refrain from squashing your commits until the merge (you can squash during the final merge itself), so that your reviewers can have an easier time viewing the latest changes you made. |
Description
Implements the handling of stdout in #507.
If
stdout
is the output file, set to write to a stream instead of a file.Checklist (never delete this)
Never delete this, it is our record that procedure was followed. If you find that for whatever reason one of the checklist points doesn't apply to your PR, you can leave it unchecked but please add an explanation below.
Content
Review
For more detailed guidelines, see https://github.com/broadinstitute/picard/wiki/Guidelines-for-pull-requests