Add the missing groups to the SeqResGroups.
@param modelChain the chain to add the information for
@param sequence the sequence of the construct
5170
public static void addSeqRes(Chain modelChain, String sequence) {
		List<Group> seqResGroups = modelChain.getSeqResGroups();
		GroupType chainType = getChainType(modelChain.getAtomGroups());
		for(int i=0; i<sequence.length(); i++){
			char singleLetterCode = sequence.charAt(i);
			Group group = null;
			if(seqResGroups.size()<=i){
			}
			else{
				group=seqResGroups.get(i);
			}
			if(group!=null){
				continue;
			}
			group = getSeqResGroup(modelChain, singleLetterCode, chainType);
			addGroupAtId(seqResGroups, group, i);
			seqResGroups.set(i, group);
		}
	}
608561
public FastqBuilder withSequence(final String sequence)
	{
		if (sequence == null)
		{
			throw new IllegalArgumentException("sequence must not be null");
		}
		if (this.sequence == null)
		{
			this.sequence = new StringBuilder(sequence.length());
		}
		this.sequence.replace(0, this.sequence.length(), sequence);
		return this;
	}
1038853
public DictionaryBuilder add(CharSequence seq) throws DictionaryBuilderException {
        if (d_finalized)
            throw new DictionaryBuilderException("Cannot add a sequence to a finalized DictionaryBuilder.");

        if (d_prevSeq != null && compareCharacterSequences(d_prevSeq, seq) >= 0)
            throw new DictionaryBuilderException(String.format("Sequences are not added in lexicographic order: %s %s", d_prevSeq, seq));

        d_prevSeq = seq;

        // Traverse across the shared prefix.
        int i = 0;
        State curState = d_startState;
        for (int len = seq.length(); i < len; i++) {
            State nextState = curState.move(seq.charAt(i));
            if (nextState != null)
                curState = nextState;
            else
                break;
        }

        if (curState.hasOutgoing())
            replaceOrRegisterIterative(curState);

        addSuffix(curState, seq.subSequence(i, seq.length()));

        ++d_nSeqs;

        return this;
    }
176829
public static void fixMicroheterogenity(Structure bioJavaStruct) {
		// Loop through the models
		for (int i=0; i<bioJavaStruct.nrModels(); i++){
			// Then the chains
			List<Chain> chains = bioJavaStruct.getModel(i);
			for (Chain c : chains) {
				// Build a new list of groups
				List<Group> outGroups = new ArrayList<>();
				for (Group g : c.getAtomGroups()) {
					List<Group> removeList = new ArrayList<>();
					for (Group altLoc : g.getAltLocs()) {
						// Check if they are not equal -> microheterogenity
						if(! altLoc.getPDBName().equals(g.getPDBName())) {
							// Now add this group to the main list
							removeList.add(altLoc);
						}
					}
					// Add this group
					outGroups.add(g);
					// Remove any microhet alt locs
					g.getAltLocs().removeAll(removeList);
					// Add these microhet alt locs
					outGroups.addAll(removeList);
				}
				c.setAtomGroups(outGroups);
			}
		}
	}
939796
def _add_sequence(self, pdbID, chainID, sequence):
        ''''''
        pdbID = pdbID.upper()
        self[pdbID] = self.get(pdbID, {})
        self[pdbID][chainID] = sequence
        self.sequences.append((pdbID, chainID, sequence))
        if not self.unique_sequences.get(sequence):
            self.unique_sequences[sequence] = visible_colors[len(self.unique_sequences) % len(visible_colors)]
        self.identical_sequences = None
899429
protected void sequence_Parameter(ISerializationContext context, Parameter semanticObject) {
		if (errorAcceptor != null) {
			if (transientValues.isValueTransient(semanticObject, XtextPackage.Literals.PARAMETER__NAME) == ValueTransient.YES)
				errorAcceptor.accept(diagnosticProvider.createFeatureValueMissing(semanticObject, XtextPackage.Literals.PARAMETER__NAME));
		}
		SequenceFeeder feeder = createSequencerFeeder(context, semanticObject);
		feeder.accept(grammarAccess.getParameterAccess().getNameIDTerminalRuleCall_0(), semanticObject.getName());
		feeder.finish();
	}
