Java Code Examples for htsjdk.samtools.reference.ReferenceSequenceFileFactory#getDefaultDictionaryForReferenceSequence()

The following examples show how to use htsjdk.samtools.reference.ReferenceSequenceFileFactory#getDefaultDictionaryForReferenceSequence() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GATKSparkTool.java    From gatk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Register the reference file (and associated dictionary and index) to be downloaded to every node using Spark's
 * copying mechanism ({@code SparkContext#addFile()}).
 * @param ctx the Spark context
 * @param referencePath the reference file, can be a local file or a remote path
 * @return the reference file name; the absolute path of the file can be found by a Spark task using {@code SparkFiles#get()}
 */
protected static String addReferenceFilesForSpark(JavaSparkContext ctx, Path referencePath) {
    if (referencePath == null) {
        return null;
    }
    Path indexPath = ReferenceSequenceFileFactory.getFastaIndexFileName(referencePath);
    Path dictPath = ReferenceSequenceFileFactory.getDefaultDictionaryForReferenceSequence(referencePath);
    Path gziPath = GZIIndex.resolveIndexNameForBgzipFile(referencePath);

    ctx.addFile(referencePath.toUri().toString());
    if (Files.exists(indexPath)) {
        ctx.addFile(indexPath.toUri().toString());
    }
    if (Files.exists(dictPath)) {
        ctx.addFile(dictPath.toUri().toString());
    }
    if (Files.exists(gziPath)) {
        ctx.addFile(gziPath.toUri().toString());
    }

    return referencePath.getFileName().toString();
}
 
Example 2
Source File: CreateSequenceDictionary.java    From picard with MIT License 5 votes vote down vote up
/**
 * Use reference filename to create URI to go into header if URI was not passed on cmd line.
 */
protected String[] customCommandLineValidation() {
    if (URI == null) {
        URI = "file:" + referenceSequence.getReferenceFile().getAbsolutePath();
    }
    if (OUTPUT == null) {
        OUTPUT = ReferenceSequenceFileFactory.getDefaultDictionaryForReferenceSequence(referenceSequence.getReferenceFile());
        logger.info("Output dictionary will be written in ", OUTPUT);
    }
    return super.customCommandLineValidation();
}
 
Example 3
Source File: CachingIndexedFastaSequenceFile.java    From gatk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Performing several preliminary checks on the file path.
 *
 * @param fastaPath Fasta file to be used as reference
 * @throws UserException If the given {@code fastaPath} is not good.
 */
private static void checkFastaPath(final Path fastaPath) {

    // does the fasta file exist? check that first...
    if (!Files.exists(fastaPath)) {
        throw new UserException.MissingReference("The specified fasta file (" + fastaPath.toUri() + ") does not exist.");
    }

    //this is the .fai index, not the .gzi
    final Path indexPath = ReferenceSequenceFileFactory.getFastaIndexFileName(fastaPath);

    // determine the name for the dict file
    final Path dictPath = ReferenceSequenceFileFactory.getDefaultDictionaryForReferenceSequence(fastaPath);

    // It's an error if either the fai or dict file does not exist. The user is now responsible
    // for creating these files.
    if (!Files.exists(indexPath)) {
        throw new UserException.MissingReferenceFaiFile(indexPath, fastaPath);
    }
    if (!Files.exists(dictPath)) {
        throw new UserException.MissingReferenceDictFile(dictPath, fastaPath);
    }

    //Block-compressed fastas additionally require a gzi index
    try {
        final Path gziPath = GZIIndex.resolveIndexNameForBgzipFile(fastaPath);
        if( IOUtil.isBlockCompressed(fastaPath, true) && !Files.exists(gziPath)){
            throw new UserException.MissingReferenceGziFile(gziPath, fastaPath);
        }
    } catch (IOException e) {
        throw new UserException.CouldNotReadInputFile("Couldn't open fasta file: " + fastaPath.toUri().toString() +  ".", e);
    }
}
 
Example 4
Source File: CreateSequenceDictionary.java    From varsim with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public CreateSequenceDictionary(String FastaSequenceFileName) {
  try {
    md5 = MessageDigest.getInstance("MD5");
  } catch (NoSuchAlgorithmException e) {
    throw new RuntimeException("MD5 algorithm not found", e);
  }
  REFERENCE_SEQUENCE = new File(FastaSequenceFileName);
  URI = "file:" + REFERENCE_SEQUENCE.getAbsolutePath();
  OUTPUT = ReferenceSequenceFileFactory.getDefaultDictionaryForReferenceSequence(REFERENCE_SEQUENCE);
  logger.info("Output dictionary will be written in ", OUTPUT);
  doWork();
}