- lastChainId = chainId;
- length++;
- }
- if (length > 0)
- {
- /*
- * record the length of the final chain
- */
- chainLengths.add(length);
- }
-
- return chainLengths;
- }
-
- /**
- * Helper method to construct a sequence for one chain and add it to the seqs
- * list
- *
- * @param monomers
- * a list of all monomers in the chain
- * @param modelTitle
- */
- protected void buildSequenceFromChain(List<Monomer> monomers,
- String modelTitle)
- {
- final int length = monomers.size();
-
- /*
- * arrays to hold sequence and secondary structure
- */
- char[] seq = new char[length];
- char[] secstr = new char[length];
- char[] secstrcode = new char[length];
-
- /*
- * populate the sequence and secondary structure arrays
- */
- extractJmolChainData(monomers, seq, secstr, secstrcode);
-
- /*
- * grab chain code and start position from first residue;
- */
- String chainId = monomers.get(0).chain.getIDStr();
- int firstResNum = monomers.get(0).getResno();
- if (firstResNum < 1)
- {
- // Jalview doesn't like residue < 1, so force this to 1
- System.err.println("Converting chain " + chainId + " first RESNUM ("
- + firstResNum + ") to 1");
- firstResNum = 1;
- }
-
- /*
- * convert any non-gap unknown residues to 'X'
- */
- convertNonGapCharacters(seq);
-
- /*
- * construct and add the Jalview sequence
- */
- String seqName = "" + modelTitle + "|" + chainId;
- int start = firstResNum;
- int end = firstResNum + length - 1;
-
- SequenceI sq = new Sequence(seqName, seq, start, end);
-
- addPdbid(sq, modelTitle, chainId);
-
- addSourceDBref(sq, modelTitle, start, end);
-
- seqs.add(sq);
-
- /*
- * add secondary structure predictions (if any)
- */
- addSecondaryStructureAnnotation(modelTitle, sq, secstr, secstrcode,
- chainId, firstResNum);
-
- }
-
- /**
- * Scans the list of (Jmol) Monomer objects, and adds the residue for each to
- * the sequence array, and any converted secondary structure prediction to the
- * secondary structure arrays
- *
- * @param monomers
- * @param seq
- * @param secstr
- * @param secstrcode
- */
- protected void extractJmolChainData(List<Monomer> monomers, char[] seq,
- char[] secstr, char[] secstrcode)
- {
- int pos = 0;
- for (Monomer monomer : monomers)
- {
- seq[pos] = monomer.getGroup1();
-
- /*
- * JAL-1828 replace a modified amino acid with its standard equivalent
- * (e.g. MSE with MET->M) to maximise sequence matching
- */
- replaceNonCanonicalResidue(monomer.getGroup3(), seq, pos);
-
- /*
- * if Jmol has derived a secondary structure prediction for this position,
- * convert it to Jalview equivalent and save it
- */
- setSecondaryStructure(monomer.getProteinStructureSubType(), pos,
- secstr, secstrcode);
- pos++;
- }
- }
-
- /**
- * Replace any non-gap miscellaneous characters with 'X'
- *
- * @param seq
- * @return
- */
- protected void convertNonGapCharacters(char[] seq)
- {
- boolean isNa = Comparison.areNucleotide(new char[][] { seq });
- int[] cinds = isNa ? ResidueProperties.nucleotideIndex
- : ResidueProperties.aaIndex;
- int nonGap = isNa ? ResidueProperties.maxNucleotideIndex
- : ResidueProperties.maxProteinIndex;
-
- for (int p = 0; p < seq.length; p++)
- {
- if (cinds[seq[p]] == nonGap)