private static IAllele validateAllele(@Nullable String speciesUid, IChromosomeType chromosomeType, @Nullable IAllele allele) { if (!chromosomeType.getAlleleClass().isInstance(allele)) { ISpeciesRoot speciesRoot = chromosomeType.getSpeciesRoot(); IAllele[] template = null; if (speciesUid != null) { template = speciesRoot.getTemplate(speciesUid); } if (template == null) { template = speciesRoot.getDefaultTemplate(); } return template[chromosomeType.ordinal()]; } return allele; }
@Override public void getTooltip(Tooltip tooltip, ITooltipFlag tooltipFlag) { tooltip.add(value.getName()); } }
private void refreshTemplate(@Nullable IChromosomeType selection) { List<Gene> genes = new ArrayList<>(); IChromosomeType[] chromosomeTypes = Binnie.GENETICS.getChromosomeMap(this.root).keySet().toArray(new IChromosomeType[0]); for (IChromosomeType type : chromosomeTypes) { IAllele allele = this.template[type.ordinal()]; if (allele == null) { throw new NullPointerException("Allele missing for Chromosome " + type.getName()); } genes.add(new Gene(allele, type, this.root)); } geneList.setOptions(genes); if (selection != null) { this.geneList.setValue(new Gene(this.template[selection.ordinal()], selection, this.root)); } else { this.geneOptions.setOptions(new ArrayList<>()); } this.refreshPickup(); }
if (chromosome.getAlleleClass().isInstance(allele)) { results.put(chromosome.getName(), MetaGenome.getAlleleMeta(allele));
public <T extends Enum<T> & IChromosomeType> void set(T chromosomeType, IAllele allele) { Preconditions.checkNotNull(allele, "Allele must not be null"); if (!chromosomeType.getAlleleClass().isInstance(allele)) { throw new IllegalArgumentException("Allele is the wrong type. Expected: " + chromosomeType + " Got: " + allele); } alleles[chromosomeType.ordinal()] = allele; }
public static void setGene(IGene gene, ItemStack target, boolean setPrimary, boolean setSecondary) { int chromosomeID = gene.getChromosome().ordinal(); Class<? extends IAllele> cls = gene.getChromosome().getAlleleClass(); if (!cls.isInstance(gene.getAllele())) { return;
ToleranceSystem(final IChromosomeType chromosomeType, final IToleranceType type) { this.speciesRootUid = chromosomeType.getSpeciesRoot().getUID(); this.chromosomeType = chromosomeType; this.type = type; }
@Nullable public IGene getGene(int chromosome) { for (IGene gene : genes) { if (gene.getChromosome().ordinal() == chromosome) { return gene; } } return null; }
if (chromosome == null) { String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + "Missing chromosome '%s'.\n%s", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes)); throw new IllegalArgumentException(message); if (primary == null) { String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + "Missing primary allele for '%s'.\n%s", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes)); throw new IllegalArgumentException(message); if (secondary == null) { String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + "Missing secondary allele for '%s'.\n%s", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes)); throw new IllegalArgumentException(message); Class<? extends IAllele> chromosomeAlleleClass = chromosomeType.getAlleleClass(); if (!chromosomeAlleleClass.isAssignableFrom(primary.getClass())) { String message = String.format("Tried to create a genome for '%s' from an invalid chromosome template. " + "Incorrect type for primary allele '%s'.\n%s.", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes)); throw new IllegalArgumentException(message); "Incorrect type for secondary allele '%s'.\n%s.", getSpeciesRoot().getUID(), chromosomeType.getName(), chromosomesToString(chromosomes)); throw new IllegalArgumentException(message);
@Override public <T extends Enum<T> & IChromosomeType> void set(IAllele[] alleles, T chromosomeType, IAllele allele) { if (!chromosomeType.getAlleleClass().isInstance(allele)) { throw new IllegalArgumentException("Allele is the wrong type. Expected: " + chromosomeType + " Got: " + allele); } Collection<IChromosomeType> validTypes = AlleleManager.alleleRegistry.getChromosomeTypes(allele); if (validTypes.size() > 0 && !validTypes.contains(chromosomeType)) { throw new IllegalArgumentException("Allele can't applied to this Chromosome type. Expected: " + validTypes + " Got: " + chromosomeType); } alleles[chromosomeType.ordinal()] = allele; }
public static IAllele getAllele(ItemStack itemStack, IChromosomeType type, boolean active) { IAllele allele = getSpeciesDirectly(itemStack, type, active); if (allele == null) { IChromosome chromosome = getChromosome(itemStack, type, type.getSpeciesRoot()); allele = active ? chromosome.getActiveAllele() : chromosome.getInactiveAllele(); } return allele; }
@Override public IAllele getInactiveAllele(IChromosomeType chromosomeType) { return chromosomes[chromosomeType.ordinal()].getInactiveAllele(); }
private String chromosomesToString(IChromosome[] chromosomes) { StringBuilder stringBuilder = new StringBuilder(); IChromosomeType[] karyotype = getSpeciesRoot().getKaryotype(); for (int i = 0; i < chromosomes.length; i++) { IChromosomeType chromosomeType = karyotype[i]; IChromosome chromosome = chromosomes[i]; stringBuilder.append(chromosomeType.getName()).append(": ").append(chromosome).append("\n"); } return stringBuilder.toString(); }
@Override public void addValidAlleleTypes(IAllele allele, IChromosomeType... chromosomeTypes) { for (IChromosomeType chromosomeType : chromosomeTypes) { if (!chromosomeType.getAlleleClass().isAssignableFrom(allele.getClass())) { throw new IllegalArgumentException("Allele class (" + allele.getClass() + ") does not match chromosome type (" + chromosomeType.getAlleleClass() + ")."); } allelesByType.put(chromosomeType, allele); typesByAllele.put(allele, chromosomeType); } }
public final void drawSpeciesRow(String text0, IIndividual individual, IChromosomeType chromosome, @Nullable String customPrimaryName, @Nullable String customSecondaryName) { IAlleleSpecies primary = individual.getGenome().getPrimary(); IAlleleSpecies secondary = individual.getGenome().getSecondary(); textLayout.drawLine(text0, textLayout.column0); int columnwidth = textLayout.column2 - textLayout.column1 - 2; Map<String, ItemStack> iconStacks = chromosome.getSpeciesRoot().getAlyzerPlugin().getIconStacks(); GuiUtil.drawItemStack(this, iconStacks.get(primary.getUID()), guiLeft + textLayout.column1 + columnwidth - 20, guiTop + 10); GuiUtil.drawItemStack(this, iconStacks.get(secondary.getUID()), guiLeft + textLayout.column2 + columnwidth - 20, guiTop + 10); String primaryName = customPrimaryName == null ? primary.getAlleleName() : customPrimaryName; String secondaryName = customSecondaryName == null ? secondary.getAlleleName() : customSecondaryName; drawSplitLine(primaryName, textLayout.column1, columnwidth, individual, chromosome, false); drawSplitLine(secondaryName, textLayout.column2, columnwidth, individual, chromosome, true); textLayout.newLine(); }
@Override public IAllele getActiveAllele(IChromosomeType chromosomeType) { return chromosomes[chromosomeType.ordinal()].getActiveAllele(); }
@Nonnull @Override public Map<Object, Object> getMeta(@Nonnull IGenome genome) { IChromosomeType[] types = genome.getSpeciesRoot().getKaryotype(); Map<String, Object> active = Maps.newHashMapWithExpectedSize(types.length); Map<String, Object> inactive = Maps.newHashMapWithExpectedSize(types.length); for (IChromosomeType type : types) { active.put(type.getName(), getAlleleMeta(genome.getActiveAllele(type))); inactive.put(type.getName(), getAlleleMeta(genome.getInactiveAllele(type))); } Map<Object, Object> out = Maps.newHashMap(); out.put("active", active); out.put("inactive", inactive); return out; }
private void loadAlleles() { this.invalidChromosomeTypes.clear(); for (IBreedingSystem system : BREEDING_SYSTEMS.values()) { ISpeciesRoot root = system.getSpeciesRoot(); Map<IChromosomeType, List<IAllele>> chromosomeMap = new LinkedHashMap<>(); for (IChromosomeType chromosome : root.getKaryotype()) { TreeSet<IAllele> alleles = new TreeSet<>(new ComparatorAllele()); for (IIndividual individual : root.getIndividualTemplates()) { IGenome genome = individual.getGenome(); IAllele activeAllele = genome.getActiveAllele(chromosome); IAllele inactiveAllele = genome.getInactiveAllele(chromosome); if (chromosome.getAlleleClass().isInstance(activeAllele)) { alleles.add(activeAllele); } if (!chromosome.getAlleleClass().isInstance(inactiveAllele)) { continue; } alleles.add(inactiveAllele); } system.addExtraAlleles(chromosome, alleles); if (alleles.size() == 0) { this.invalidChromosomeTypes.add(chromosome); } else { final List<IAllele> alleleList = new ArrayList<>(alleles); chromosomeMap.put(chromosome, alleleList); } } this.chromosomeArray.put(root, chromosomeMap); } }
@Override public Collection<? extends IMutation> getPaths(IAllele result, IChromosomeType chromosomeType) { ArrayList<IMutation> paths = new ArrayList<>(); for (IMutation mutation : getMutations(false)) { if (mutation.getTemplate()[chromosomeType.ordinal()] == result) { paths.add(mutation); } } return paths; }