29939
@Override
    public Object mapSequence(Object sequence) {
        List<?> seq = (List<?>) sequence;
        List<Object> out = new ArrayList<>();
        for (Object step : seq) {
            out.add(map(step));
        }
        return out;
    }
808337
private Group getNextGroup(int tmp_model,int tmp_chain,int tmp_group)
	throws NoSuchElementException
	{

		if ( tmp_model >= structure.nrModels()){
			throw new NoSuchElementException("arrived at end of structure!");
		}

		List<Chain> model = structure.getModel(tmp_model);

		if ( tmp_chain >= model.size() ){
			if(fixed_model)
				throw new NoSuchElementException("arrived at end of model!");
			return getNextGroup(tmp_model+1,0,0);
		}

		Chain     chain = model.get(tmp_chain);

		if (tmp_group  >= chain.getAtomLength()){
			// start search at beginning of next chain.
			return getNextGroup(tmp_model,tmp_chain+1,0);
		} else {
			current_model_pos = tmp_model;
			current_chain_pos = tmp_chain;
			current_group_pos = tmp_group;
			return chain.getAtomGroup(current_group_pos);
		}

	}
38304
private List<String> transformSimpleSequenceAsStringList(SimpleSequence sequence, String paramName)
            throws TemplateModelException {
        List<String> list = new ArrayList<>();
        int size = sequence.size();
        for (int i = 0; i < size; i++) {
            TemplateModel model = sequence.get(i);
            if (!(model instanceof SimpleScalar)) {
                throw new IllegalArgumentException(paramName + "'s item must be string");
            }
            list.add(((SimpleScalar)model).getAsString());
        }
        return list;
    }
588022
private void createSequencesConstraintsStatements(Statements statements, Iterable<Sequence> sequences) {
		Statement statement = createUniqueConstraintStatement( SEQUENCE_NAME_PROPERTY, NodeLabel.SEQUENCE.name() );
		statements.addStatement( statement );
	}
1189642
public GroupChain getGroupChainFor(final Collection<Class<?>> groups) {
    if (groups == null || groups.isEmpty()) {
      throw new IllegalArgumentException("At least one group has to be specified.");
    }

    groups.forEach(clazz -> {
      if (!validationGroupsMetadata.containsGroup(clazz)
          && !validationGroupsMetadata.isSeqeuence(clazz)) {
        throw new ValidationException("The class " + clazz + " is not a valid group or sequence.");
      }
    });

    final GroupChain chain = new GroupChain();
    groups.forEach(clazz -> {
      if (isGroupSequence(clazz)) {
        insertSequence(clazz, chain);
      } else {
        final Group group = new Group(clazz);
        chain.insertGroup(group);
        insertInheritedGroups(clazz, chain);
      }
    });

    return chain;
  }
140479
public void addAlignedSequence(S sequence){
		if(length == null){
			length = sequence.getLength();
		}
		if(sequence.getLength() != length){
			throw new IllegalArgumentException(sequence.getAccession() + " length = " + sequence.getLength() +
					" not equal to MSA length = " + length);
		}
		sequences.add(sequence);
	}
884436
private void addSequences(Iterable<Sequence> sequences) {
		Transaction tx = null;
		try {
			tx = neo4jDb.beginTx();
			for ( Sequence sequence : sequences ) {
				addSequence( sequence );
			}
			tx.success();
		}
		finally {
			tx.close();
		}
	}
691820
public void sequence(FA seq) {
        int idx;
        int relocation;

        relocation = append(seq);

        if (seq.start != -1) {
            for (idx = ends.first(); idx != -1; idx = ends.next(idx)) {
                states[idx].add(relocation + seq.start, null);
            }
        }

        ends.clear();
        for (idx = seq.ends.first(); idx != -1; idx = seq.ends.next(idx)) {
            ends.add(idx + relocation);
        }
    }
1010815
public void sampleSequenceRepeatedly(SequenceModel model, int[] sequence, int numSamples) {
    sequence = copy(sequence); // so we don't change the initial, or the one we just stored
    listener.setInitialSequence(sequence);
    for (int iter=0; iter<numSamples; iter++) {
      sampleSequenceForward(model, sequence);
    }
  }
