use of org.apache.commons.lang3.tuple.Pair in project RecurrentComplex by Ivorforce.
the class RCSaplingGenerator method findRandomSapling.
@Nullable
public static Pair<Structure<?>, SaplingGeneration> findRandomSapling(WorldServer world, BlockPos pos, Random random, boolean considerVanilla) {
Environment baseEnv = Environment.inNature(world, new StructureBoundingBox(pos, pos));
List<Pair<Structure<?>, SaplingGeneration>> applicable = StructureRegistry.INSTANCE.getStructureGenerations(SaplingGeneration.class).stream().filter(pair1 -> pair1.getRight().generatesIn(baseEnv.withGeneration(pair1.getRight()))).collect(Collectors.toCollection(ArrayList::new));
// Hackily consider big vanilla trees too
int vanillaComplexity = complexity(world, pos, random, predictors);
ImmutableMultimap<Integer, Pair<Structure<?>, SaplingGeneration>> groups = IvFunctions.groupMap(applicable, pair -> pair.getRight().pattern.pattern.compile(true).size());
List<Integer> complexities = Lists.newArrayList(groups.keySet());
if (vanillaComplexity > 0)
complexities.add(vanillaComplexity);
Collections.sort(complexities);
Pair<Structure<?>, SaplingGeneration> pair = null;
while (complexities.size() > 0 && pair == null) {
Integer complexity = complexities.remove(complexities.size() - 1);
Set<Pair<Structure<?>, SaplingGeneration>> placeable = groups.get(complexity).stream().filter(p -> p.getRight().pattern.canPlace(world, pos, p.getLeft().size(), p.getLeft().isRotatable(), p.getLeft().isMirrorable())).collect(Collectors.toSet());
double totalWeight = placeable.stream().mapToDouble(RCSaplingGenerator::getSpawnWeight).sum();
if (complexity == vanillaComplexity && considerVanilla) {
if (random.nextDouble() * (totalWeight * RCConfig.baseSaplingSpawnWeight + 1) < 1)
break;
}
if (totalWeight > 0)
pair = WeightedSelector.select(random, placeable, RCSaplingGenerator::getSpawnWeight);
}
return pair;
}
use of org.apache.commons.lang3.tuple.Pair in project RecurrentComplex by Ivorforce.
the class WorldGenStructures method planStructuresInChunk.
public static void planStructuresInChunk(Random random, ChunkPos chunkPos, WorldServer world, Biome biomeGen, @Nullable Predicate<Structure> structurePredicate) {
MixingStructureSelector<NaturalGeneration, NaturalStructureSelector.Category> structureSelector = StructureRegistry.INSTANCE.naturalStructureSelectors().get(biomeGen, world.provider);
float distanceToSpawn = distance(new ChunkPos(world.getSpawnPoint()), chunkPos);
// TODO Use STRUCTURE_TRIES
List<Pair<Structure<?>, NaturalGeneration>> generated = structureSelector.generatedStructures(random, world.getBiome(chunkPos.getBlock(0, 0, 0)), world.provider, distanceToSpawn);
generated.stream().filter(pair -> structurePredicate == null || structurePredicate.test(pair.getLeft())).forEach(pair -> planStructureInChunk(chunkPos, world, pair.getLeft(), pair.getRight(), random.nextLong()));
}
use of org.apache.commons.lang3.tuple.Pair in project RecurrentComplex by Ivorforce.
the class InventoryGenerationHandler method generateAllTags.
public static void generateAllTags(WorldServer server, IInventory inventory, MCRegistrySpecial.ItemHidingRegistry registry, Random random) {
List<Triple<ItemStack, GeneratingItem, Integer>> foundGenerators = new ArrayList<>();
boolean didChange = true;
int cycles = 0;
do {
if (didChange) {
for (int i = 0; i < inventory.getSizeInventory(); i++) {
ItemStack stack = inventory.getStackInSlot(i);
if (!stack.isEmpty()) {
Item item = registry.containedItem(stack);
if (item instanceof GeneratingItem) {
foundGenerators.add(Triple.of(stack, (GeneratingItem) item, i));
inventory.setInventorySlotContents(i, ItemStack.EMPTY);
}
}
}
didChange = false;
}
if (foundGenerators.size() > 0) {
Triple<ItemStack, GeneratingItem, Integer> pair = foundGenerators.get(0);
pair.getMiddle().generateInInventory(server, inventory, random, pair.getLeft(), pair.getRight());
foundGenerators.remove(0);
didChange = true;
}
cycles++;
} while ((foundGenerators.size() > 0 || didChange) && cycles < 1000);
}
use of org.apache.commons.lang3.tuple.Pair in project gatk by broadinstitute.
the class FilterByOrientationBias method onTraversalSuccess.
@Override
public Object onTraversalSuccess() {
logger.info("Tagging whether genotypes are in one of the artifact modes.");
// Calculate how many artifacts need to be cut
double fdrThreshold = 0.01;
final List<VariantContext> finalVariants = OrientationBiasFilterer.annotateVariantContextsWithFilterResults(fdrThreshold, relevantTransitions, firstPassVariants, transitionToPreAdapterScoreMap);
logger.info("Writing variants to VCF...");
finalVariants.forEach(vcfWriter::add);
logger.info("Writing a simple summary table...");
List<String> sampleNames = new ArrayList<>();
if (finalVariants.size() != 0) {
sampleNames = finalVariants.get(0).getSampleNamesOrderedByName();
}
final List<Pair<String, Transition>> sampleTransitionCombinations = new ArrayList<>();
for (Transition relevantTransition : relevantTransitions) {
for (String sampleName : sampleNames) {
sampleTransitionCombinations.add(Pair.of(sampleName, relevantTransition));
}
}
OrientationBiasUtils.writeOrientationBiasSummaryTable(sampleTransitionCombinations, finalVariants, transitionToPreAdapterScoreMap, new File(outputFile.getAbsolutePath() + SUMMARY_FILE_SUFFIX));
return null;
}
use of org.apache.commons.lang3.tuple.Pair in project gatk by broadinstitute.
the class RecalUtils method generateReportTables.
public static List<GATKReportTable> generateReportTables(final RecalibrationTables recalibrationTables, final StandardCovariateList covariates) {
final List<GATKReportTable> result = new LinkedList<>();
int rowIndex = 0;
GATKReportTable allCovsReportTable = null;
for (NestedIntegerArray<RecalDatum> table : recalibrationTables) {
// initialize the array to hold the column names
final ArrayList<Pair<String, String>> columnNames = new ArrayList<>();
// save the required covariate name so we can reference it in the future
columnNames.add(new MutablePair<>(covariates.getReadGroupCovariate().parseNameForReport(), "%s"));
if (!recalibrationTables.isReadGroupTable(table)) {
// save the required covariate name so we can reference it in the future
columnNames.add(new MutablePair<>(covariates.getQualityScoreCovariate().parseNameForReport(), "%d"));
if (recalibrationTables.isAdditionalCovariateTable(table)) {
columnNames.add(covariateValue);
columnNames.add(covariateName);
}
}
// the order of these column names is important here
columnNames.add(eventType);
columnNames.add(empiricalQuality);
if (recalibrationTables.isReadGroupTable(table)) {
// only the read group table needs the estimated Q reported
columnNames.add(estimatedQReported);
}
columnNames.add(nObservations);
columnNames.add(nErrors);
final String reportTableName = getReportTableName(recalibrationTables, table);
final GATKReportTable.Sorting sort = GATKReportTable.Sorting.SORT_BY_COLUMN;
final GATKReportTable reportTable;
final boolean addToList;
//XXX this "if" implicitly uses the knowledge about the ordering of tables.
if (!recalibrationTables.isAdditionalCovariateTable(table)) {
reportTable = makeNewTableWithColumns(columnNames, reportTableName, sort);
// reset the row index since we're starting with a new table
rowIndex = 0;
addToList = true;
} else if (allCovsReportTable == null && recalibrationTables.isAdditionalCovariateTable(table)) {
reportTable = makeNewTableWithColumns(columnNames, reportTableName, sort);
// reset the row index since we're starting with a new table
rowIndex = 0;
allCovsReportTable = reportTable;
addToList = true;
} else {
reportTable = allCovsReportTable;
addToList = false;
}
for (final NestedIntegerArray.Leaf<RecalDatum> row : table.getAllLeaves()) {
final RecalDatum datum = row.value;
final int[] keys = row.keys;
int columnIndex = 0;
int keyIndex = 0;
reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), covariates.getReadGroupCovariate().formatKey(keys[keyIndex++]));
if (!recalibrationTables.isReadGroupTable(table)) {
reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), covariates.getQualityScoreCovariate().formatKey(keys[keyIndex++]));
if (recalibrationTables.isAdditionalCovariateTable(table)) {
final Covariate covariate = recalibrationTables.getCovariateForTable(table);
reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), covariate.formatKey(keys[keyIndex++]));
reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), covariate.parseNameForReport());
}
}
final EventType event = EventType.eventFrom(keys[keyIndex]);
reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), event.toString());
reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), datum.getEmpiricalQuality());
if (recalibrationTables.isReadGroupTable(table)) {
// we only add the estimated Q reported in the RG table
reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), datum.getEstimatedQReported());
}
reportTable.set(rowIndex, columnNames.get(columnIndex++).getLeft(), datum.getNumObservations());
reportTable.set(rowIndex, columnNames.get(columnIndex).getLeft(), datum.getNumMismatches());
rowIndex++;
}
if (addToList) {
//XXX using a set would be slow because the equals method on GATKReportTable is expensive.
result.add(reportTable);
}
}
return result;
}
Aggregations