use of com.milaboratory.core.sequence.provider.SequenceProviderIndexOutOfBoundsException in project repseqio by repseqio.
the class CompileAction method compile.
public static void compile(Path source, Path destination, int surroundings) throws IOException {
VDJCLibraryRegistry.resetDefaultRegistry();
VDJCLibraryRegistry reg = VDJCLibraryRegistry.getDefault();
reg.registerLibraries(source, "lib");
List<VDJCLibraryData> result = new ArrayList<>();
for (VDJCLibrary lib : reg.getLoadedLibraries()) {
VDJCDataUtils.FragmentsBuilder fragmentsBuilder = new VDJCDataUtils.FragmentsBuilder();
for (KnownSequenceFragmentData fragment : lib.getData().getSequenceFragments()) fragmentsBuilder.addRegion(fragment);
for (VDJCGene gene : lib.getGenes()) {
if (!gene.getData().getBaseSequence().isPureOriginalSequence())
throw new IllegalArgumentException("Don't support mutated sequences yet.");
URI uri = gene.getData().getBaseSequence().getOrigin();
Range region = gene.getPartitioning().getContainingRegion();
region = region.expand(surroundings);
NucleotideSequence seq;
try {
seq = gene.getSequenceProvider().getRegion(region);
} catch (SequenceProviderIndexOutOfBoundsException e) {
region = e.getAvailableRange();
if (region == null)
throw new IllegalArgumentException("Wrong anchor points for " + gene.getName() + " ?");
seq = gene.getSequenceProvider().getRegion(region);
}
fragmentsBuilder.addRegion(uri, region, seq);
}
result.add(new VDJCLibraryData(lib.getTaxonId(), lib.getData().getSpeciesNames(), lib.getData().getGenes(), lib.getData().getMeta(), fragmentsBuilder.getFragments()));
}
VDJCDataUtils.writeToFile(result, destination, true);
log.info("{} compiled successfully.", source);
}
Aggregations