-
Notifications
You must be signed in to change notification settings - Fork 596
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
Added an argument to specify the parts directory for ReadsSparkSink #4666
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
45a1acc
Added an argument to specify the parts directory for ReadsSparkSink
jamesemery 0f1932b
responded to a round of comments
jamesemery 6f75d93
added louis' test
jamesemery 2b25bad
reverted to shelling out for file permissions
jamesemery 8d11b4f
throwing in the towel
jamesemery File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
import org.bdgenomics.adam.models.RecordGroupDictionary; | ||
import org.bdgenomics.adam.models.SequenceDictionary; | ||
import org.bdgenomics.formats.avro.AlignmentRecord; | ||
import org.broadinstitute.hellbender.exceptions.GATKException; | ||
import org.broadinstitute.hellbender.exceptions.UserException; | ||
import org.broadinstitute.hellbender.tools.walkers.annotator.VariantAnnotatorEngine; | ||
import org.broadinstitute.hellbender.utils.gcs.BucketUtils; | ||
|
@@ -122,7 +123,7 @@ public SparkHeaderlessCRAMOutputFormat() { | |
public static void writeReads( | ||
final JavaSparkContext ctx, final String outputFile, final String referenceFile, final JavaRDD<GATKRead> reads, | ||
final SAMFileHeader header, ReadsWriteFormat format) throws IOException { | ||
writeReads(ctx, outputFile, referenceFile, reads, header, format, 0); | ||
writeReads(ctx, outputFile, referenceFile, reads, header, format, 0, null); | ||
} | ||
|
||
/** | ||
|
@@ -135,10 +136,11 @@ public static void writeReads( | |
* @param format should the output be a single file, sharded, ADAM, etc. | ||
* @param numReducers the number of reducers to use when writing a single file. A value of zero indicates that the default | ||
* should be used. | ||
* @param outputPartsDir directory for temporary files for SINGLE output format, should be null for default value of filename + .output | ||
*/ | ||
public static void writeReads( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update parameter javadoc and mention that a default is used if it's null |
||
final JavaSparkContext ctx, final String outputFile, final String referenceFile, final JavaRDD<GATKRead> reads, | ||
final SAMFileHeader header, ReadsWriteFormat format, final int numReducers) throws IOException { | ||
final SAMFileHeader header, ReadsWriteFormat format, final int numReducers, final String outputPartsDir) throws IOException { | ||
|
||
SAMFormat samOutputFormat = IOUtils.isCramFileName(outputFile) ? SAMFormat.CRAM : SAMFormat.BAM; | ||
|
||
|
@@ -155,10 +157,16 @@ public static void writeReads( | |
final JavaRDD<SAMRecord> samReads = reads.map(read -> read.convertToSAMRecord(null)); | ||
|
||
if (format == ReadsWriteFormat.SINGLE) { | ||
writeReadsSingle(ctx, absoluteOutputFile, absoluteReferenceFile, samOutputFormat, samReads, header, numReducers); | ||
writeReadsSingle(ctx, absoluteOutputFile, absoluteReferenceFile, samOutputFormat, samReads, header, numReducers, outputPartsDir); | ||
} else if (format == ReadsWriteFormat.SHARDED) { | ||
if (outputPartsDir!=null) { | ||
throw new GATKException(String.format("You specified the bam output parts directory %s, but requested a sharded output format which does not use this option",outputPartsDir)); | ||
} | ||
saveAsShardedHadoopFiles(ctx, absoluteOutputFile, absoluteReferenceFile, samOutputFormat, samReads, header, true); | ||
} else if (format == ReadsWriteFormat.ADAM) { | ||
if (outputPartsDir!=null) { | ||
throw new GATKException(String.format("You specified the bam output parts directory %s, but requested an ADAM output format which does not use this option",outputPartsDir)); | ||
} | ||
writeReadsADAM(ctx, absoluteOutputFile, samReads, header); | ||
} | ||
} | ||
|
@@ -228,10 +236,10 @@ private static JavaRDD<SAMRecord> setHeaderForEachPartition(final JavaRDD<SAMRec | |
|
||
private static void writeReadsSingle( | ||
final JavaSparkContext ctx, final String outputFile, final String referenceFile, final SAMFormat samOutputFormat, final JavaRDD<SAMRecord> reads, | ||
final SAMFileHeader header, final int numReducers) throws IOException { | ||
final SAMFileHeader header, final int numReducers, final String outputPartsDir) throws IOException { | ||
|
||
final JavaRDD<SAMRecord> sortedReads = SparkUtils.sortReads(reads, header, numReducers); | ||
final String outputPartsDirectory = outputFile + ".parts/"; | ||
final String outputPartsDirectory = (outputPartsDir == null)? getDefaultPartsDirectory(outputFile) : outputPartsDir; | ||
saveAsShardedHadoopFiles(ctx, outputPartsDirectory, referenceFile, samOutputFormat, sortedReads, header, false); | ||
logger.info("Finished sorting the bam file and dumping read shards to disk, proceeding to merge the shards into a single file using the master thread"); | ||
SAMFileMerger.mergeParts(outputPartsDirectory, outputFile, samOutputFormat, header); | ||
|
@@ -301,4 +309,11 @@ private static void setHadoopBAMConfigurationProperties(final JavaSparkContext c | |
} | ||
} | ||
|
||
/** | ||
* Gets the default parts directory for a given file by appending .parts/ to the end of it | ||
*/ | ||
public static String getDefaultPartsDirectory(String file) { | ||
return file + ".parts/"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We probably want a check that makes sure you're not setting this if
shardedOutput == true
, because it will be confusingly ignored.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 added a check in the writer which will throw.