-
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
Updating htsjdk to 2.19.0 #1297
Merged
+71
−71
Merged
Changes from all commits
Commits
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 |
---|---|---|
|
@@ -33,14 +33,13 @@ | |
import htsjdk.samtools.util.IOUtil; | ||
import htsjdk.samtools.util.Log; | ||
import htsjdk.samtools.util.ProgressLogger; | ||
import org.broadinstitute.barclay.argparser.Argument; | ||
import org.broadinstitute.barclay.argparser.CommandLineProgramProperties; | ||
import org.broadinstitute.barclay.help.DocumentedFeature; | ||
import picard.PicardException; | ||
import picard.cmdline.CommandLineProgram; | ||
import org.broadinstitute.barclay.argparser.CommandLineProgramProperties; | ||
import org.broadinstitute.barclay.argparser.Argument; | ||
import picard.cmdline.StandardOptionDefinitions; | ||
import picard.cmdline.programgroups.ReadDataManipulationProgramGroup; | ||
import picard.illumina.parser.ReadData; | ||
|
||
import java.io.File; | ||
|
||
|
@@ -55,15 +54,12 @@ | |
oneLineSummary = "Convert a BAM file to a SAM file, or a SAM to a BAM", | ||
programGroup = ReadDataManipulationProgramGroup.class) | ||
@DocumentedFeature | ||
public class | ||
SamFormatConverter extends CommandLineProgram { | ||
|
||
private static final String PROGRAM_VERSION = "1.0"; | ||
public class SamFormatConverter extends CommandLineProgram { | ||
|
||
// The following attributes define the command-line arguments | ||
|
||
@Argument(doc = "The BAM or SAM file to parse.", shortName = StandardOptionDefinitions.INPUT_SHORT_NAME) | ||
public File INPUT; | ||
|
||
@Argument(doc = "The BAM or SAM output file. ", shortName = StandardOptionDefinitions.OUTPUT_SHORT_NAME) | ||
public File OUTPUT; | ||
|
||
|
@@ -72,12 +68,24 @@ public static void main(final String[] argv) { | |
} | ||
|
||
protected int doWork() { | ||
IOUtil.assertFileIsReadable(INPUT); | ||
IOUtil.assertFileIsWritable(OUTPUT); | ||
final SamReader reader = SamReaderFactory.makeDefault().referenceSequence(REFERENCE_SEQUENCE).open(INPUT); | ||
final SAMFileWriter writer = new SAMFileWriterFactory().makeWriter(reader.getFileHeader(), true, OUTPUT, REFERENCE_SEQUENCE); | ||
convert(INPUT, OUTPUT, REFERENCE_SEQUENCE, CREATE_INDEX); | ||
return 0; | ||
} | ||
|
||
if (CREATE_INDEX && writer.getFileHeader().getSortOrder() != SAMFileHeader.SortOrder.coordinate) { | ||
/** | ||
* Convert a file from one of sam/bam/cram format to another based on the extension of output. | ||
* | ||
* @param input input file in one of sam/bam/cram format | ||
* @param output output to write converted file to, the conversion is based on the extension of this filename | ||
* @param referenceSequence the reference sequence to use, necessary when reading/writing cram | ||
* @param createIndex whether or not an index should be written alongside the output file | ||
*/ | ||
public static void convert(final File input, final File output, final File referenceSequence, final Boolean createIndex) { | ||
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. I extracted the guts of this tool into a public method so it could be tested more sanely. |
||
IOUtil.assertFileIsReadable(input); | ||
IOUtil.assertFileIsWritable(output); | ||
final SamReader reader = SamReaderFactory.makeDefault().referenceSequence(referenceSequence).open(input); | ||
final SAMFileWriter writer = new SAMFileWriterFactory().makeWriter(reader.getFileHeader(), true, output, referenceSequence); | ||
if (createIndex && writer.getFileHeader().getSortOrder() != SAMFileHeader.SortOrder.coordinate) { | ||
throw new PicardException("Can't CREATE_INDEX unless sort order is coordinate"); | ||
} | ||
|
||
|
@@ -88,6 +96,5 @@ protected int doWork() { | |
} | ||
CloserUtil.close(reader); | ||
writer.close(); | ||
return 0; | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -24,6 +24,8 @@ | |
|
||
package picard.sam; | ||
|
||
import htsjdk.samtools.Defaults; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
|
||
import java.io.File; | ||
|
@@ -34,63 +36,47 @@ | |
import static org.testng.Assert.assertEquals; | ||
import static org.testng.Assert.assertTrue; | ||
|
||
public class SamFileConverterTest { | ||
public class SamFormatConverterTest { | ||
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. Renamed the test so it matched the tool name. |
||
|
||
private static final File TEST_DATA_DIR = new File("testdata/picard/sam/SamFileConverterTest"); | ||
private static final File TEST_DATA_DIR = new File("testdata/picard/sam/SamFormatConverterTest"); | ||
private static final File unmappedSam = new File(TEST_DATA_DIR, "unmapped.sam"); | ||
private static final File unmappedBam = new File(TEST_DATA_DIR, "unmapped.bam"); | ||
private static final File unmappedCram = new File(TEST_DATA_DIR, "unmapped.cram"); | ||
|
||
@Test | ||
public void testSAMToBAM() { | ||
convertFile(unmappedSam, unmappedBam, ".bam"); | ||
} | ||
|
||
@Test | ||
public void testSAMToCRAM() { | ||
convertFile(unmappedSam, unmappedCram, ".cram"); | ||
} | ||
private static final File ESSENTIALLY_EMPTY_REFERENCE_TO_USE_WITH_UNMAPPED_CRAM = new File(TEST_DATA_DIR, "basicallyEmpty.fasta"); | ||
|
||
@Test | ||
public void testBAMToCRAM() { | ||
convertFile(unmappedBam, unmappedCram, ".cram"); | ||
} | ||
|
||
@Test | ||
public void testBAMToSAM() { | ||
convertFile(unmappedBam, unmappedSam, ".sam"); | ||
} | ||
@DataProvider | ||
public Object[][] conversionCases() { | ||
return new Object[][]{ | ||
{unmappedSam, unmappedBam, ".bam"}, | ||
{unmappedSam, unmappedCram, ".cram"}, | ||
{unmappedBam, unmappedCram, ".cram"}, | ||
{unmappedBam, unmappedSam, ".sam"}, | ||
{unmappedCram, unmappedBam, ".bam"}, | ||
{unmappedCram, unmappedSam, ".sam"}, | ||
|
||
@Test | ||
public void testCRAMToBAM() { | ||
convertFile(unmappedCram, unmappedBam, ".bam"); | ||
}; | ||
} | ||
|
||
@Test | ||
public void testCRAMToSAM() { | ||
convertFile(unmappedCram, unmappedSam, ".sam"); | ||
@Test(dataProvider = "conversionCases") | ||
public void testConvert(File input, File expected, String extension) throws IOException { | ||
convertFile(input, expected, extension); | ||
} | ||
|
||
|
||
private void convertFile(final File inputFile, final File fileToCompare, final String extension) { | ||
final SamFormatConverter samFormatConverter = new SamFormatConverter(); | ||
final List<File> samFiles = new ArrayList<File>(); | ||
private void convertFile(final File inputFile, final File fileToCompare, final String extension) throws IOException { | ||
final List<File> samFiles = new ArrayList<>(); | ||
final ValidateSamFile validateSamFile = new ValidateSamFile(); | ||
final CompareSAMs compareSAMs = new CompareSAMs(); | ||
|
||
samFormatConverter.INPUT = inputFile; | ||
try { | ||
samFormatConverter.OUTPUT = File.createTempFile("SamFileConverterTest." + inputFile.getName(), extension); | ||
samFormatConverter.OUTPUT.deleteOnExit(); | ||
} catch (final IOException e) { | ||
e.printStackTrace(); | ||
} | ||
samFormatConverter.doWork(); | ||
final File output = File.createTempFile("SamFormatConverterTest." + inputFile.getName(), extension); | ||
output.deleteOnExit(); | ||
SamFormatConverter.convert(inputFile, output, ESSENTIALLY_EMPTY_REFERENCE_TO_USE_WITH_UNMAPPED_CRAM, Defaults.CREATE_INDEX); | ||
|
||
validateSamFile.INPUT = samFormatConverter.OUTPUT; | ||
validateSamFile.INPUT = output; | ||
assertEquals(validateSamFile.doWork(), 0); | ||
|
||
samFiles.add(samFormatConverter.OUTPUT); | ||
samFiles.add(output); | ||
samFiles.add(fileToCompare); | ||
|
||
compareSAMs.samFiles = samFiles; | ||
|
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
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
2 changes: 2 additions & 0 deletions
2
testdata/picard/sam/SamFormatConverterTest/basicallyEmpty.fasta
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
>chrNull | ||
NNNNNNN |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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.
this was unused