final ReferenceSequenceFile ref;
try {
ref = ReferenceSequenceFileFactory.getReferenceSequenceFile(refFile);
} catch ( Exception e ) {
throw new UserException("Couldn't load provided reference sequence file " + refFile, e);
}
variant = parseVariantList(variant);
Comparator<Pair<Integer,File>> positionComparator = new PositionComparator();
Queue<Pair<Integer,File>> priorityQueue;
if (assumeSorted)
priorityQueue = new LinkedList<>();
else
priorityQueue = new PriorityQueue<>(10000, positionComparator);
FileType fileType = FileType.INVALID;
for (File file : variant) {
// if it returns a valid type, it will be the same for all files
fileType = fileExtensionCheck(file, outputFile);
if (fileType == FileType.INVALID)
return 1;
if (assumeSorted){
priorityQueue.add(new Pair<>(0,file));
}
else{
if (!file.exists()) {
throw new UserException(String.format("File %s doesn't exist",file.getAbsolutePath()));
}
FeatureReader<VariantContext> reader = getFeatureReader(fileType, file);
Iterator<VariantContext> it = reader.iterator();
if(!it.hasNext()){
System.err.println(String.format("File %s is empty. This file will be ignored",file.getAbsolutePath()));
continue;
}
VariantContext vc = it.next();
int firstPosition = vc.getStart();
reader.close();
priorityQueue.add(new Pair<>(firstPosition,file));
}
}
FileOutputStream outputStream = new FileOutputStream(outputFile);
EnumSet<Options> options = EnumSet.of(Options.INDEX_ON_THE_FLY);
final IndexCreator idxCreator = GATKVCFUtils.getIndexCreator(variant_index_type, variant_index_parameter, outputFile, ref.getSequenceDictionary());
final VariantContextWriter outputWriter = VariantContextWriterFactory.create(outputFile, outputStream, ref.getSequenceDictionary(), idxCreator, options);
boolean firstFile = true;
int count = 0;
while(!priorityQueue.isEmpty() ){
count++;
File file = priorityQueue.remove().getSecond();
if (!file.exists()) {
throw new UserException(String.format("File %s doesn't exist",file.getAbsolutePath()));
}
FeatureReader<VariantContext> reader = getFeatureReader(fileType, file);
if(count%10 ==0)
System.out.print(count);