Skip to content

Commit

Permalink
Improve index creation
Browse files Browse the repository at this point in the history
  • Loading branch information
seppinho committed Jul 12, 2024
1 parent 4958e29 commit 809f070
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/main/java/genepi/nf/test/vcf/VcfFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Set;

import genepi.io.text.LineReader;
import htsjdk.samtools.SAMSequenceDictionary;
import htsjdk.samtools.util.CloseableIterator;
import htsjdk.tribble.index.IndexFactory;
import htsjdk.tribble.index.tabix.TabixFormat;
Expand Down Expand Up @@ -243,12 +244,12 @@ public void setNoSamples(int noSamples) {
}

public void createIndex() throws IOException {

TabixIndex index = IndexFactory.createTabixIndex(new File(vcfFilename), new VCFCodec(), TabixFormat.VCF, null);
File indexFile = new File(new File(vcfFilename).getAbsolutePath() + ".tbi");
if(!indexFile.exists()) {
index.write(indexFile);
}
File vcfFile = new File(vcfFilename);
VCFFileReader reader = new VCFFileReader(vcfFile, false);
SAMSequenceDictionary vcfDict = reader.getFileHeader().getSequenceDictionary();
TabixIndex index = IndexFactory.createTabixIndex(new File(vcfFilename), new VCFCodec(), TabixFormat.VCF, vcfDict);
index.writeBasedOnFeatureFile(new File(vcfFilename));
reader.close();
}

}

0 comments on commit 809f070

Please sign in to comment.