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.Comparison;
33 import jalview.util.DBRefUtils;
34 import jalview.util.Format;
35 import jalview.xml.binding.sifts.Entry;
36 import jalview.xml.binding.sifts.Entry.Entity;
37 import jalview.xml.binding.sifts.Entry.Entity.Segment;
38 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListMapRegion.MapRegion;
39 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue;
40 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.CrossRefDb;
41 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.ResidueDetail;
44 import java.io.FileInputStream;
45 import java.io.FileOutputStream;
46 import java.io.IOException;
47 import java.io.InputStream;
48 import java.io.PrintStream;
50 import java.net.URLConnection;
51 import java.nio.file.Files;
52 import java.nio.file.Path;
53 import java.nio.file.attribute.BasicFileAttributes;
54 import java.util.ArrayList;
55 import java.util.Arrays;
56 import java.util.Collection;
57 import java.util.Collections;
58 import java.util.Date;
59 import java.util.HashMap;
60 import java.util.HashSet;
61 import java.util.List;
64 import java.util.TreeMap;
65 import java.util.zip.GZIPInputStream;
67 import javax.xml.bind.JAXBContext;
68 import javax.xml.bind.Unmarshaller;
69 import javax.xml.stream.XMLInputFactory;
70 import javax.xml.stream.XMLStreamReader;
73 import MCview.PDBChain;
75 public class SiftsClient implements SiftsClientI
77 private Entry siftsEntry;
79 private StructureFile pdb;
83 private String structId;
85 private CoordinateSys seqCoordSys = CoordinateSys.UNIPROT;
87 private static final int BUFFER_SIZE = 4096;
89 public static final int UNASSIGNED = -1;
91 private static final int PDB_RES_POS = 0;
93 private static final int PDB_ATOM_POS = 1;
95 private static final String NOT_OBSERVED = "Not_Observed";
97 private static final String SIFTS_FTP_BASE_URL = "http://ftp.ebi.ac.uk/pub/databases/msd/sifts/xml/";
99 private final static String NEWLINE = System.lineSeparator();
101 private String curSourceDBRef;
103 private HashSet<String> curDBRefAccessionIdsString;
105 private enum CoordinateSys
107 UNIPROT("UniProt"), PDB("PDBresnum"), PDBe("PDBe");
110 private CoordinateSys(String name)
115 public String getName()
121 private enum ResidueDetailType
123 NAME_SEC_STRUCTURE("nameSecondaryStructure"), CODE_SEC_STRUCTURE(
124 "codeSecondaryStructure"), ANNOTATION("Annotation");
127 private ResidueDetailType(String code)
132 public String getCode()
139 * Fetch SIFTs file for the given PDBfile and construct an instance of
143 * @throws SiftsException
145 public SiftsClient(StructureFile pdb) throws SiftsException
148 this.pdbId = pdb.getId();
149 File siftsFile = getSiftsFile(pdbId);
150 siftsEntry = parseSIFTs(siftsFile);
154 * Parse the given SIFTs File and return a JAXB POJO of parsed data
157 * - the GZipped SIFTs XML file to parse
160 * if a problem occurs while parsing the SIFTs XML
162 private Entry parseSIFTs(File siftFile) throws SiftsException
164 try (InputStream in = new FileInputStream(siftFile);
165 GZIPInputStream gzis = new GZIPInputStream(in);)
167 // System.out.println("File : " + siftFile.getAbsolutePath());
168 JAXBContext jc = JAXBContext.newInstance("jalview.xml.binding.sifts");
169 XMLStreamReader streamReader = XMLInputFactory.newInstance()
170 .createXMLStreamReader(gzis);
171 Unmarshaller um = jc.createUnmarshaller();
172 return (Entry) um.unmarshal(streamReader);
173 } catch (Exception e)
176 throw new SiftsException(e.getMessage());
181 * Get a SIFTs XML file for a given PDB Id from Cache or download from FTP
182 * repository if not found in cache
185 * @return SIFTs XML file
186 * @throws SiftsException
188 public static File getSiftsFile(String pdbId) throws SiftsException
190 String siftsFileName = SiftsSettings.getSiftDownloadDirectory()
191 + pdbId.toLowerCase() + ".xml.gz";
192 File siftsFile = new File(siftsFileName);
193 if (siftsFile.exists())
195 // The line below is required for unit testing... don't comment it out!!!
196 System.out.println(">>> SIFTS File already downloaded for " + pdbId);
198 if (isFileOlderThanThreshold(siftsFile,
199 SiftsSettings.getCacheThresholdInDays()))
201 File oldSiftsFile = new File(siftsFileName + "_old");
202 siftsFile.renameTo(oldSiftsFile);
205 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
206 oldSiftsFile.delete();
208 } catch (IOException e)
211 oldSiftsFile.renameTo(siftsFile);
212 return new File(siftsFileName);
222 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
223 } catch (IOException e)
225 throw new SiftsException(e.getMessage());
231 * This method enables checking if a cached file has exceeded a certain
237 * the threshold in days
240 public static boolean isFileOlderThanThreshold(File file, int noOfDays)
242 Path filePath = file.toPath();
243 BasicFileAttributes attr;
247 attr = Files.readAttributes(filePath, BasicFileAttributes.class);
248 diffInDays = (int) ((new Date().getTime() - attr.lastModifiedTime()
249 .toMillis()) / (1000 * 60 * 60 * 24));
250 // System.out.println("Diff in days : " + diffInDays);
251 } catch (IOException e)
255 return noOfDays <= diffInDays;
259 * Download a SIFTs XML file for a given PDB Id from an FTP repository
262 * @return downloaded SIFTs XML file
263 * @throws SiftsException
264 * @throws IOException
266 public static File downloadSiftsFile(String pdbId) throws SiftsException,
269 if (pdbId.contains(".cif"))
271 pdbId = pdbId.replace(".cif", "");
273 String siftFile = pdbId + ".xml.gz";
274 String siftsFileFTPURL = SIFTS_FTP_BASE_URL + siftFile;
275 String downloadedSiftsFile = SiftsSettings.getSiftDownloadDirectory()
277 File siftsDownloadDir = new File(
278 SiftsSettings.getSiftDownloadDirectory());
279 if (!siftsDownloadDir.exists())
281 siftsDownloadDir.mkdirs();
283 // System.out.println(">> Download ftp url : " + siftsFileFTPURL);
284 // long now = System.currentTimeMillis();
285 URL url = new URL(siftsFileFTPURL);
286 URLConnection conn = url.openConnection();
287 InputStream inputStream = conn.getInputStream();
288 FileOutputStream outputStream = new FileOutputStream(
289 downloadedSiftsFile);
290 byte[] buffer = new byte[BUFFER_SIZE];
292 while ((bytesRead = inputStream.read(buffer)) != -1)
294 outputStream.write(buffer, 0, bytesRead);
296 outputStream.close();
298 // System.out.println(">>> File downloaded : " + downloadedSiftsFile
299 // + " took " + (System.currentTimeMillis() - now) + "ms");
300 return new File(downloadedSiftsFile);
304 * Delete the SIFTs file for the given PDB Id in the local SIFTs download
308 * @return true if the file was deleted or doesn't exist
310 public static boolean deleteSiftsFileByPDBId(String pdbId)
312 File siftsFile = new File(SiftsSettings.getSiftDownloadDirectory()
313 + pdbId.toLowerCase() + ".xml.gz");
314 if (siftsFile.exists())
316 return siftsFile.delete();
322 * Get a valid SIFTs DBRef for the given sequence current SIFTs entry
325 * - the target sequence for the operation
326 * @return a valid DBRefEntry that is SIFTs compatible
328 * if no valid source DBRefEntry was found for the given sequences
330 public DBRefEntryI getValidSourceDBRef(SequenceI seq)
331 throws SiftsException
333 List<DBRefEntry> dbRefs = seq.getPrimaryDBRefs();
334 if (dbRefs == null || dbRefs.size() < 1)
336 throw new SiftsException(
337 "Source DBRef could not be determined. DBRefs might not have been retrieved.");
340 for (DBRefEntry dbRef : dbRefs)
342 if (dbRef == null || dbRef.getAccessionId() == null
343 || dbRef.getSource() == null)
347 String canonicalSource = DBRefUtils.getCanonicalName(dbRef
349 if (isValidDBRefEntry(dbRef)
350 && (canonicalSource.equalsIgnoreCase(DBRefSource.UNIPROT) || canonicalSource
351 .equalsIgnoreCase(DBRefSource.PDB)))
356 throw new SiftsException("Could not get source DB Ref");
360 * Check that the DBRef Entry is properly populated and is available in this
361 * SiftClient instance
364 * - DBRefEntry to validate
365 * @return true validation is successful otherwise false is returned.
367 boolean isValidDBRefEntry(DBRefEntryI entry)
369 return entry != null && entry.getAccessionId() != null
370 && isFoundInSiftsEntry(entry.getAccessionId());
374 public HashSet<String> getAllMappingAccession()
376 HashSet<String> accessions = new HashSet<String>();
377 List<Entity> entities = siftsEntry.getEntity();
378 for (Entity entity : entities)
380 List<Segment> segments = entity.getSegment();
381 for (Segment segment : segments)
383 List<MapRegion> mapRegions = segment.getListMapRegion()
385 for (MapRegion mapRegion : mapRegions)
388 .add(mapRegion.getDb().getDbAccessionId().toLowerCase());
396 public StructureMapping getSiftsStructureMapping(SequenceI seq,
397 String pdbFile, String chain) throws SiftsException
399 structId = (chain == null) ? pdbId : pdbId + "|" + chain;
400 System.out.println("Getting SIFTS mapping for " + structId + ": seq "
403 final StringBuilder mappingDetails = new StringBuilder(128);
404 PrintStream ps = new PrintStream(System.out)
407 public void print(String x)
409 mappingDetails.append(x);
413 public void println()
415 mappingDetails.append(NEWLINE);
418 HashMap<Integer, int[]> mapping = getGreedyMapping(chain, seq, ps);
420 String mappingOutput = mappingDetails.toString();
421 StructureMapping siftsMapping = new StructureMapping(seq, pdbFile,
422 pdbId, chain, mapping, mappingOutput);
427 public HashMap<Integer, int[]> getGreedyMapping(String entityId,
428 SequenceI seq, java.io.PrintStream os) throws SiftsException
430 List<Integer> omitNonObserved = new ArrayList<Integer>();
431 int nonObservedShiftIndex = 0;
432 // System.out.println("Generating mappings for : " + entityId);
433 Entity entity = null;
434 entity = getEntityById(entityId);
435 String originalSeq = AlignSeq.extractGaps(
436 jalview.util.Comparison.GapChars, seq.getSequenceAsString());
437 HashMap<Integer, int[]> mapping = new HashMap<Integer, int[]>();
438 DBRefEntryI sourceDBRef;
439 sourceDBRef = getValidSourceDBRef(seq);
440 // TODO ensure sequence start/end is in the same coordinate system and
441 // consistent with the choosen sourceDBRef
443 // set sequence coordinate system - default value is UniProt
444 if (sourceDBRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
446 seqCoordSys = CoordinateSys.PDB;
449 HashSet<String> dbRefAccessionIdsString = new HashSet<String>();
450 for (DBRefEntry dbref : seq.getDBRefs())
452 dbRefAccessionIdsString.add(dbref.getAccessionId().toLowerCase());
454 dbRefAccessionIdsString.add(sourceDBRef.getAccessionId().toLowerCase());
456 curDBRefAccessionIdsString = dbRefAccessionIdsString;
457 curSourceDBRef = sourceDBRef.getAccessionId();
459 TreeMap<Integer, String> resNumMap = new TreeMap<Integer, String>();
460 List<Segment> segments = entity.getSegment();
461 SegmentHelperPojo shp = new SegmentHelperPojo(seq, mapping, resNumMap,
462 omitNonObserved, nonObservedShiftIndex);
463 processSegments(segments, shp);
466 populateAtomPositions(entityId, mapping);
467 } catch (Exception e)
471 if (seqCoordSys == CoordinateSys.UNIPROT)
473 padWithGaps(resNumMap, omitNonObserved);
475 int seqStart = UNASSIGNED;
476 int seqEnd = UNASSIGNED;
477 int pdbStart = UNASSIGNED;
478 int pdbEnd = UNASSIGNED;
480 if (mapping.isEmpty())
482 throw new SiftsException("SIFTS mapping failed");
485 Integer[] keys = mapping.keySet().toArray(new Integer[0]);
488 seqEnd = keys[keys.length - 1];
490 String matchedSeq = originalSeq;
491 if (seqStart != UNASSIGNED)
493 pdbStart = mapping.get(seqStart)[PDB_RES_POS];
494 pdbEnd = mapping.get(seqEnd)[PDB_RES_POS];
495 int orignalSeqStart = seq.getStart();
496 if (orignalSeqStart >= 1)
498 int subSeqStart = (seqStart >= orignalSeqStart) ? seqStart
499 - orignalSeqStart : 0;
500 int subSeqEnd = seqEnd - (orignalSeqStart - 1);
501 subSeqEnd = originalSeq.length() < subSeqEnd ? originalSeq.length()
503 matchedSeq = originalSeq.substring(subSeqStart, subSeqEnd);
507 matchedSeq = originalSeq.substring(1, originalSeq.length());
511 StringBuilder targetStrucSeqs = new StringBuilder();
512 for (String res : resNumMap.values())
514 targetStrucSeqs.append(res);
519 MappingOutputPojo mop = new MappingOutputPojo();
520 mop.setSeqStart(seqStart);
521 mop.setSeqEnd(seqEnd);
522 mop.setSeqName(seq.getName());
523 mop.setSeqResidue(matchedSeq);
525 mop.setStrStart(pdbStart);
526 mop.setStrEnd(pdbEnd);
527 mop.setStrName(structId);
528 mop.setStrResidue(targetStrucSeqs.toString());
531 os.print(getMappingOutput(mop).toString());
537 void processSegments(List<Segment> segments, SegmentHelperPojo shp)
539 SequenceI seq = shp.getSeq();
540 HashMap<Integer, int[]> mapping = shp.getMapping();
541 TreeMap<Integer, String> resNumMap = shp.getResNumMap();
542 List<Integer> omitNonObserved = shp.getOmitNonObserved();
543 int nonObservedShiftIndex = shp.getNonObservedShiftIndex();
544 for (Segment segment : segments)
546 // System.out.println("Mapping segments : " + segment.getSegId() + "\\"s
548 List<Residue> residues = segment.getListResidue().getResidue();
549 for (Residue residue : residues)
551 int currSeqIndex = UNASSIGNED;
552 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
553 CrossRefDb pdbRefDb = null;
554 for (CrossRefDb cRefDb : cRefDbs)
556 if (cRefDb.getDbSource().equalsIgnoreCase(DBRefSource.PDB))
560 if (cRefDb.getDbCoordSys()
561 .equalsIgnoreCase(seqCoordSys.getName())
562 && isAccessionMatched(cRefDb.getDbAccessionId()))
564 String resNumIndexString = cRefDb.getDbResNum()
565 .equalsIgnoreCase("None") ? String.valueOf(UNASSIGNED)
566 : cRefDb.getDbResNum();
569 currSeqIndex = Integer.valueOf(resNumIndexString);
570 } catch (NumberFormatException nfe)
572 currSeqIndex = Integer.valueOf(resNumIndexString
573 .split("[a-zA-Z]")[0]);
576 if (pdbRefDb != null)
578 break;// exit loop if pdb and uniprot are already found
582 if (currSeqIndex == UNASSIGNED)
586 if (currSeqIndex >= seq.getStart() && currSeqIndex <= seq.getEnd())
591 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
592 .getDbResNum()) : Integer.valueOf(pdbRefDb
594 } catch (NumberFormatException nfe)
596 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
597 .getDbResNum()) : Integer.valueOf(pdbRefDb
598 .getDbResNum().split("[a-zA-Z]")[0]);
602 if (isResidueObserved(residue)
603 || seqCoordSys == CoordinateSys.UNIPROT)
605 char resCharCode = ResidueProperties
606 .getSingleCharacterCode(ResidueProperties
607 .getCanonicalAminoAcid(residue.getDbResName()));
608 resNumMap.put(currSeqIndex, String.valueOf(resCharCode));
612 omitNonObserved.add(currSeqIndex);
613 ++nonObservedShiftIndex;
615 mapping.put(currSeqIndex - nonObservedShiftIndex, new int[] {
616 Integer.valueOf(resNum), UNASSIGNED });
625 * Target chain to populate mapping of its atom positions.
627 * Two dimension array of residue index versus atom position
628 * @throws IllegalArgumentException
629 * Thrown if chainId or mapping is null
630 * @throws SiftsException
632 void populateAtomPositions(String chainId, Map<Integer, int[]> mapping)
633 throws IllegalArgumentException, SiftsException
637 PDBChain chain = pdb.findChain(chainId);
639 if (chain == null || mapping == null)
641 throw new IllegalArgumentException(
642 "Chain id or mapping must not be null.");
644 for (int[] map : mapping.values())
646 if (map[PDB_RES_POS] != UNASSIGNED)
648 map[PDB_ATOM_POS] = getAtomIndex(map[PDB_RES_POS], chain.atoms);
651 } catch (NullPointerException e)
653 throw new SiftsException(e.getMessage());
654 } catch (Exception e)
656 throw new SiftsException(e.getMessage());
662 * @param residueIndex
663 * The residue index used for the search
665 * A collection of Atom to search
666 * @return atom position for the given residue index
668 int getAtomIndex(int residueIndex, Collection<Atom> atoms)
672 throw new IllegalArgumentException(
673 "atoms collection must not be null!");
675 for (Atom atom : atoms)
677 if (atom.resNumber == residueIndex)
679 return atom.atomIndex;
686 * Checks if the residue instance is marked 'Not_observed' or not
691 private boolean isResidueObserved(Residue residue)
693 Set<String> annotations = getResidueAnnotaitons(residue,
694 ResidueDetailType.ANNOTATION);
695 if (annotations == null || annotations.isEmpty())
699 for (String annotation : annotations)
701 if (annotation.equalsIgnoreCase(NOT_OBSERVED))
710 * Get annotation String for a given residue and annotation type
716 private Set<String> getResidueAnnotaitons(Residue residue,
717 ResidueDetailType type)
719 HashSet<String> foundAnnotations = new HashSet<String>();
720 List<ResidueDetail> resDetails = residue.getResidueDetail();
721 for (ResidueDetail resDetail : resDetails)
723 if (resDetail.getProperty().equalsIgnoreCase(type.getCode()))
725 foundAnnotations.add(resDetail.getContent());
728 return foundAnnotations;
732 public boolean isAccessionMatched(String accession)
734 boolean isStrictMatch = true;
735 return isStrictMatch ? curSourceDBRef.equalsIgnoreCase(accession)
736 : curDBRefAccessionIdsString.contains(accession.toLowerCase());
739 private boolean isFoundInSiftsEntry(String accessionId)
741 Set<String> siftsDBRefs = getAllMappingAccession();
742 return accessionId != null
743 && siftsDBRefs.contains(accessionId.toLowerCase());
747 * Pad omitted residue positions in PDB sequence with gaps
751 void padWithGaps(Map<Integer, String> resNumMap,
752 List<Integer> omitNonObserved)
754 if (resNumMap == null || resNumMap.isEmpty())
758 Integer[] keys = resNumMap.keySet().toArray(new Integer[0]);
759 // Arrays.sort(keys);
760 int firstIndex = keys[0];
761 int lastIndex = keys[keys.length - 1];
762 // System.out.println("Min value " + firstIndex);
763 // System.out.println("Max value " + lastIndex);
764 for (int x = firstIndex; x <= lastIndex; x++)
766 if (!resNumMap.containsKey(x) && !omitNonObserved.contains(x))
768 resNumMap.put(x, "-");
774 public Entity getEntityById(String id) throws SiftsException
776 // Determines an entity to process by performing a heuristic matching of all
777 // Entities with the given chainId and choosing the best matching Entity
778 Entity entity = getEntityByMostOptimalMatchedId(id);
783 throw new SiftsException("Entity " + id + " not found");
787 * This method was added because EntityId is NOT always equal to ChainId.
788 * Hence, it provides the logic to greedily detect the "true" Entity for a
789 * given chainId where discrepancies exist.
794 public Entity getEntityByMostOptimalMatchedId(String chainId)
796 // System.out.println("---> advanced greedy entityId matching block entered..");
797 List<Entity> entities = siftsEntry.getEntity();
798 SiftsEntitySortPojo[] sPojo = new SiftsEntitySortPojo[entities.size()];
800 for (Entity entity : entities)
802 sPojo[count] = new SiftsEntitySortPojo();
803 sPojo[count].entityId = entity.getEntityId();
805 List<Segment> segments = entity.getSegment();
806 for (Segment segment : segments)
808 List<Residue> residues = segment.getListResidue().getResidue();
809 for (Residue residue : residues)
811 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
812 for (CrossRefDb cRefDb : cRefDbs)
814 if (!cRefDb.getDbSource().equalsIgnoreCase("PDB"))
818 ++sPojo[count].resCount;
819 if (cRefDb.getDbChainId().equalsIgnoreCase(chainId))
821 ++sPojo[count].chainIdFreq;
826 sPojo[count].pid = (100 * sPojo[count].chainIdFreq)
827 / sPojo[count].resCount;
830 Arrays.sort(sPojo, Collections.reverseOrder());
831 // System.out.println("highest matched entity : " + sPojo[0].entityId);
832 // System.out.println("highest matched pid : " + sPojo[0].pid);
834 if (sPojo[0].entityId != null)
836 if (sPojo[0].pid < 1)
840 for (Entity entity : entities)
842 if (!entity.getEntityId().equalsIgnoreCase(sPojo[0].entityId))
852 private class SiftsEntitySortPojo implements
853 Comparable<SiftsEntitySortPojo>
855 public String entityId;
857 public int chainIdFreq;
864 public int compareTo(SiftsEntitySortPojo o)
866 return this.pid - o.pid;
870 private class SegmentHelperPojo
872 private SequenceI seq;
874 private HashMap<Integer, int[]> mapping;
876 private TreeMap<Integer, String> resNumMap;
878 private List<Integer> omitNonObserved;
880 private int nonObservedShiftIndex;
882 public SegmentHelperPojo(SequenceI seq,
883 HashMap<Integer, int[]> mapping,
884 TreeMap<Integer, String> resNumMap,
885 List<Integer> omitNonObserved, int nonObservedShiftIndex)
889 setResNumMap(resNumMap);
890 setOmitNonObserved(omitNonObserved);
891 setNonObservedShiftIndex(nonObservedShiftIndex);
894 public SequenceI getSeq()
899 public void setSeq(SequenceI seq)
904 public HashMap<Integer, int[]> getMapping()
909 public void setMapping(HashMap<Integer, int[]> mapping)
911 this.mapping = mapping;
914 public TreeMap<Integer, String> getResNumMap()
919 public void setResNumMap(TreeMap<Integer, String> resNumMap)
921 this.resNumMap = resNumMap;
924 public List<Integer> getOmitNonObserved()
926 return omitNonObserved;
929 public void setOmitNonObserved(List<Integer> omitNonObserved)
931 this.omitNonObserved = omitNonObserved;
934 public int getNonObservedShiftIndex()
936 return nonObservedShiftIndex;
939 public void setNonObservedShiftIndex(int nonObservedShiftIndex)
941 this.nonObservedShiftIndex = nonObservedShiftIndex;
946 public StringBuffer getMappingOutput(MappingOutputPojo mp)
947 throws SiftsException
949 String seqRes = mp.getSeqResidue();
950 String seqName = mp.getSeqName();
951 int sStart = mp.getSeqStart();
952 int sEnd = mp.getSeqEnd();
954 String strRes = mp.getStrResidue();
955 String strName = mp.getStrName();
956 int pdbStart = mp.getStrStart();
957 int pdbEnd = mp.getStrEnd();
959 String type = mp.getType();
961 int maxid = (seqName.length() >= strName.length()) ? seqName.length()
963 int len = 72 - maxid - 1;
965 int nochunks = ((seqRes.length()) / len)
966 + ((seqRes.length()) % len > 0 ? 1 : 0);
968 StringBuffer output = new StringBuffer();
969 output.append(NEWLINE);
970 output.append("Sequence \u27f7 Structure mapping details").append(
972 output.append("Method: SIFTS");
973 output.append(NEWLINE).append(NEWLINE);
975 output.append(new Format("%" + maxid + "s").form(seqName));
976 output.append(" : ");
977 output.append(String.valueOf(sStart));
978 output.append(" - ");
979 output.append(String.valueOf(sEnd));
980 output.append(" Maps to ");
981 output.append(NEWLINE);
982 output.append(new Format("%" + maxid + "s").form(structId));
983 output.append(" : ");
984 output.append(String.valueOf(pdbStart));
985 output.append(" - ");
986 output.append(String.valueOf(pdbEnd));
987 output.append(NEWLINE).append(NEWLINE);
989 int matchedSeqCount = 0;
990 for (int j = 0; j < nochunks; j++)
992 // Print the first aligned sequence
993 output.append(new Format("%" + (maxid) + "s").form(seqName)).append(
996 for (int i = 0; i < len; i++)
998 if ((i + (j * len)) < seqRes.length())
1000 output.append(seqRes.charAt(i + (j * len)));
1004 output.append(NEWLINE);
1005 output.append(new Format("%" + (maxid) + "s").form(" ")).append(" ");
1007 // Print out the matching chars
1008 for (int i = 0; i < len; i++)
1012 if ((i + (j * len)) < seqRes.length())
1014 boolean sameChar = Comparison.isSameResidue(
1015 seqRes.charAt(i + (j * len)),
1016 strRes.charAt(i + (j * len)), false);
1018 && !jalview.util.Comparison.isGap(seqRes.charAt(i
1024 else if (type.equals("pep"))
1026 if (ResidueProperties.getPAM250(seqRes.charAt(i + (j * len)),
1027 strRes.charAt(i + (j * len))) > 0)
1041 } catch (IndexOutOfBoundsException e)
1046 // Now print the second aligned sequence
1047 output = output.append(NEWLINE);
1048 output = output.append(new Format("%" + (maxid) + "s").form(strName))
1050 for (int i = 0; i < len; i++)
1052 if ((i + (j * len)) < strRes.length())
1054 output.append(strRes.charAt(i + (j * len)));
1057 output.append(NEWLINE).append(NEWLINE);
1059 float pid = (float) matchedSeqCount / seqRes.length() * 100;
1060 if (pid < SiftsSettings.getFailSafePIDThreshold())
1062 throw new SiftsException(">>> Low PID detected for SIFTs mapping...");
1064 output.append("Length of alignment = " + seqRes.length()).append(
1066 output.append(new Format("Percentage ID = %2.2f").form(pid));
1071 public int getEntityCount()
1073 return siftsEntry.getEntity().size();
1077 public String getDbAccessionId()
1079 return siftsEntry.getDbAccessionId();
1083 public String getDbCoordSys()
1085 return siftsEntry.getDbCoordSys();
1089 public String getDbSource()
1091 return siftsEntry.getDbSource();
1095 public String getDbVersion()
1097 return siftsEntry.getDbVersion();