Search in sources :

Example 96 with Pair

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;
}
Also used : BlockSurfacePos(ivorius.ivtoolkit.blocks.BlockSurfacePos) java.util(java.util) Blocks(net.minecraft.init.Blocks) AxisAlignedTransform2D(ivorius.ivtoolkit.math.AxisAlignedTransform2D) World(net.minecraft.world.World) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) StructureSpawnContext(ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) StructureGenerator(ivorius.reccomplex.world.gen.feature.StructureGenerator) BlockPos(net.minecraft.util.math.BlockPos) Multimap(com.google.common.collect.Multimap) WeightedSelector(ivorius.ivtoolkit.random.WeightedSelector) RCConfig(ivorius.reccomplex.RCConfig) Collectors(java.util.stream.Collectors) Environment(ivorius.reccomplex.world.gen.feature.structure.Environment) IBlockState(net.minecraft.block.state.IBlockState) IvFunctions(ivorius.ivtoolkit.util.IvFunctions) Lists(com.google.common.collect.Lists) Pair(org.apache.commons.lang3.tuple.Pair) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) WorldServer(net.minecraft.world.WorldServer) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) Nullable(javax.annotation.Nullable) SaplingGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.SaplingGeneration) StructureBoundingBox(net.minecraft.world.gen.structure.StructureBoundingBox) SaplingGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.SaplingGeneration) Environment(ivorius.reccomplex.world.gen.feature.structure.Environment) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) Pair(org.apache.commons.lang3.tuple.Pair) Nullable(javax.annotation.Nullable)

Example 97 with 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()));
}
Also used : BlockSurfacePos(ivorius.ivtoolkit.blocks.BlockSurfacePos) NaturalStructureSelector(ivorius.reccomplex.world.gen.feature.selector.NaturalStructureSelector) StaticGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.StaticGeneration) Structures(ivorius.reccomplex.world.gen.feature.structure.Structures) Predicate(java.util.function.Predicate) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) StructureSpawnContext(ivorius.reccomplex.world.gen.feature.structure.context.StructureSpawnContext) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) Random(java.util.Random) RCConfig(ivorius.reccomplex.RCConfig) Collectors(java.util.stream.Collectors) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) MathHelper(net.minecraft.util.math.MathHelper) MixingStructureSelector(ivorius.reccomplex.world.gen.feature.selector.MixingStructureSelector) NaturalGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.NaturalGeneration) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) WorldServer(net.minecraft.world.WorldServer) IvVecMathHelper(ivorius.ivtoolkit.math.IvVecMathHelper) Biome(net.minecraft.world.biome.Biome) Nullable(javax.annotation.Nullable) ChunkPos(net.minecraft.util.math.ChunkPos) NaturalGeneration(ivorius.reccomplex.world.gen.feature.structure.generic.generation.NaturalGeneration) Pair(org.apache.commons.lang3.tuple.Pair)

Example 98 with Pair

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);
}
Also used : Triple(org.apache.commons.lang3.tuple.Triple) Item(net.minecraft.item.Item) GeneratingItem(ivorius.reccomplex.item.GeneratingItem) GeneratingItem(ivorius.reccomplex.item.GeneratingItem) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Example 99 with Pair

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;
}
Also used : Transition(org.broadinstitute.hellbender.tools.picard.analysis.artifacts.Transition) VariantContext(htsjdk.variant.variantcontext.VariantContext) MetricsFile(htsjdk.samtools.metrics.MetricsFile) File(java.io.File) Pair(org.apache.commons.lang3.tuple.Pair)

Example 100 with Pair

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;
}
Also used : Covariate(org.broadinstitute.hellbender.utils.recalibration.covariates.Covariate) GATKReportTable(org.broadinstitute.hellbender.utils.report.GATKReportTable) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair) NestedIntegerArray(org.broadinstitute.hellbender.utils.collections.NestedIntegerArray)

Aggregations

Pair (org.apache.commons.lang3.tuple.Pair)111 ArrayList (java.util.ArrayList)98 Mutable (org.apache.commons.lang3.mutable.Mutable)97 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)87 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)86 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)75 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)73 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)63 Pair (org.apache.hyracks.algebricks.common.utils.Pair)62 MutableObject (org.apache.commons.lang3.mutable.MutableObject)42 List (java.util.List)35 HashMap (java.util.HashMap)34 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)32 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)30 Collectors (java.util.stream.Collectors)29 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)29 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)29 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)27 HashSet (java.util.HashSet)25 File (java.io.File)24