use of utils.GtfLine in project ASCIIGenome by dariober.
the class UcscFetch method blockCompressAndIndex.
/**
* Block compress input file and create associated tabix index. Newly created file and index are
* deleted on exit if deleteOnExit true.
* @throws IOException
* @throws InvalidRecordException
*/
private void blockCompressAndIndex(String in, String bgzfOut, boolean deleteOnExit) throws IOException, InvalidRecordException {
File inFile = new File(in);
File outFile = new File(bgzfOut);
LineIterator lin = utils.IOUtils.openURIForLineIterator(inFile.getAbsolutePath());
BlockCompressedOutputStream writer = new BlockCompressedOutputStream(outFile);
long filePosition = writer.getFilePointer();
TabixIndexCreator indexCreator = new TabixIndexCreator(TabixFormat.GFF);
while (lin.hasNext()) {
String line = lin.next();
GtfLine gtf = new GtfLine(line.split("\t"));
writer.write(line.getBytes());
writer.write('\n');
indexCreator.addFeature(gtf, filePosition);
filePosition = writer.getFilePointer();
}
writer.flush();
File tbi = new File(bgzfOut + TabixUtils.STANDARD_INDEX_EXTENSION);
if (tbi.exists() && tbi.isFile()) {
writer.close();
throw new RuntimeException("Index file exists: " + tbi);
}
Index index = indexCreator.finalizeIndex(writer.getFilePointer());
index.writeBasedOnFeatureFile(outFile);
writer.close();
if (deleteOnExit) {
outFile.deleteOnExit();
File idx = new File(outFile.getAbsolutePath() + TabixUtils.STANDARD_INDEX_EXTENSION);
idx.deleteOnExit();
}
}
use of utils.GtfLine in project ASCIIGenome by dariober.
the class MakeTabixIndex method addLineToIndex.
/**
* Set vcfHeader and vcfCodec to null if reading non-vcf line.
*/
private void addLineToIndex(String line, TabixIndexCreator indexCreator, long filePosition, TabixFormat fmt, VCFHeader vcfHeader, VCFCodec vcfCodec) throws InvalidRecordException {
if (fmt.equals(TabixFormat.BED)) {
BedLineCodec bedCodec = new BedLineCodec();
BedLine bed = bedCodec.decode(line);
indexCreator.addFeature(bed, filePosition);
} else if (fmt.equals(TabixFormat.GFF)) {
GtfLine gtf = new GtfLine(line.split("\t"));
indexCreator.addFeature(gtf, filePosition);
} else if (fmt.equals(TabixFormat.VCF)) {
VariantContext vcf = vcfCodec.decode(line);
indexCreator.addFeature(vcf, filePosition);
} else {
System.err.println("Unexpected TabixFormat: " + fmt.sequenceColumn + " " + fmt.startPositionColumn);
throw new InvalidRecordException();
}
}
Aggregations