Better handling of fasta files with non-standard extensions.x
git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@1206 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
parent
5e26770634
commit
60a86fb34a
|
|
@ -22,6 +22,7 @@ import net.sf.samtools.SAMTextHeaderCodec;
|
|||
import net.sf.samtools.SAMFileHeader;
|
||||
import net.sf.samtools.SAMSequenceRecord;
|
||||
import net.sf.samtools.util.AsciiLineReader;
|
||||
import org.broadinstitute.sting.utils.StingException;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
|
|
@ -64,7 +65,7 @@ public class IndexedFastaSequenceFile implements ReferenceSequenceFile {
|
|||
private void loadDictionary( File fastaFile ) {
|
||||
// Try and locate the dictionary
|
||||
String dictionaryName = fastaFile.getAbsolutePath();
|
||||
dictionaryName = dictionaryName.substring(0, dictionaryName.lastIndexOf(".fasta"));
|
||||
dictionaryName = dictionaryName.substring(0, getFastaFileExtensionStart(dictionaryName));
|
||||
dictionaryName += ".dict";
|
||||
final File dictionary = new File(dictionaryName);
|
||||
if (!dictionary.exists())
|
||||
|
|
@ -85,6 +86,21 @@ public class IndexedFastaSequenceFile implements ReferenceSequenceFile {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the index of the first character in the fasta file's extension.
|
||||
* @param filename The filename of the fasta. Must not be null, and must end with either '.fasta' or '.fa'.
|
||||
* @return The index of the start of the extension within the filename. If neither '.fasta' nor '.fa' are
|
||||
* present in the filename, a StingException will be thrown.
|
||||
*/
|
||||
private int getFastaFileExtensionStart( String filename ) {
|
||||
if( filename.endsWith(".fasta") )
|
||||
return filename.lastIndexOf(".fasta");
|
||||
else if( filename.endsWith(".fa") )
|
||||
return filename.lastIndexOf(".fa");
|
||||
else
|
||||
throw new StingException("Invalid fasta filename; fasta filename must end with '.fasta' or '.fa'.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the index for the fasta, if present. Throws an exception if now present.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue