2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ws.sifts;
23 import jalview.analysis.AlignSeq;
24 import jalview.api.DBRefEntryI;
25 import jalview.api.SiftsClientI;
26 import jalview.datamodel.DBRefEntry;
27 import jalview.datamodel.DBRefSource;
28 import jalview.datamodel.SequenceI;
29 import jalview.io.StructureFile;
30 import jalview.schemes.ResidueProperties;
31 import jalview.structure.StructureMapping;
32 import jalview.util.Format;
33 import jalview.xml.binding.sifts.Entry;
34 import jalview.xml.binding.sifts.Entry.Entity;
35 import jalview.xml.binding.sifts.Entry.Entity.Segment;
36 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListMapRegion.MapRegion;
37 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue;
38 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.CrossRefDb;
39 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.ResidueDetail;
42 import java.io.FileInputStream;
43 import java.io.FileOutputStream;
44 import java.io.IOException;
45 import java.io.InputStream;
46 import java.io.PrintStream;
48 import java.net.URLConnection;
49 import java.nio.file.Files;
50 import java.nio.file.Path;
51 import java.nio.file.attribute.BasicFileAttributes;
52 import java.util.ArrayList;
53 import java.util.Arrays;
54 import java.util.Collection;
55 import java.util.Collections;
56 import java.util.Date;
57 import java.util.HashMap;
58 import java.util.HashSet;
59 import java.util.List;
62 import java.util.TreeMap;
63 import java.util.zip.GZIPInputStream;
65 import javax.xml.bind.JAXBContext;
66 import javax.xml.bind.Unmarshaller;
67 import javax.xml.stream.XMLInputFactory;
68 import javax.xml.stream.XMLStreamReader;
71 import MCview.PDBChain;
73 public class SiftsClient implements SiftsClientI
75 private Entry siftsEntry;
77 private StructureFile pdb;
81 private String structId;
83 private CoordinateSys seqCoordSys = CoordinateSys.UNIPROT;
85 private static final int BUFFER_SIZE = 4096;
87 public static final int UNASSIGNED = -1;
89 private static final int PDB_RES_POS = 0;
91 private static final int PDB_ATOM_POS = 1;
93 private static final String NOT_OBSERVED = "Not_Observed";
95 private static final String SIFTS_FTP_BASE_URL = "http://ftp.ebi.ac.uk/pub/databases/msd/sifts/xml/";
97 private final static String NEWLINE = System.lineSeparator();
99 private String curSourceDBRef;
101 private HashSet<String> curDBRefAccessionIdsString;
103 private enum CoordinateSys
105 UNIPROT("UniProt"), PDB("PDBresnum"), PDBe("PDBe");
108 private CoordinateSys(String name)
113 public String getName()
119 private enum ResidueDetailType
121 NAME_SEC_STRUCTURE("nameSecondaryStructure"), CODE_SEC_STRUCTURE(
122 "codeSecondaryStructure"), ANNOTATION("Annotation");
125 private ResidueDetailType(String code)
130 public String getCode()
137 * Fetch SIFTs file for the given PDBfile and construct an instance of
141 * @throws SiftsException
143 public SiftsClient(StructureFile pdb) throws SiftsException
146 this.pdbId = pdb.getId();
147 File siftsFile = getSiftsFile(pdbId);
148 siftsEntry = parseSIFTs(siftsFile);
153 * Parse the given SIFTs File and return a JAXB POJO of parsed data
156 * - the GZipped SIFTs XML file to parse
159 * if a problem occurs while parsing the SIFTs XML
161 private Entry parseSIFTs(File siftFile) throws SiftsException
163 try (InputStream in = new FileInputStream(siftFile);
164 GZIPInputStream gzis = new GZIPInputStream(in);)
166 // System.out.println("File : " + siftFile.getAbsolutePath());
167 JAXBContext jc = JAXBContext.newInstance("jalview.xml.binding.sifts");
168 XMLStreamReader streamReader = XMLInputFactory.newInstance()
169 .createXMLStreamReader(gzis);
170 Unmarshaller um = jc.createUnmarshaller();
171 return (Entry) um.unmarshal(streamReader);
172 } catch (Exception e)
175 throw new SiftsException(e.getMessage());
180 * Get a SIFTs XML file for a given PDB Id from Cache or download from FTP
181 * repository if not found in cache
184 * @return SIFTs XML file
185 * @throws SiftsException
187 public static File getSiftsFile(String pdbId) throws SiftsException
189 String siftsFileName = SiftsSettings.getSiftDownloadDirectory()
190 + pdbId.toLowerCase() + ".xml.gz";
191 File siftsFile = new File(siftsFileName);
192 if (siftsFile.exists())
194 // The line below is required for unit testing... don't comment it out!!!
195 System.out.println(">>> SIFTS File already downloaded for " + pdbId);
197 if (isFileOlderThanThreshold(siftsFile,
198 SiftsSettings.getCacheThresholdInDays()))
200 File oldSiftsFile = new File(siftsFileName + "_old");
201 siftsFile.renameTo(oldSiftsFile);
204 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
205 oldSiftsFile.delete();
207 } catch (IOException e)
210 oldSiftsFile.renameTo(siftsFile);
211 return new File(siftsFileName);
217 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
218 } catch (IOException e)
220 throw new SiftsException(e.getMessage());
226 * This method enables checking if a cached file has exceeded a certain
232 * the threshold in days
235 public static boolean isFileOlderThanThreshold(File file, int noOfDays)
237 Path filePath = file.toPath();
238 BasicFileAttributes attr;
242 attr = Files.readAttributes(filePath, BasicFileAttributes.class);
243 diffInDays = (int) ((new Date().getTime() - attr.lastModifiedTime()
244 .toMillis()) / (1000 * 60 * 60 * 24));
245 // System.out.println("Diff in days : " + diffInDays);
246 } catch (IOException e)
250 return noOfDays <= diffInDays;
254 * Download a SIFTs XML file for a given PDB Id from an FTP repository
257 * @return downloaded SIFTs XML file
258 * @throws SiftsException
259 * @throws IOException
261 public static File downloadSiftsFile(String pdbId) throws SiftsException,
264 if (pdbId.contains(".cif"))
266 pdbId = pdbId.replace(".cif", "");
268 String siftFile = pdbId + ".xml.gz";
269 String siftsFileFTPURL = SIFTS_FTP_BASE_URL + siftFile;
270 String downloadedSiftsFile = SiftsSettings.getSiftDownloadDirectory()
272 File siftsDownloadDir = new File(
273 SiftsSettings.getSiftDownloadDirectory());
274 if (!siftsDownloadDir.exists())
276 siftsDownloadDir.mkdirs();
278 // System.out.println(">> Download ftp url : " + siftsFileFTPURL);
279 URL url = new URL(siftsFileFTPURL);
280 URLConnection conn = url.openConnection();
281 InputStream inputStream = conn.getInputStream();
282 FileOutputStream outputStream = new FileOutputStream(
283 downloadedSiftsFile);
284 byte[] buffer = new byte[BUFFER_SIZE];
286 while ((bytesRead = inputStream.read(buffer)) != -1)
288 outputStream.write(buffer, 0, bytesRead);
290 outputStream.close();
292 // System.out.println(">>> File downloaded : " + downloadedSiftsFile);
293 return new File(downloadedSiftsFile);
297 * Delete the SIFTs file for the given PDB Id in the local SIFTs download
301 * @return true if the file was deleted or doesn't exist
303 public static boolean deleteSiftsFileByPDBId(String pdbId)
305 File siftsFile = new File(SiftsSettings.getSiftDownloadDirectory()
306 + pdbId.toLowerCase() + ".xml.gz");
307 if (siftsFile.exists())
309 return siftsFile.delete();
315 * Get a valid SIFTs DBRef for the given sequence current SIFTs entry
318 * - the target sequence for the operation
319 * @return a valid DBRefEntry that is SIFTs compatible
321 * if no valid source DBRefEntry was found for the given sequences
323 public DBRefEntryI getValidSourceDBRef(SequenceI seq)
324 throws SiftsException
326 DBRefEntryI sourceDBRef = null;
327 sourceDBRef = seq.getSourceDBRef();
328 if (sourceDBRef != null && isValidDBRefEntry(sourceDBRef))
334 DBRefEntry[] dbRefs = seq.getDBRefs();
335 if (dbRefs == null || dbRefs.length < 1)
337 throw new SiftsException(
338 "Source DBRef could not be determined. DBRefs might not have been retrieved.");
341 for (DBRefEntryI dbRef : dbRefs)
343 if (dbRef == null || dbRef.getAccessionId() == null
344 || dbRef.getSource() == null)
348 if (isFoundInSiftsEntry(dbRef.getAccessionId())
349 && (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT) || dbRef
350 .getSource().equalsIgnoreCase(DBRefSource.PDB)))
352 seq.setSourceDBRef(dbRef);
357 if (sourceDBRef != null && isValidDBRefEntry(sourceDBRef))
361 throw new SiftsException("Could not get source DB Ref");
365 * Check that the DBRef Entry is properly populated and is available in this
366 * SiftClient instance
369 * - DBRefEntry to validate
370 * @return true validation is successful otherwise false is returned.
372 boolean isValidDBRefEntry(DBRefEntryI entry)
374 return entry != null && entry.getAccessionId() != null
375 && isFoundInSiftsEntry(entry.getAccessionId());
379 public HashSet<String> getAllMappingAccession()
381 HashSet<String> accessions = new HashSet<String>();
382 List<Entity> entities = siftsEntry.getEntity();
383 for (Entity entity : entities)
385 List<Segment> segments = entity.getSegment();
386 for (Segment segment : segments)
388 List<MapRegion> mapRegions = segment.getListMapRegion()
390 for (MapRegion mapRegion : mapRegions)
393 .add(mapRegion.getDb().getDbAccessionId().toLowerCase());
401 public StructureMapping getSiftsStructureMapping(SequenceI seq,
402 String pdbFile, String chain) throws SiftsException
404 structId = (chain == null) ? pdbId : pdbId + "|" + chain;
405 System.out.println("Getting mapping for: " + pdbId + "|" + chain
406 + " : seq- " + seq.getName());
408 final StringBuilder mappingDetails = new StringBuilder(128);
409 PrintStream ps = new PrintStream(System.out)
412 public void print(String x)
414 mappingDetails.append(x);
418 public void println()
420 mappingDetails.append(NEWLINE);
423 HashMap<Integer, int[]> mapping = getGreedyMapping(chain, seq, ps);
425 String mappingOutput = mappingDetails.toString();
426 StructureMapping siftsMapping = new StructureMapping(seq, pdbFile,
427 pdbId, chain, mapping, mappingOutput);
432 public HashMap<Integer, int[]> getGreedyMapping(String entityId,
433 SequenceI seq, java.io.PrintStream os) throws SiftsException
435 List<Integer> omitNonObserved = new ArrayList<Integer>();
436 int nonObservedShiftIndex = 0;
437 // System.out.println("Generating mappings for : " + entityId);
438 Entity entity = null;
439 entity = getEntityById(entityId);
440 String originalSeq = AlignSeq.extractGaps(
441 jalview.util.Comparison.GapChars, seq.getSequenceAsString());
442 HashMap<Integer, int[]> mapping = new HashMap<Integer, int[]>();
443 DBRefEntryI sourceDBRef = seq.getSourceDBRef();
444 sourceDBRef = getValidSourceDBRef(seq);
445 // TODO ensure sequence start/end is in the same coordinate system and
446 // consistent with the choosen sourceDBRef
448 // set sequence coordinate system - default value is UniProt
449 if (sourceDBRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
451 seqCoordSys = CoordinateSys.PDB;
454 HashSet<String> dbRefAccessionIdsString = new HashSet<String>();
455 for (DBRefEntry dbref : seq.getDBRefs())
457 dbRefAccessionIdsString.add(dbref.getAccessionId().toLowerCase());
459 dbRefAccessionIdsString.add(sourceDBRef.getAccessionId().toLowerCase());
461 curDBRefAccessionIdsString = dbRefAccessionIdsString;
462 curSourceDBRef = sourceDBRef.getAccessionId();
464 TreeMap<Integer, String> resNumMap = new TreeMap<Integer, String>();
465 List<Segment> segments = entity.getSegment();
466 SegmentHelperPojo shp = new SegmentHelperPojo(seq, mapping, resNumMap,
467 omitNonObserved, nonObservedShiftIndex);
468 processSegments(segments, shp);
471 populateAtomPositions(entityId, mapping);
472 } catch (Exception e)
476 if (seqCoordSys == CoordinateSys.UNIPROT)
478 padWithGaps(resNumMap, omitNonObserved);
480 int seqStart = UNASSIGNED;
481 int seqEnd = UNASSIGNED;
482 int pdbStart = UNASSIGNED;
483 int pdbEnd = UNASSIGNED;
485 Integer[] keys = mapping.keySet().toArray(new Integer[0]);
489 throw new SiftsException(">>> Empty SIFTS mapping generated!!");
492 seqEnd = keys[keys.length - 1];
494 String matchedSeq = originalSeq;
495 if (seqStart != UNASSIGNED)
497 pdbStart = mapping.get(seqStart)[PDB_RES_POS];
498 pdbEnd = mapping.get(seqEnd)[PDB_RES_POS];
499 int orignalSeqStart = seq.getStart();
500 if (orignalSeqStart >= 1)
502 int subSeqStart = (seqStart >= orignalSeqStart) ? seqStart
503 - orignalSeqStart : 0;
504 int subSeqEnd = seqEnd - (orignalSeqStart - 1);
505 subSeqEnd = originalSeq.length() < subSeqEnd ? originalSeq.length()
507 matchedSeq = originalSeq.substring(subSeqStart, subSeqEnd);
511 matchedSeq = originalSeq.substring(1, originalSeq.length());
515 StringBuilder targetStrucSeqs = new StringBuilder();
516 for (String res : resNumMap.values())
518 targetStrucSeqs.append(res);
523 MappingOutputPojo mop = new MappingOutputPojo();
524 mop.setSeqStart(pdbStart);
525 mop.setSeqEnd(pdbEnd);
526 mop.setSeqName(seq.getName());
527 mop.setSeqResidue(matchedSeq);
529 mop.setStrStart(seqStart);
530 mop.setStrEnd(seqEnd);
531 mop.setStrName(structId);
532 mop.setStrResidue(targetStrucSeqs.toString());
535 os.print(getMappingOutput(mop).toString());
541 void processSegments(List<Segment> segments, SegmentHelperPojo shp)
543 SequenceI seq = shp.getSeq();
544 HashMap<Integer, int[]> mapping = shp.getMapping();
545 TreeMap<Integer, String> resNumMap = shp.getResNumMap();
546 List<Integer> omitNonObserved = shp.getOmitNonObserved();
547 int nonObservedShiftIndex = shp.getNonObservedShiftIndex();
548 for (Segment segment : segments)
550 // System.out.println("Mapping segments : " + segment.getSegId() + "\\"s
552 List<Residue> residues = segment.getListResidue().getResidue();
553 for (Residue residue : residues)
555 int currSeqIndex = UNASSIGNED;
556 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
557 CrossRefDb pdbRefDb = null;
558 for (CrossRefDb cRefDb : cRefDbs)
560 if (cRefDb.getDbSource().equalsIgnoreCase(DBRefSource.PDB))
564 if (cRefDb.getDbCoordSys()
565 .equalsIgnoreCase(seqCoordSys.getName())
566 && isAccessionMatched(cRefDb.getDbAccessionId()))
568 String resNumIndexString = cRefDb.getDbResNum()
569 .equalsIgnoreCase("None") ? String.valueOf(UNASSIGNED)
570 : cRefDb.getDbResNum();
573 currSeqIndex = Integer.valueOf(resNumIndexString);
574 } catch (NumberFormatException nfe)
576 currSeqIndex = Integer.valueOf(resNumIndexString
577 .split("[a-zA-Z]")[0]);
580 if (pdbRefDb != null)
582 break;// exit loop if pdb and uniprot are already found
586 if (currSeqIndex == UNASSIGNED)
590 if (currSeqIndex >= seq.getStart() && currSeqIndex <= seq.getEnd())
595 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
596 .getDbResNum()) : Integer.valueOf(pdbRefDb
598 } catch (NumberFormatException nfe)
600 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
601 .getDbResNum()) : Integer.valueOf(pdbRefDb
602 .getDbResNum().split("[a-zA-Z]")[0]);
606 if (isResidueObserved(residue)
607 || seqCoordSys == CoordinateSys.UNIPROT)
609 char resCharCode = ResidueProperties
610 .getSingleCharacterCode(ResidueProperties
611 .getCanonicalAminoAcid(residue.getDbResName()));
612 resNumMap.put(currSeqIndex, String.valueOf(resCharCode));
616 omitNonObserved.add(currSeqIndex);
617 ++nonObservedShiftIndex;
619 mapping.put(currSeqIndex - nonObservedShiftIndex, new int[] {
620 Integer.valueOf(resNum), UNASSIGNED });
628 * Target chain to populate mapping of its atom positions.
630 * Two dimension array of residue index versus atom position
631 * @throws IllegalArgumentException
632 * Thrown if chainId or mapping is null
633 * @throws SiftsException
635 void populateAtomPositions(String chainId, Map<Integer, int[]> mapping)
636 throws IllegalArgumentException, SiftsException
640 PDBChain chain = pdb.findChain(chainId);
642 if (chain == null || mapping == null)
644 throw new IllegalArgumentException(
645 "Chain id or mapping must not be null.");
647 for (int[] map : mapping.values())
649 if (map[PDB_RES_POS] != UNASSIGNED)
651 map[PDB_ATOM_POS] = getAtomIndex(map[PDB_RES_POS], chain.atoms);
654 } catch (NullPointerException e)
656 throw new SiftsException(e.getMessage());
657 } catch (Exception e)
659 throw new SiftsException(e.getMessage());
665 * @param residueIndex
666 * The residue index used for the search
668 * A collection of Atom to search
669 * @return atom position for the given residue index
671 int getAtomIndex(int residueIndex, Collection<Atom> atoms)
675 throw new IllegalArgumentException(
676 "atoms collection must not be null!");
678 for (Atom atom : atoms)
680 if (atom.resNumber == residueIndex)
682 return atom.atomIndex;
689 * Checks if the residue instance is marked 'Not_observed' or not
694 private boolean isResidueObserved(Residue residue)
696 Set<String> annotations = getResidueAnnotaitons(residue,
697 ResidueDetailType.ANNOTATION);
698 if (annotations == null || annotations.isEmpty())
702 for (String annotation : annotations)
704 if (annotation.equalsIgnoreCase(NOT_OBSERVED))
713 * Get annotation String for a given residue and annotation type
719 private Set<String> getResidueAnnotaitons(Residue residue,
720 ResidueDetailType type)
722 HashSet<String> foundAnnotations = new HashSet<String>();
723 List<ResidueDetail> resDetails = residue.getResidueDetail();
724 for (ResidueDetail resDetail : resDetails)
726 if (resDetail.getProperty().equalsIgnoreCase(type.getCode()))
728 foundAnnotations.add(resDetail.getContent());
731 return foundAnnotations;
735 public boolean isAccessionMatched(String accession)
737 boolean isStrictMatch = true;
738 return isStrictMatch ? curSourceDBRef.equalsIgnoreCase(accession)
739 : curDBRefAccessionIdsString.contains(accession.toLowerCase());
742 private boolean isFoundInSiftsEntry(String accessionId)
744 Set<String> siftsDBRefs = getAllMappingAccession();
745 return accessionId != null
746 && siftsDBRefs.contains(accessionId.toLowerCase());
750 * Pad omitted residue positions in PDB sequence with gaps
754 void padWithGaps(Map<Integer, String> resNumMap,
755 List<Integer> omitNonObserved)
757 if (resNumMap == null || resNumMap.isEmpty())
761 Integer[] keys = resNumMap.keySet().toArray(new Integer[0]);
762 // Arrays.sort(keys);
763 int firstIndex = keys[0];
764 int lastIndex = keys[keys.length - 1];
765 // System.out.println("Min value " + firstIndex);
766 // System.out.println("Max value " + lastIndex);
767 for (int x = firstIndex; x <= lastIndex; x++)
769 if (!resNumMap.containsKey(x) && !omitNonObserved.contains(x))
771 resNumMap.put(x, "-");
779 public Entity getEntityById(String id) throws SiftsException
781 // Determines an entity to process by performing a heuristic matching of all
782 // Entities with the given chainId and choosing the best matching Entity
783 Entity entity = getEntityByMostOptimalMatchedId(id);
788 throw new SiftsException("Entity " + id + " not found");
792 * This method was added because EntityId is NOT always equal to ChainId.
793 * Hence, it provides the logic to greedily detect the "true" Entity for a
794 * given chainId where discrepancies exist.
799 public Entity getEntityByMostOptimalMatchedId(String chainId)
801 // System.out.println("---> advanced greedy entityId matching block entered..");
802 List<Entity> entities = siftsEntry.getEntity();
803 SiftsEntitySortPojo[] sPojo = new SiftsEntitySortPojo[entities.size()];
805 for (Entity entity : entities)
807 sPojo[count] = new SiftsEntitySortPojo();
808 sPojo[count].entityId = entity.getEntityId();
810 List<Segment> segments = entity.getSegment();
811 for (Segment segment : segments)
813 List<Residue> residues = segment.getListResidue().getResidue();
814 for (Residue residue : residues)
816 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
817 for (CrossRefDb cRefDb : cRefDbs)
819 if (!cRefDb.getDbSource().equalsIgnoreCase("PDB"))
823 ++sPojo[count].resCount;
824 if (cRefDb.getDbChainId().equalsIgnoreCase(chainId))
826 ++sPojo[count].chainIdFreq;
831 sPojo[count].pid = (100 * sPojo[count].chainIdFreq)
832 / sPojo[count].resCount;
835 Arrays.sort(sPojo, Collections.reverseOrder());
836 // System.out.println("highest matched entity : " + sPojo[0].entityId);
837 // System.out.println("highest matched pid : " + sPojo[0].pid);
839 if (sPojo[0].entityId != null)
841 for (Entity entity : entities)
843 if (!entity.getEntityId().equalsIgnoreCase(sPojo[0].entityId))
853 private class SiftsEntitySortPojo implements
854 Comparable<SiftsEntitySortPojo>
856 public String entityId;
858 public int chainIdFreq;
865 public int compareTo(SiftsEntitySortPojo o)
867 return this.pid - o.pid;
871 private class SegmentHelperPojo
873 private SequenceI seq;
875 private HashMap<Integer, int[]> mapping;
877 private TreeMap<Integer, String> resNumMap;
879 private List<Integer> omitNonObserved;
881 private int nonObservedShiftIndex;
883 public SegmentHelperPojo(SequenceI seq,
884 HashMap<Integer, int[]> mapping,
885 TreeMap<Integer, String> resNumMap,
886 List<Integer> omitNonObserved, int nonObservedShiftIndex)
890 setResNumMap(resNumMap);
891 setOmitNonObserved(omitNonObserved);
892 setNonObservedShiftIndex(nonObservedShiftIndex);
895 public SequenceI getSeq()
900 public void setSeq(SequenceI seq)
905 public HashMap<Integer, int[]> getMapping()
910 public void setMapping(HashMap<Integer, int[]> mapping)
912 this.mapping = mapping;
915 public TreeMap<Integer, String> getResNumMap()
920 public void setResNumMap(TreeMap<Integer, String> resNumMap)
922 this.resNumMap = resNumMap;
925 public List<Integer> getOmitNonObserved()
927 return omitNonObserved;
930 public void setOmitNonObserved(List<Integer> omitNonObserved)
932 this.omitNonObserved = omitNonObserved;
935 public int getNonObservedShiftIndex()
937 return nonObservedShiftIndex;
940 public void setNonObservedShiftIndex(int nonObservedShiftIndex)
942 this.nonObservedShiftIndex = nonObservedShiftIndex;
947 public StringBuffer getMappingOutput(MappingOutputPojo mp)
948 throws SiftsException
950 String seqRes = mp.getSeqResidue();
951 String seqName = mp.getSeqName();
952 int sStart = mp.getSeqStart();
953 int sEnd = mp.getSeqEnd();
955 String strRes = mp.getStrResidue();
956 String strName = mp.getStrName();
957 int pdbStart = mp.getStrStart();
958 int pdbEnd = mp.getStrEnd();
960 String type = mp.getType();
962 int maxid = (seqName.length() >= strName.length()) ? seqName.length()
964 int len = 72 - maxid - 1;
966 int nochunks = ((seqRes.length()) / len)
967 + ((seqRes.length()) % len > 0 ? 1 : 0);
969 StringBuffer output = new StringBuffer();
970 output.append(NEWLINE);
971 output.append("Sequence \u27f7 Structure mapping details").append(
973 output.append("Method: SIFTS");
974 output.append(NEWLINE).append(NEWLINE);
976 output.append(new Format("%" + maxid + "s").form(seqName));
977 output.append(" : ");
978 output.append(String.valueOf(sStart));
979 output.append(" - ");
980 output.append(String.valueOf(sEnd));
981 output.append(" Maps to ");
982 output.append(NEWLINE);
983 output.append(new Format("%" + maxid + "s").form(structId));
984 output.append(" : ");
985 output.append(String.valueOf(pdbStart));
986 output.append(" - ");
987 output.append(String.valueOf(pdbEnd));
988 output.append(NEWLINE).append(NEWLINE);
990 int matchedSeqCount = 0;
991 for (int j = 0; j < nochunks; j++)
993 // Print the first aligned sequence
994 output.append(new Format("%" + (maxid) + "s").form(seqName)).append(
997 for (int i = 0; i < len; i++)
999 if ((i + (j * len)) < seqRes.length())
1001 output.append(seqRes.charAt(i + (j * len)));
1005 output.append(NEWLINE);
1006 output.append(new Format("%" + (maxid) + "s").form(" ")).append(" ");
1008 // Print out the matching chars
1009 for (int i = 0; i < len; i++)
1013 if ((i + (j * len)) < seqRes.length())
1015 if (seqRes.charAt(i + (j * len)) == strRes
1016 .charAt(i + (j * len))
1017 && !jalview.util.Comparison.isGap(seqRes.charAt(i
1023 else if (type.equals("pep"))
1025 if (ResidueProperties.getPAM250(seqRes.charAt(i + (j * len)),
1026 strRes.charAt(i + (j * len))) > 0)
1040 } catch (IndexOutOfBoundsException e)
1045 // Now print the second aligned sequence
1046 output = output.append(NEWLINE);
1047 output = output.append(new Format("%" + (maxid) + "s").form(strName))
1049 for (int i = 0; i < len; i++)
1051 if ((i + (j * len)) < strRes.length())
1053 output.append(strRes.charAt(i + (j * len)));
1056 output.append(NEWLINE).append(NEWLINE);
1058 float pid = (float) matchedSeqCount / seqRes.length() * 100;
1059 if (pid < SiftsSettings.getFailSafePIDThreshold())
1061 throw new SiftsException(">>> Low PID detected for SIFTs mapping...");
1063 output.append("Length of alignment = " + seqRes.length()).append(
1065 output.append(new Format("Percentage ID = %2.2f").form(pid));
1070 public int getEntityCount()
1072 return siftsEntry.getEntity().size();
1076 public String getDbAccessionId()
1078 return siftsEntry.getDbAccessionId();
1082 public String getDbCoordSys()
1084 return siftsEntry.getDbCoordSys();
1088 public String getDbSource()
1090 return siftsEntry.getDbSource();
1094 public String getDbVersion()
1096 return siftsEntry.getDbVersion();