-
Notifications
You must be signed in to change notification settings - Fork 372
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
Adding error in LiftoverVcf if reference dictionary does not exist (Issue #1157) #1189
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,10 +9,12 @@ | |
import htsjdk.samtools.util.Interval; | ||
import htsjdk.variant.variantcontext.*; | ||
import htsjdk.variant.vcf.VCFFileReader; | ||
import htsjdk.samtools.SAMException; | ||
import org.testng.Assert; | ||
import org.testng.annotations.AfterClass; | ||
import org.testng.annotations.DataProvider; | ||
import org.testng.annotations.Test; | ||
import picard.PicardException; | ||
import picard.cmdline.CommandLineProgramTest; | ||
import picard.vcf.LiftoverVcf; | ||
import picard.vcf.VcfTestUtils; | ||
|
@@ -21,7 +23,9 @@ | |
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.*; | ||
|
||
import java.nio.file.Path; | ||
import java.nio.file.Files; | ||
import java.nio.file.StandardCopyOption; | ||
/** | ||
* Test class for LiftoverVcf. | ||
* <p> | ||
|
@@ -1169,4 +1173,49 @@ public void testLiftOverNoCallAndSymbolic(final LiftOver liftOver, final Variant | |
Assert.assertEquals(resultAlleles, result.getAttributeAsStringList(LiftoverVcf.ORIGINAL_ALLELES, null)); | ||
} | ||
} | ||
|
||
@Test() | ||
public void testNoDictionary() throws IOException { | ||
final Path liftOutput = Files.createTempFile("tmpouput", ".vcf"); | ||
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. with all these deleteOnExit, I wonder if it's cleaner to have a 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. maybe not....nevermind. |
||
liftOutput.toFile().deleteOnExit(); | ||
final Path rejectOutput = Files.createTempFile("tmpreject", ".vcf"); | ||
rejectOutput.toFile().deleteOnExit(); | ||
final Path input = TEST_DATA_PATH.toPath().resolve("testLiftoverBiallelicIndels.vcf"); | ||
final Path referenceCopy = Files.createTempFile("ref", ".fasta"); | ||
referenceCopy.toFile().deleteOnExit(); | ||
Files.copy(REFERENCE_FILE.toPath(), referenceCopy, StandardCopyOption.REPLACE_EXISTING); | ||
final String[] args = new String[]{ | ||
"INPUT=" + input.toString(), | ||
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. all calls to |
||
"OUTPUT=" + liftOutput.toString(), | ||
"REJECT=" + rejectOutput.toString(), | ||
"CHAIN=" + CHAIN_FILE, | ||
"REFERENCE_SEQUENCE=" + referenceCopy.toString(), | ||
}; | ||
Assert.assertEquals(runPicardCommandLine(args), 1); | ||
} | ||
|
||
@Test(expectedExceptions = SAMException.class, expectedExceptionsMessageRegExp = "File exists but is not readable:.*") | ||
public void testUnreadableDictionary() throws IOException { | ||
final Path liftOutput = Files.createTempFile("tmpouput", ".vcf"); | ||
liftOutput.toFile().deleteOnExit(); | ||
final Path rejectOutput = Files.createTempFile("tmpreject", ".vcf"); | ||
rejectOutput.toFile().deleteOnExit(); | ||
final Path input = TEST_DATA_PATH.toPath().resolve("testLiftoverBiallelicIndels.vcf"); | ||
final Path referenceCopy = Files.createTempFile("ref", ".fasta"); | ||
referenceCopy.toFile().deleteOnExit(); | ||
Files.copy(REFERENCE_FILE.toPath(), referenceCopy, StandardCopyOption.REPLACE_EXISTING); | ||
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. overwriting a temporary file? 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. yeah, once Files.createTempFile is called the file exists and Files.copy will need to overwrite. I can't really find a good way to get a temp path for the reference copy without creating the file; I could create a helper temp file and then resolveSibling on the helper to get the reference copy, or use Paths.get on an absolute path into the java tmp directory, but neither of those options seems better than just allowing the copy to overwrite. 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 think what you want to do is use 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 agree, that's better, thanks. |
||
final Path dictCopy = referenceCopy.resolveSibling(referenceCopy.toFile().getName().replaceAll("fasta$", "dict")); | ||
final Path dictionary = REFERENCE_FILE.toPath().resolveSibling(REFERENCE_FILE.getName().replaceAll("fasta$", "dict")); | ||
Files.copy(dictionary, dictCopy); | ||
dictCopy.toFile().deleteOnExit(); | ||
dictCopy.toFile().setReadable(false); | ||
final String[] args = new String[]{ | ||
"INPUT=" + input.toString(), | ||
"OUTPUT=" + liftOutput.toString(), | ||
"REJECT=" + rejectOutput.toString(), | ||
"CHAIN=" + CHAIN_FILE, | ||
"REFERENCE_SEQUENCE=" + referenceCopy.toString(), | ||
}; | ||
runPicardCommandLine(args); | ||
} | ||
} |
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.
May as well write this using a complete sentence, e.g.
Reference x must have an associated Dictionary .dict file in the same directory.