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.analysis.scoremodels.ScoreMatrix;
25 import jalview.analysis.scoremodels.ScoreModels;
26 import jalview.api.DBRefEntryI;
27 import jalview.api.SiftsClientI;
28 import jalview.datamodel.DBRefEntry;
29 import jalview.datamodel.DBRefSource;
30 import jalview.datamodel.SequenceI;
31 import jalview.io.StructureFile;
32 import jalview.schemes.ResidueProperties;
33 import jalview.structure.StructureMapping;
34 import jalview.util.Comparison;
35 import jalview.util.DBRefUtils;
36 import jalview.util.Format;
37 import jalview.xml.binding.sifts.Entry;
38 import jalview.xml.binding.sifts.Entry.Entity;
39 import jalview.xml.binding.sifts.Entry.Entity.Segment;
40 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListMapRegion.MapRegion;
41 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue;
42 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.CrossRefDb;
43 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.ResidueDetail;
46 import java.io.FileInputStream;
47 import java.io.FileOutputStream;
48 import java.io.IOException;
49 import java.io.InputStream;
50 import java.io.PrintStream;
52 import java.net.URLConnection;
53 import java.nio.file.Files;
54 import java.nio.file.Path;
55 import java.nio.file.attribute.BasicFileAttributes;
56 import java.util.ArrayList;
57 import java.util.Arrays;
58 import java.util.Collection;
59 import java.util.Collections;
60 import java.util.Date;
61 import java.util.HashMap;
62 import java.util.HashSet;
63 import java.util.List;
66 import java.util.TreeMap;
67 import java.util.zip.GZIPInputStream;
69 import javax.xml.bind.JAXBContext;
70 import javax.xml.bind.Unmarshaller;
71 import javax.xml.stream.XMLInputFactory;
72 import javax.xml.stream.XMLStreamReader;
75 import MCview.PDBChain;
77 public class SiftsClient implements SiftsClientI
79 private Entry siftsEntry;
81 private StructureFile pdb;
85 private String structId;
87 private CoordinateSys seqCoordSys = CoordinateSys.UNIPROT;
89 private static final int BUFFER_SIZE = 4096;
91 public static final int UNASSIGNED = -1;
93 private static final int PDB_RES_POS = 0;
95 private static final int PDB_ATOM_POS = 1;
97 private static final String NOT_OBSERVED = "Not_Observed";
99 private static final String SIFTS_FTP_BASE_URL = "http://ftp.ebi.ac.uk/pub/databases/msd/sifts/xml/";
101 private final static String NEWLINE = System.lineSeparator();
103 private String curSourceDBRef;
105 private HashSet<String> curDBRefAccessionIdsString;
107 private enum CoordinateSys
109 UNIPROT("UniProt"), PDB("PDBresnum"), PDBe("PDBe");
112 private CoordinateSys(String name)
117 public String getName()
123 private enum ResidueDetailType
125 NAME_SEC_STRUCTURE("nameSecondaryStructure"), CODE_SEC_STRUCTURE(
126 "codeSecondaryStructure"), ANNOTATION("Annotation");
129 private ResidueDetailType(String code)
134 public String getCode()
141 * Fetch SIFTs file for the given PDBfile and construct an instance of
145 * @throws SiftsException
147 public SiftsClient(StructureFile pdb) throws SiftsException
150 this.pdbId = pdb.getId();
151 File siftsFile = getSiftsFile(pdbId);
152 siftsEntry = parseSIFTs(siftsFile);
156 * Parse the given SIFTs File and return a JAXB POJO of parsed data
159 * - the GZipped SIFTs XML file to parse
162 * if a problem occurs while parsing the SIFTs XML
164 private Entry parseSIFTs(File siftFile) throws SiftsException
166 try (InputStream in = new FileInputStream(siftFile);
167 GZIPInputStream gzis = new GZIPInputStream(in);)
169 // System.out.println("File : " + siftFile.getAbsolutePath());
170 JAXBContext jc = JAXBContext.newInstance("jalview.xml.binding.sifts");
171 XMLStreamReader streamReader = XMLInputFactory.newInstance()
172 .createXMLStreamReader(gzis);
173 Unmarshaller um = jc.createUnmarshaller();
174 return (Entry) um.unmarshal(streamReader);
175 } catch (Exception e)
178 throw new SiftsException(e.getMessage());
183 * Get a SIFTs XML file for a given PDB Id from Cache or download from FTP
184 * repository if not found in cache
187 * @return SIFTs XML file
188 * @throws SiftsException
190 public static File getSiftsFile(String pdbId) throws SiftsException
192 String siftsFileName = SiftsSettings.getSiftDownloadDirectory()
193 + pdbId.toLowerCase() + ".xml.gz";
194 File siftsFile = new File(siftsFileName);
195 if (siftsFile.exists())
197 // The line below is required for unit testing... don't comment it out!!!
198 System.out.println(">>> SIFTS File already downloaded for " + pdbId);
200 if (isFileOlderThanThreshold(siftsFile,
201 SiftsSettings.getCacheThresholdInDays()))
203 File oldSiftsFile = new File(siftsFileName + "_old");
204 siftsFile.renameTo(oldSiftsFile);
207 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
208 oldSiftsFile.delete();
210 } catch (IOException e)
213 oldSiftsFile.renameTo(siftsFile);
214 return new File(siftsFileName);
224 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
225 } catch (IOException e)
227 throw new SiftsException(e.getMessage());
233 * This method enables checking if a cached file has exceeded a certain
239 * the threshold in days
242 public static boolean isFileOlderThanThreshold(File file, int noOfDays)
244 Path filePath = file.toPath();
245 BasicFileAttributes attr;
249 attr = Files.readAttributes(filePath, BasicFileAttributes.class);
250 diffInDays = (int) ((new Date().getTime() - attr.lastModifiedTime()
251 .toMillis()) / (1000 * 60 * 60 * 24));
252 // System.out.println("Diff in days : " + diffInDays);
253 } catch (IOException e)
257 return noOfDays <= diffInDays;
261 * Download a SIFTs XML file for a given PDB Id from an FTP repository
264 * @return downloaded SIFTs XML file
265 * @throws SiftsException
266 * @throws IOException
268 public static File downloadSiftsFile(String pdbId) throws SiftsException,
271 if (pdbId.contains(".cif"))
273 pdbId = pdbId.replace(".cif", "");
275 String siftFile = pdbId + ".xml.gz";
276 String siftsFileFTPURL = SIFTS_FTP_BASE_URL + siftFile;
277 String downloadedSiftsFile = SiftsSettings.getSiftDownloadDirectory()
279 File siftsDownloadDir = new File(
280 SiftsSettings.getSiftDownloadDirectory());
281 if (!siftsDownloadDir.exists())
283 siftsDownloadDir.mkdirs();
285 // System.out.println(">> Download ftp url : " + siftsFileFTPURL);
286 // long now = System.currentTimeMillis();
287 URL url = new URL(siftsFileFTPURL);
288 URLConnection conn = url.openConnection();
289 InputStream inputStream = conn.getInputStream();
290 FileOutputStream outputStream = new FileOutputStream(
291 downloadedSiftsFile);
292 byte[] buffer = new byte[BUFFER_SIZE];
294 while ((bytesRead = inputStream.read(buffer)) != -1)
296 outputStream.write(buffer, 0, bytesRead);
298 outputStream.close();
300 // System.out.println(">>> File downloaded : " + downloadedSiftsFile
301 // + " took " + (System.currentTimeMillis() - now) + "ms");
302 return new File(downloadedSiftsFile);
306 * Delete the SIFTs file for the given PDB Id in the local SIFTs download
310 * @return true if the file was deleted or doesn't exist
312 public static boolean deleteSiftsFileByPDBId(String pdbId)
314 File siftsFile = new File(SiftsSettings.getSiftDownloadDirectory()
315 + pdbId.toLowerCase() + ".xml.gz");
316 if (siftsFile.exists())
318 return siftsFile.delete();
324 * Get a valid SIFTs DBRef for the given sequence current SIFTs entry
327 * - the target sequence for the operation
328 * @return a valid DBRefEntry that is SIFTs compatible
330 * if no valid source DBRefEntry was found for the given sequences
332 public DBRefEntryI getValidSourceDBRef(SequenceI seq)
333 throws SiftsException
335 List<DBRefEntry> dbRefs = seq.getPrimaryDBRefs();
336 if (dbRefs == null || dbRefs.size() < 1)
338 throw new SiftsException(
339 "Source DBRef could not be determined. DBRefs might not have been retrieved.");
342 for (DBRefEntry dbRef : dbRefs)
344 if (dbRef == null || dbRef.getAccessionId() == null
345 || dbRef.getSource() == null)
349 String canonicalSource = DBRefUtils.getCanonicalName(dbRef
351 if (isValidDBRefEntry(dbRef)
352 && (canonicalSource.equalsIgnoreCase(DBRefSource.UNIPROT) || canonicalSource
353 .equalsIgnoreCase(DBRefSource.PDB)))
358 throw new SiftsException("Could not get source DB Ref");
362 * Check that the DBRef Entry is properly populated and is available in this
363 * SiftClient instance
366 * - DBRefEntry to validate
367 * @return true validation is successful otherwise false is returned.
369 boolean isValidDBRefEntry(DBRefEntryI entry)
371 return entry != null && entry.getAccessionId() != null
372 && isFoundInSiftsEntry(entry.getAccessionId());
376 public HashSet<String> getAllMappingAccession()
378 HashSet<String> accessions = new HashSet<String>();
379 List<Entity> entities = siftsEntry.getEntity();
380 for (Entity entity : entities)
382 List<Segment> segments = entity.getSegment();
383 for (Segment segment : segments)
385 List<MapRegion> mapRegions = segment.getListMapRegion()
387 for (MapRegion mapRegion : mapRegions)
390 .add(mapRegion.getDb().getDbAccessionId().toLowerCase());
398 public StructureMapping getSiftsStructureMapping(SequenceI seq,
399 String pdbFile, String chain) throws SiftsException
401 structId = (chain == null) ? pdbId : pdbId + "|" + chain;
402 System.out.println("Getting SIFTS mapping for " + structId + ": seq "
405 final StringBuilder mappingDetails = new StringBuilder(128);
406 PrintStream ps = new PrintStream(System.out)
409 public void print(String x)
411 mappingDetails.append(x);
415 public void println()
417 mappingDetails.append(NEWLINE);
420 HashMap<Integer, int[]> mapping = getGreedyMapping(chain, seq, ps);
422 String mappingOutput = mappingDetails.toString();
423 StructureMapping siftsMapping = new StructureMapping(seq, pdbFile,
424 pdbId, chain, mapping, mappingOutput);
429 public HashMap<Integer, int[]> getGreedyMapping(String entityId,
430 SequenceI seq, java.io.PrintStream os) throws SiftsException
432 List<Integer> omitNonObserved = new ArrayList<Integer>();
433 int nonObservedShiftIndex = 0;
434 // System.out.println("Generating mappings for : " + entityId);
435 Entity entity = null;
436 entity = getEntityById(entityId);
437 String originalSeq = AlignSeq.extractGaps(
438 jalview.util.Comparison.GapChars, seq.getSequenceAsString());
439 HashMap<Integer, int[]> mapping = new HashMap<Integer, int[]>();
440 DBRefEntryI sourceDBRef;
441 sourceDBRef = getValidSourceDBRef(seq);
442 // TODO ensure sequence start/end is in the same coordinate system and
443 // consistent with the choosen sourceDBRef
445 // set sequence coordinate system - default value is UniProt
446 if (sourceDBRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
448 seqCoordSys = CoordinateSys.PDB;
451 HashSet<String> dbRefAccessionIdsString = new HashSet<String>();
452 for (DBRefEntry dbref : seq.getDBRefs())
454 dbRefAccessionIdsString.add(dbref.getAccessionId().toLowerCase());
456 dbRefAccessionIdsString.add(sourceDBRef.getAccessionId().toLowerCase());
458 curDBRefAccessionIdsString = dbRefAccessionIdsString;
459 curSourceDBRef = sourceDBRef.getAccessionId();
461 TreeMap<Integer, String> resNumMap = new TreeMap<Integer, String>();
462 List<Segment> segments = entity.getSegment();
463 SegmentHelperPojo shp = new SegmentHelperPojo(seq, mapping, resNumMap,
464 omitNonObserved, nonObservedShiftIndex);
465 processSegments(segments, shp);
468 populateAtomPositions(entityId, mapping);
469 } catch (Exception e)
473 if (seqCoordSys == CoordinateSys.UNIPROT)
475 padWithGaps(resNumMap, omitNonObserved);
477 int seqStart = UNASSIGNED;
478 int seqEnd = UNASSIGNED;
479 int pdbStart = UNASSIGNED;
480 int pdbEnd = UNASSIGNED;
482 if (mapping.isEmpty())
484 throw new SiftsException("SIFTS mapping failed");
487 Integer[] keys = mapping.keySet().toArray(new Integer[0]);
490 seqEnd = keys[keys.length - 1];
492 String matchedSeq = originalSeq;
493 if (seqStart != UNASSIGNED)
495 pdbStart = mapping.get(seqStart)[PDB_RES_POS];
496 pdbEnd = mapping.get(seqEnd)[PDB_RES_POS];
497 int orignalSeqStart = seq.getStart();
498 if (orignalSeqStart >= 1)
500 int subSeqStart = (seqStart >= orignalSeqStart) ? seqStart
501 - orignalSeqStart : 0;
502 int subSeqEnd = seqEnd - (orignalSeqStart - 1);
503 subSeqEnd = originalSeq.length() < subSeqEnd ? originalSeq.length()
505 matchedSeq = originalSeq.substring(subSeqStart, subSeqEnd);
509 matchedSeq = originalSeq.substring(1, originalSeq.length());
513 StringBuilder targetStrucSeqs = new StringBuilder();
514 for (String res : resNumMap.values())
516 targetStrucSeqs.append(res);
521 MappingOutputPojo mop = new MappingOutputPojo();
522 mop.setSeqStart(seqStart);
523 mop.setSeqEnd(seqEnd);
524 mop.setSeqName(seq.getName());
525 mop.setSeqResidue(matchedSeq);
527 mop.setStrStart(pdbStart);
528 mop.setStrEnd(pdbEnd);
529 mop.setStrName(structId);
530 mop.setStrResidue(targetStrucSeqs.toString());
533 os.print(getMappingOutput(mop).toString());
539 void processSegments(List<Segment> segments, SegmentHelperPojo shp)
541 SequenceI seq = shp.getSeq();
542 HashMap<Integer, int[]> mapping = shp.getMapping();
543 TreeMap<Integer, String> resNumMap = shp.getResNumMap();
544 List<Integer> omitNonObserved = shp.getOmitNonObserved();
545 int nonObservedShiftIndex = shp.getNonObservedShiftIndex();
546 for (Segment segment : segments)
548 // System.out.println("Mapping segments : " + segment.getSegId() + "\\"s
550 List<Residue> residues = segment.getListResidue().getResidue();
551 for (Residue residue : residues)
553 int currSeqIndex = UNASSIGNED;
554 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
555 CrossRefDb pdbRefDb = null;
556 for (CrossRefDb cRefDb : cRefDbs)
558 if (cRefDb.getDbSource().equalsIgnoreCase(DBRefSource.PDB))
562 if (cRefDb.getDbCoordSys()
563 .equalsIgnoreCase(seqCoordSys.getName())
564 && isAccessionMatched(cRefDb.getDbAccessionId()))
566 String resNumIndexString = cRefDb.getDbResNum()
567 .equalsIgnoreCase("None") ? String.valueOf(UNASSIGNED)
568 : cRefDb.getDbResNum();
571 currSeqIndex = Integer.valueOf(resNumIndexString);
572 } catch (NumberFormatException nfe)
574 currSeqIndex = Integer.valueOf(resNumIndexString
575 .split("[a-zA-Z]")[0]);
578 if (pdbRefDb != null)
580 break;// exit loop if pdb and uniprot are already found
584 if (currSeqIndex == UNASSIGNED)
588 if (currSeqIndex >= seq.getStart() && currSeqIndex <= seq.getEnd())
593 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
594 .getDbResNum()) : Integer.valueOf(pdbRefDb
596 } catch (NumberFormatException nfe)
598 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
599 .getDbResNum()) : Integer.valueOf(pdbRefDb
600 .getDbResNum().split("[a-zA-Z]")[0]);
604 if (isResidueObserved(residue)
605 || seqCoordSys == CoordinateSys.UNIPROT)
607 char resCharCode = ResidueProperties
608 .getSingleCharacterCode(ResidueProperties
609 .getCanonicalAminoAcid(residue.getDbResName()));
610 resNumMap.put(currSeqIndex, String.valueOf(resCharCode));
614 omitNonObserved.add(currSeqIndex);
615 ++nonObservedShiftIndex;
617 mapping.put(currSeqIndex - nonObservedShiftIndex, new int[] {
618 Integer.valueOf(resNum), UNASSIGNED });
627 * Target chain to populate mapping of its atom positions.
629 * Two dimension array of residue index versus atom position
630 * @throws IllegalArgumentException
631 * Thrown if chainId or mapping is null
632 * @throws SiftsException
634 void populateAtomPositions(String chainId, Map<Integer, int[]> mapping)
635 throws IllegalArgumentException, SiftsException
639 PDBChain chain = pdb.findChain(chainId);
641 if (chain == null || mapping == null)
643 throw new IllegalArgumentException(
644 "Chain id or mapping must not be null.");
646 for (int[] map : mapping.values())
648 if (map[PDB_RES_POS] != UNASSIGNED)
650 map[PDB_ATOM_POS] = getAtomIndex(map[PDB_RES_POS], chain.atoms);
653 } catch (NullPointerException e)
655 throw new SiftsException(e.getMessage());
656 } catch (Exception e)
658 throw new SiftsException(e.getMessage());
664 * @param residueIndex
665 * The residue index used for the search
667 * A collection of Atom to search
668 * @return atom position for the given residue index
670 int getAtomIndex(int residueIndex, Collection<Atom> atoms)
674 throw new IllegalArgumentException(
675 "atoms collection must not be null!");
677 for (Atom atom : atoms)
679 if (atom.resNumber == residueIndex)
681 return atom.atomIndex;
688 * Checks if the residue instance is marked 'Not_observed' or not
693 private boolean isResidueObserved(Residue residue)
695 Set<String> annotations = getResidueAnnotaitons(residue,
696 ResidueDetailType.ANNOTATION);
697 if (annotations == null || annotations.isEmpty())
701 for (String annotation : annotations)
703 if (annotation.equalsIgnoreCase(NOT_OBSERVED))
712 * Get annotation String for a given residue and annotation type
718 private Set<String> getResidueAnnotaitons(Residue residue,
719 ResidueDetailType type)
721 HashSet<String> foundAnnotations = new HashSet<String>();
722 List<ResidueDetail> resDetails = residue.getResidueDetail();
723 for (ResidueDetail resDetail : resDetails)
725 if (resDetail.getProperty().equalsIgnoreCase(type.getCode()))
727 foundAnnotations.add(resDetail.getContent());
730 return foundAnnotations;
734 public boolean isAccessionMatched(String accession)
736 boolean isStrictMatch = true;
737 return isStrictMatch ? curSourceDBRef.equalsIgnoreCase(accession)
738 : curDBRefAccessionIdsString.contains(accession.toLowerCase());
741 private boolean isFoundInSiftsEntry(String accessionId)
743 Set<String> siftsDBRefs = getAllMappingAccession();
744 return accessionId != null
745 && siftsDBRefs.contains(accessionId.toLowerCase());
749 * Pad omitted residue positions in PDB sequence with gaps
753 void padWithGaps(Map<Integer, String> resNumMap,
754 List<Integer> omitNonObserved)
756 if (resNumMap == null || resNumMap.isEmpty())
760 Integer[] keys = resNumMap.keySet().toArray(new Integer[0]);
761 // Arrays.sort(keys);
762 int firstIndex = keys[0];
763 int lastIndex = keys[keys.length - 1];
764 // System.out.println("Min value " + firstIndex);
765 // System.out.println("Max value " + lastIndex);
766 for (int x = firstIndex; x <= lastIndex; x++)
768 if (!resNumMap.containsKey(x) && !omitNonObserved.contains(x))
770 resNumMap.put(x, "-");
776 public Entity getEntityById(String id) throws SiftsException
778 // Determines an entity to process by performing a heuristic matching of all
779 // Entities with the given chainId and choosing the best matching Entity
780 Entity entity = getEntityByMostOptimalMatchedId(id);
785 throw new SiftsException("Entity " + id + " not found");
789 * This method was added because EntityId is NOT always equal to ChainId.
790 * Hence, it provides the logic to greedily detect the "true" Entity for a
791 * given chainId where discrepancies exist.
796 public Entity getEntityByMostOptimalMatchedId(String chainId)
798 // System.out.println("---> advanced greedy entityId matching block entered..");
799 List<Entity> entities = siftsEntry.getEntity();
800 SiftsEntitySortPojo[] sPojo = new SiftsEntitySortPojo[entities.size()];
802 for (Entity entity : entities)
804 sPojo[count] = new SiftsEntitySortPojo();
805 sPojo[count].entityId = entity.getEntityId();
807 List<Segment> segments = entity.getSegment();
808 for (Segment segment : segments)
810 List<Residue> residues = segment.getListResidue().getResidue();
811 for (Residue residue : residues)
813 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
814 for (CrossRefDb cRefDb : cRefDbs)
816 if (!cRefDb.getDbSource().equalsIgnoreCase("PDB"))
820 ++sPojo[count].resCount;
821 if (cRefDb.getDbChainId().equalsIgnoreCase(chainId))
823 ++sPojo[count].chainIdFreq;
828 sPojo[count].pid = (100 * sPojo[count].chainIdFreq)
829 / sPojo[count].resCount;
832 Arrays.sort(sPojo, Collections.reverseOrder());
833 // System.out.println("highest matched entity : " + sPojo[0].entityId);
834 // System.out.println("highest matched pid : " + sPojo[0].pid);
836 if (sPojo[0].entityId != null)
838 if (sPojo[0].pid < 1)
842 for (Entity entity : entities)
844 if (!entity.getEntityId().equalsIgnoreCase(sPojo[0].entityId))
854 private class SiftsEntitySortPojo implements
855 Comparable<SiftsEntitySortPojo>
857 public String entityId;
859 public int chainIdFreq;
866 public int compareTo(SiftsEntitySortPojo o)
868 return this.pid - o.pid;
872 private class SegmentHelperPojo
874 private SequenceI seq;
876 private HashMap<Integer, int[]> mapping;
878 private TreeMap<Integer, String> resNumMap;
880 private List<Integer> omitNonObserved;
882 private int nonObservedShiftIndex;
884 public SegmentHelperPojo(SequenceI seq,
885 HashMap<Integer, int[]> mapping,
886 TreeMap<Integer, String> resNumMap,
887 List<Integer> omitNonObserved, int nonObservedShiftIndex)
891 setResNumMap(resNumMap);
892 setOmitNonObserved(omitNonObserved);
893 setNonObservedShiftIndex(nonObservedShiftIndex);
896 public SequenceI getSeq()
901 public void setSeq(SequenceI seq)
906 public HashMap<Integer, int[]> getMapping()
911 public void setMapping(HashMap<Integer, int[]> mapping)
913 this.mapping = mapping;
916 public TreeMap<Integer, String> getResNumMap()
921 public void setResNumMap(TreeMap<Integer, String> resNumMap)
923 this.resNumMap = resNumMap;
926 public List<Integer> getOmitNonObserved()
928 return omitNonObserved;
931 public void setOmitNonObserved(List<Integer> omitNonObserved)
933 this.omitNonObserved = omitNonObserved;
936 public int getNonObservedShiftIndex()
938 return nonObservedShiftIndex;
941 public void setNonObservedShiftIndex(int nonObservedShiftIndex)
943 this.nonObservedShiftIndex = nonObservedShiftIndex;
948 public StringBuilder getMappingOutput(MappingOutputPojo mp)
949 throws SiftsException
951 String seqRes = mp.getSeqResidue();
952 String seqName = mp.getSeqName();
953 int sStart = mp.getSeqStart();
954 int sEnd = mp.getSeqEnd();
956 String strRes = mp.getStrResidue();
957 String strName = mp.getStrName();
958 int pdbStart = mp.getStrStart();
959 int pdbEnd = mp.getStrEnd();
961 String type = mp.getType();
963 int maxid = (seqName.length() >= strName.length()) ? seqName.length()
965 int len = 72 - maxid - 1;
967 int nochunks = ((seqRes.length()) / len)
968 + ((seqRes.length()) % len > 0 ? 1 : 0);
970 StringBuilder output = new StringBuilder(512);
971 output.append(NEWLINE);
972 output.append("Sequence \u27f7 Structure mapping details").append(
974 output.append("Method: SIFTS");
975 output.append(NEWLINE).append(NEWLINE);
977 output.append(new Format("%" + maxid + "s").form(seqName));
978 output.append(" : ");
979 output.append(String.valueOf(sStart));
980 output.append(" - ");
981 output.append(String.valueOf(sEnd));
982 output.append(" Maps to ");
983 output.append(NEWLINE);
984 output.append(new Format("%" + maxid + "s").form(structId));
985 output.append(" : ");
986 output.append(String.valueOf(pdbStart));
987 output.append(" - ");
988 output.append(String.valueOf(pdbEnd));
989 output.append(NEWLINE).append(NEWLINE);
991 ScoreMatrix pam250 = ScoreModels.getInstance().getPam250();
992 int matchedSeqCount = 0;
993 for (int j = 0; j < nochunks; j++)
995 // Print the first aligned sequence
996 output.append(new Format("%" + (maxid) + "s").form(seqName)).append(
999 for (int i = 0; i < len; i++)
1001 if ((i + (j * len)) < seqRes.length())
1003 output.append(seqRes.charAt(i + (j * len)));
1007 output.append(NEWLINE);
1008 output.append(new Format("%" + (maxid) + "s").form(" ")).append(" ");
1011 * Print out the match symbols:
1012 * | for exact match (ignoring case)
1013 * . if PAM250 score is positive
1016 for (int i = 0; i < len; i++)
1020 if ((i + (j * len)) < seqRes.length())
1022 char c1 = seqRes.charAt(i + (j * len));
1023 char c2 = strRes.charAt(i + (j * len));
1024 boolean sameChar = Comparison.isSameResidue(c1, c2, false);
1025 if (sameChar && !Comparison.isGap(c1))
1030 else if (type.equals("pep"))
1032 if (pam250.getPairwiseScore(c1, c2) > 0)
1046 } catch (IndexOutOfBoundsException e)
1051 // Now print the second aligned sequence
1052 output = output.append(NEWLINE);
1053 output = output.append(new Format("%" + (maxid) + "s").form(strName))
1055 for (int i = 0; i < len; i++)
1057 if ((i + (j * len)) < strRes.length())
1059 output.append(strRes.charAt(i + (j * len)));
1062 output.append(NEWLINE).append(NEWLINE);
1064 float pid = (float) matchedSeqCount / seqRes.length() * 100;
1065 if (pid < SiftsSettings.getFailSafePIDThreshold())
1067 throw new SiftsException(">>> Low PID detected for SIFTs mapping...");
1069 output.append("Length of alignment = " + seqRes.length()).append(
1071 output.append(new Format("Percentage ID = %2.2f").form(pid));
1076 public int getEntityCount()
1078 return siftsEntry.getEntity().size();
1082 public String getDbAccessionId()
1084 return siftsEntry.getDbAccessionId();
1088 public String getDbCoordSys()
1090 return siftsEntry.getDbCoordSys();
1094 public String getDbSource()
1096 return siftsEntry.getDbSource();
1100 public String getDbVersion()
1102 return siftsEntry.getDbVersion();