package jalview.structure; import jalview.datamodel.SequenceI; import jalview.io.StructureFile; import jalview.structures.models.MappingOutputModel; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Map.Entry; import MCview.Atom; import MCview.PDBChain; public abstract class StructureMappingClient { protected StructureFile structureFile; private static final int PDB_RES_POS = StructureMapping.PDB_RES_NUM_INDEX; // 0 private static final int PDB_ATOM_POS = StructureMapping.PDB_ATOM_NUM_INDEX; // 1 /** * Populates the atom positions mapped to by finding the atom number (if any) * for each structure residue number in the map. If no atom is found (as is * the case for residues missing in a PDB file), then deletes the residue from * the map. * * @param chainId * @param mapping * @throws IllegalArgumentException * @throws StructureMappingException */ public void populateAtomPositions(String chainId, Map mapping) throws IllegalArgumentException, StructureMappingException { try { PDBChain chain = structureFile.findChain(chainId); if (chain == null || mapping == null) { throw new IllegalArgumentException( "Chain id or mapping must not be null."); } List notFound = new ArrayList(); for (Entry map : mapping.entrySet()) { int structureResNo = map.getValue()[PDB_RES_POS]; /* * find the atom number in the chain for this residue number * NB only CA or P atoms have been saved in the chain - see * JmolParser.convertSignificantAtoms */ int atomIndex = getAtomIndex(structureResNo, chain.atoms); if (atomIndex == StructureMapping.UNASSIGNED) { notFound.add(map.getKey()); } else { map.getValue()[PDB_ATOM_POS] = atomIndex; } } for (Integer missing : notFound) { mapping.remove(missing); } } catch (Exception e) { throw new StructureMappingException( "Structure mapping exception occured."); } } /** * * @param residueIndex * The residue index used for the search * @param atoms * A collection of Atom to search * @return atom position for the given residue index */ public int getAtomIndex(int residueIndex, Collection atoms) { if (atoms == null) { throw new IllegalArgumentException( "atoms collection must not be null!"); } for (Atom atom : atoms) { if (atom.resNumber == residueIndex) { return atom.atomIndex; } } return StructureMapping.UNASSIGNED; } public class StructureMappingException extends Exception { private static final long serialVersionUID = 1L; public StructureMappingException(String message) { super(message); } } /** * * @param seq * sequence to generate mapping against the structure * @param pdbFile * PDB file for the mapping * @param chain * the chain of the entry to use for mapping * @return StructureMapping * @throws Exception */ public abstract StructureMapping getStructureMapping(SequenceI seq, String pdbFile, String chain) throws Exception, StructureMappingException; /** * * @param mop * MappingOutputPojo * @return Sequence<->Structure mapping as int[][] * @throws StructureMappingException */ public abstract StringBuffer getMappingOutput(MappingOutputModel mp) throws StructureMappingException; }