838639
public void fitSequences(JavaRDD<Sequence<T>> corpus) {
        /**
         * Basically all we want for base implementation here is 3 things:
         * a) build vocabulary
         * b) build huffman tree
         * c) do training
         *
         * in this case all classes extending SeqVec, like deepwalk or word2vec will be just building their RDD<Sequence<T>>,
         * and calling this method for training, instead implementing own routines
         */

        validateConfiguration();

        if (ela == null) {
            try {
                ela = (SparkElementsLearningAlgorithm) Class.forName(configuration.getElementsLearningAlgorithm())
                                .newInstance();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }


        if (workers > 1) {
            log.info("Repartitioning corpus to {} parts...", workers);
            corpus.repartition(workers);
        }

        if (storageLevel != null)
            corpus.persist(storageLevel);

        final JavaSparkContext sc = new JavaSparkContext(corpus.context());

        // this will have any effect only if wasn't called before, in extension classes
        broadcastEnvironment(sc);

        Counter<Long> finalCounter;
        long numberOfSequences = 0;

        /**
         * Here we s
         */
        if (paramServerConfiguration == null) {
            paramServerConfiguration = VoidConfiguration.builder()
                    .numberOfShards(2).unicastPort(40123).multicastPort(40124).build();
            paramServerConfiguration.setFaultToleranceStrategy(FaultToleranceStrategy.NONE);
        }

        isAutoDiscoveryMode = paramServerConfiguration.getShardAddresses() != null
                        && !paramServerConfiguration.getShardAddresses().isEmpty() ? false : true;

        Broadcast<VoidConfiguration> paramServerConfigurationBroadcast = null;

        if (isAutoDiscoveryMode) {
            log.info("Trying auto discovery mode...");

            elementsFreqAccumExtra = corpus.context().accumulator(new ExtraCounter<Long>(),
                            new ExtraElementsFrequenciesAccumulator());

            ExtraCountFunction<T> elementsCounter =
                            new ExtraCountFunction<>(elementsFreqAccumExtra, configuration.isTrainSequenceVectors());

            JavaRDD<Pair<Sequence<T>, Long>> countedCorpus = corpus.map(elementsCounter);

            // just to trigger map function, since we need huffman tree before proceeding
            numberOfSequences = countedCorpus.count();

            finalCounter = elementsFreqAccumExtra.value();

            ExtraCounter<Long> spareReference = (ExtraCounter<Long>) finalCounter;

            // getting list of available hosts
            Set<NetworkInformation> availableHosts = spareReference.getNetworkInformation();

            log.info("availableHosts: {}", availableHosts);
            if (availableHosts.size() > 1) {
                // now we have to pick N shards and optionally N backup nodes, and pass them within configuration bean
                NetworkOrganizer organizer =
                                new NetworkOrganizer(availableHosts, paramServerConfiguration.getNetworkMask());

                paramServerConfiguration
                                .setShardAddresses(organizer.getSubset(paramServerConfiguration.getNumberOfShards()));

                // backup shards are optional
                if (paramServerConfiguration.getFaultToleranceStrategy() != FaultToleranceStrategy.NONE) {
                    paramServerConfiguration.setBackupAddresses(
                                    organizer.getSubset(paramServerConfiguration.getNumberOfShards(),
                                                    paramServerConfiguration.getShardAddresses()));
                }
            } else {
                // for single host (aka driver-only, aka spark-local) just run on loopback interface
                paramServerConfiguration.setShardAddresses(
                                Arrays.asList("127.0.0.1:" + paramServerConfiguration.getPortSupplier().getPort()));
                paramServerConfiguration.setFaultToleranceStrategy(FaultToleranceStrategy.NONE);
            }



            log.info("Got Shards so far: {}", paramServerConfiguration.getShardAddresses());

            // update ps configuration with real values where required
            paramServerConfiguration.setNumberOfShards(paramServerConfiguration.getShardAddresses().size());
            paramServerConfiguration.setUseHS(configuration.isUseHierarchicSoftmax());
            paramServerConfiguration.setUseNS(configuration.getNegative() > 0);

            paramServerConfigurationBroadcast = sc.broadcast(paramServerConfiguration);

        } else {

            // update ps configuration with real values where required
            paramServerConfiguration.setNumberOfShards(paramServerConfiguration.getShardAddresses().size());
            paramServerConfiguration.setUseHS(configuration.isUseHierarchicSoftmax());
            paramServerConfiguration.setUseNS(configuration.getNegative() > 0);

            paramServerConfigurationBroadcast = sc.broadcast(paramServerConfiguration);


            // set up freqs accumulator
            elementsFreqAccum = corpus.context().accumulator(new Counter<Long>(), new ElementsFrequenciesAccumulator());
            CountFunction<T> elementsCounter =
                            new CountFunction<>(configurationBroadcast, paramServerConfigurationBroadcast,
                                            elementsFreqAccum, configuration.isTrainSequenceVectors());

            // count all sequence elements and their sum
            JavaRDD<Pair<Sequence<T>, Long>> countedCorpus = corpus.map(elementsCounter);

            // just to trigger map function, since we need huffman tree before proceeding
            numberOfSequences = countedCorpus.count();

            // now we grab counter, which contains frequencies for all SequenceElements in corpus
            finalCounter = elementsFreqAccum.value();
        }

        long numberOfElements = (long) finalCounter.totalCount();

        long numberOfUniqueElements = finalCounter.size();

        log.info("Total number of sequences: {}; Total number of elements entries: {}; Total number of unique elements: {}",
                        numberOfSequences, numberOfElements, numberOfUniqueElements);

        /*
         build RDD of reduced SequenceElements, just get rid of labels temporary, stick to some numerical values,
         like index or hashcode. So we could reduce driver memory footprint
         */


        // build huffman tree, and update original RDD with huffman encoding info
        shallowVocabCache = buildShallowVocabCache(finalCounter);
        shallowVocabCacheBroadcast = sc.broadcast(shallowVocabCache);

        // FIXME: probably we need to reconsider this approach
        JavaRDD<T> vocabRDD = corpus
                        .flatMap(new VocabRddFunctionFlat<T>(configurationBroadcast, paramServerConfigurationBroadcast))
                        .distinct();
        vocabRDD.count();

        /**
         * now we initialize Shards with values. That call should be started from driver which is either Client or Shard in standalone mode.
         */
        VoidParameterServer.getInstance().init(paramServerConfiguration, new RoutedTransport(),
                        ela.getTrainingDriver());
        VoidParameterServer.getInstance().initializeSeqVec(configuration.getLayersSize(), (int) numberOfUniqueElements,
                        119, configuration.getLayersSize() / paramServerConfiguration.getNumberOfShards(),
                        paramServerConfiguration.isUseHS(), paramServerConfiguration.isUseNS());

        // proceed to training
        // also, training function is the place where we invoke ParameterServer
        TrainingFunction<T> trainer = new TrainingFunction<>(shallowVocabCacheBroadcast, configurationBroadcast,
                        paramServerConfigurationBroadcast);
        PartitionTrainingFunction<T> partitionTrainer = new PartitionTrainingFunction<>(shallowVocabCacheBroadcast,
                        configurationBroadcast, paramServerConfigurationBroadcast);

        if (configuration != null)
            for (int e = 0; e < configuration.getEpochs(); e++)
                corpus.foreachPartition(partitionTrainer);
        //corpus.foreach(trainer);


        // we're transferring vectors to ExportContainer
        JavaRDD<ExportContainer<T>> exportRdd =
                        vocabRDD.map(new DistributedFunction<T>(paramServerConfigurationBroadcast,
                                        configurationBroadcast, shallowVocabCacheBroadcast));

        // at this particular moment training should be pretty much done, and we're good to go for export
        if (exporter != null)
            exporter.export(exportRdd);

        // unpersist, if we've persisten corpus after all
        if (storageLevel != null)
            corpus.unpersist();

        log.info("Training finish, starting cleanup...");
        VoidParameterServer.getInstance().shutdown();
    }
635644
private static Chain removeSeqResHeterogeneity(Chain c) {

		Chain trimmedChain = new ChainImpl();

		ResidueNumber lastResNum = null;

		for (Group g:c.getAtomGroups()) {

			// note we have to deep copy this, otherwise they stay linked and would get altered in addGroup(g)
			ResidueNumber currentResNum = new ResidueNumber(
					g.getResidueNumber().getChainName(),
					g.getResidueNumber().getSeqNum(),
					g.getResidueNumber().getInsCode());

			if (lastResNum == null || !lastResNum.equals(currentResNum) ) {
				trimmedChain.addGroup(g);
			} else {
				logger.debug("Removing seqres group because it seems to be repeated in entity_poly_seq, most likely has hetero='y': "+g);
			}

			lastResNum = currentResNum;

		}
		return trimmedChain;
	}