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
80 * for use in mocking out file fetch for tests only
81 * - reset to null after testing!
83 private static File mockSiftsFile;
85 private Entry siftsEntry;
87 private StructureFile pdb;
91 private String structId;
93 private CoordinateSys seqCoordSys = CoordinateSys.UNIPROT;
95 private static final int BUFFER_SIZE = 4096;
97 public static final int UNASSIGNED = -1;
99 private static final int PDB_RES_POS = 0;
101 private static final int PDB_ATOM_POS = 1;
103 private static final String NOT_OBSERVED = "Not_Observed";
105 private static final String SIFTS_FTP_BASE_URL = "http://ftp.ebi.ac.uk/pub/databases/msd/sifts/xml/";
107 private final static String NEWLINE = System.lineSeparator();
109 private String curSourceDBRef;
111 private HashSet<String> curDBRefAccessionIdsString;
113 private enum CoordinateSys
115 UNIPROT("UniProt"), PDB("PDBresnum"), PDBe("PDBe");
118 private CoordinateSys(String name)
123 public String getName()
129 private enum ResidueDetailType
131 NAME_SEC_STRUCTURE("nameSecondaryStructure"),
132 CODE_SEC_STRUCTURE("codeSecondaryStructure"), ANNOTATION("Annotation");
135 private ResidueDetailType(String code)
140 public String getCode()
147 * Fetch SIFTs file for the given PDBfile and construct an instance of
151 * @throws SiftsException
153 public SiftsClient(StructureFile pdb) throws SiftsException
156 this.pdbId = pdb.getId();
157 File siftsFile = getSiftsFile(pdbId);
158 siftsEntry = parseSIFTs(siftsFile);
162 * Parse the given SIFTs File and return a JAXB POJO of parsed data
165 * - the GZipped SIFTs XML file to parse
168 * if a problem occurs while parsing the SIFTs XML
170 private Entry parseSIFTs(File siftFile) throws SiftsException
172 try (InputStream in = new FileInputStream(siftFile);
173 GZIPInputStream gzis = new GZIPInputStream(in);)
175 // System.out.println("File : " + siftFile.getAbsolutePath());
176 JAXBContext jc = JAXBContext.newInstance("jalview.xml.binding.sifts");
177 XMLStreamReader streamReader = XMLInputFactory.newInstance()
178 .createXMLStreamReader(gzis);
179 Unmarshaller um = jc.createUnmarshaller();
180 return (Entry) um.unmarshal(streamReader);
181 } catch (Exception e)
184 throw new SiftsException(e.getMessage());
189 * Get a SIFTs XML file for a given PDB Id from Cache or download from FTP
190 * repository if not found in cache
193 * @return SIFTs XML file
194 * @throws SiftsException
196 public static File getSiftsFile(String pdbId) throws SiftsException
199 * return mocked file if it has been set
201 if (mockSiftsFile != null)
203 return mockSiftsFile;
206 String siftsFileName = SiftsSettings.getSiftDownloadDirectory()
207 + pdbId.toLowerCase() + ".xml.gz";
208 File siftsFile = new File(siftsFileName);
209 if (siftsFile.exists())
211 // The line below is required for unit testing... don't comment it out!!!
212 System.out.println(">>> SIFTS File already downloaded for " + pdbId);
214 if (isFileOlderThanThreshold(siftsFile,
215 SiftsSettings.getCacheThresholdInDays()))
217 File oldSiftsFile = new File(siftsFileName + "_old");
218 siftsFile.renameTo(oldSiftsFile);
221 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
222 oldSiftsFile.delete();
224 } catch (IOException e)
227 oldSiftsFile.renameTo(siftsFile);
228 return new File(siftsFileName);
238 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
239 } catch (IOException e)
241 throw new SiftsException(e.getMessage());
247 * This method enables checking if a cached file has exceeded a certain
253 * the threshold in days
256 public static boolean isFileOlderThanThreshold(File file, int noOfDays)
258 Path filePath = file.toPath();
259 BasicFileAttributes attr;
263 attr = Files.readAttributes(filePath, BasicFileAttributes.class);
264 diffInDays = (int) ((new Date().getTime()
265 - attr.lastModifiedTime().toMillis())
266 / (1000 * 60 * 60 * 24));
267 // System.out.println("Diff in days : " + diffInDays);
268 } catch (IOException e)
272 return noOfDays <= diffInDays;
276 * Download a SIFTs XML file for a given PDB Id from an FTP repository
279 * @return downloaded SIFTs XML file
280 * @throws SiftsException
281 * @throws IOException
283 public static File downloadSiftsFile(String pdbId)
284 throws SiftsException, IOException
286 if (pdbId.contains(".cif"))
288 pdbId = pdbId.replace(".cif", "");
290 String siftFile = pdbId + ".xml.gz";
291 String siftsFileFTPURL = SIFTS_FTP_BASE_URL + siftFile;
292 String downloadedSiftsFile = SiftsSettings.getSiftDownloadDirectory()
294 File siftsDownloadDir = new File(
295 SiftsSettings.getSiftDownloadDirectory());
296 if (!siftsDownloadDir.exists())
298 siftsDownloadDir.mkdirs();
300 // System.out.println(">> Download ftp url : " + siftsFileFTPURL);
301 // long now = System.currentTimeMillis();
302 URL url = new URL(siftsFileFTPURL);
303 URLConnection conn = url.openConnection();
304 InputStream inputStream = conn.getInputStream();
305 FileOutputStream outputStream = new FileOutputStream(
306 downloadedSiftsFile);
307 byte[] buffer = new byte[BUFFER_SIZE];
309 while ((bytesRead = inputStream.read(buffer)) != -1)
311 outputStream.write(buffer, 0, bytesRead);
313 outputStream.close();
315 // System.out.println(">>> File downloaded : " + downloadedSiftsFile
316 // + " took " + (System.currentTimeMillis() - now) + "ms");
317 return new File(downloadedSiftsFile);
321 * Delete the SIFTs file for the given PDB Id in the local SIFTs download
325 * @return true if the file was deleted or doesn't exist
327 public static boolean deleteSiftsFileByPDBId(String pdbId)
329 File siftsFile = new File(SiftsSettings.getSiftDownloadDirectory()
330 + pdbId.toLowerCase() + ".xml.gz");
331 if (siftsFile.exists())
333 return siftsFile.delete();
339 * Get a valid SIFTs DBRef for the given sequence current SIFTs entry
342 * - the target sequence for the operation
343 * @return a valid DBRefEntry that is SIFTs compatible
345 * if no valid source DBRefEntry was found for the given sequences
347 public DBRefEntryI getValidSourceDBRef(SequenceI seq)
348 throws SiftsException
350 List<DBRefEntry> dbRefs = seq.getPrimaryDBRefs();
351 if (dbRefs == null || dbRefs.size() < 1)
353 throw new SiftsException(
354 "Source DBRef could not be determined. DBRefs might not have been retrieved.");
357 for (DBRefEntry dbRef : dbRefs)
359 if (dbRef == null || dbRef.getAccessionId() == null
360 || dbRef.getSource() == null)
364 String canonicalSource = DBRefUtils
365 .getCanonicalName(dbRef.getSource());
366 if (isValidDBRefEntry(dbRef)
367 && (canonicalSource.equalsIgnoreCase(DBRefSource.UNIPROT)
368 || canonicalSource.equalsIgnoreCase(DBRefSource.PDB)))
373 throw new SiftsException("Could not get source DB Ref");
377 * Check that the DBRef Entry is properly populated and is available in this
378 * SiftClient instance
381 * - DBRefEntry to validate
382 * @return true validation is successful otherwise false is returned.
384 boolean isValidDBRefEntry(DBRefEntryI entry)
386 return entry != null && entry.getAccessionId() != null
387 && isFoundInSiftsEntry(entry.getAccessionId());
391 public HashSet<String> getAllMappingAccession()
393 HashSet<String> accessions = new HashSet<String>();
394 List<Entity> entities = siftsEntry.getEntity();
395 for (Entity entity : entities)
397 List<Segment> segments = entity.getSegment();
398 for (Segment segment : segments)
400 List<MapRegion> mapRegions = segment.getListMapRegion()
402 for (MapRegion mapRegion : mapRegions)
405 .add(mapRegion.getDb().getDbAccessionId().toLowerCase());
413 public StructureMapping getSiftsStructureMapping(SequenceI seq,
414 String pdbFile, String chain) throws SiftsException
416 SequenceI aseq = seq;
417 while (seq.getDatasetSequence() != null)
419 seq = seq.getDatasetSequence();
421 structId = (chain == null) ? pdbId : pdbId + "|" + chain;
422 System.out.println("Getting SIFTS mapping for " + structId + ": seq "
425 final StringBuilder mappingDetails = new StringBuilder(128);
426 PrintStream ps = new PrintStream(System.out)
429 public void print(String x)
431 mappingDetails.append(x);
435 public void println()
437 mappingDetails.append(NEWLINE);
440 HashMap<Integer, int[]> mapping = getGreedyMapping(chain, seq, ps);
442 String mappingOutput = mappingDetails.toString();
443 StructureMapping siftsMapping = new StructureMapping(seq, pdbFile,
444 pdbId, chain, mapping, mappingOutput);
449 public HashMap<Integer, int[]> getGreedyMapping(String entityId,
450 SequenceI seq, java.io.PrintStream os) throws SiftsException
452 List<Integer> omitNonObserved = new ArrayList<Integer>();
453 int nonObservedShiftIndex = 0;
454 // System.out.println("Generating mappings for : " + entityId);
455 Entity entity = null;
456 entity = getEntityById(entityId);
457 String originalSeq = AlignSeq.extractGaps(
458 jalview.util.Comparison.GapChars, seq.getSequenceAsString());
459 HashMap<Integer, int[]> mapping = new HashMap<Integer, int[]>();
460 DBRefEntryI sourceDBRef;
461 sourceDBRef = getValidSourceDBRef(seq);
462 // TODO ensure sequence start/end is in the same coordinate system and
463 // consistent with the choosen sourceDBRef
465 // set sequence coordinate system - default value is UniProt
466 if (sourceDBRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
468 seqCoordSys = CoordinateSys.PDB;
471 HashSet<String> dbRefAccessionIdsString = new HashSet<String>();
472 for (DBRefEntry dbref : seq.getDBRefs())
474 dbRefAccessionIdsString.add(dbref.getAccessionId().toLowerCase());
476 dbRefAccessionIdsString.add(sourceDBRef.getAccessionId().toLowerCase());
478 curDBRefAccessionIdsString = dbRefAccessionIdsString;
479 curSourceDBRef = sourceDBRef.getAccessionId();
481 TreeMap<Integer, String> resNumMap = new TreeMap<Integer, String>();
482 List<Segment> segments = entity.getSegment();
483 SegmentHelperPojo shp = new SegmentHelperPojo(seq, mapping, resNumMap,
484 omitNonObserved, nonObservedShiftIndex);
485 processSegments(segments, shp);
488 populateAtomPositions(entityId, mapping);
489 } catch (Exception e)
493 if (seqCoordSys == CoordinateSys.UNIPROT)
495 padWithGaps(resNumMap, omitNonObserved);
497 int seqStart = UNASSIGNED;
498 int seqEnd = UNASSIGNED;
499 int pdbStart = UNASSIGNED;
500 int pdbEnd = UNASSIGNED;
502 if (mapping.isEmpty())
504 throw new SiftsException("SIFTS mapping failed");
507 Integer[] keys = mapping.keySet().toArray(new Integer[0]);
510 seqEnd = keys[keys.length - 1];
512 String matchedSeq = originalSeq;
513 if (seqStart != UNASSIGNED)
515 pdbStart = mapping.get(seqStart)[PDB_RES_POS];
516 pdbEnd = mapping.get(seqEnd)[PDB_RES_POS];
517 int orignalSeqStart = seq.getStart();
518 if (orignalSeqStart >= 1)
520 int subSeqStart = (seqStart >= orignalSeqStart)
521 ? seqStart - orignalSeqStart
523 int subSeqEnd = seqEnd - (orignalSeqStart - 1);
524 subSeqEnd = originalSeq.length() < subSeqEnd ? originalSeq.length()
526 matchedSeq = originalSeq.substring(subSeqStart, subSeqEnd);
530 matchedSeq = originalSeq.substring(1, originalSeq.length());
534 StringBuilder targetStrucSeqs = new StringBuilder();
535 for (String res : resNumMap.values())
537 targetStrucSeqs.append(res);
542 MappingOutputPojo mop = new MappingOutputPojo();
543 mop.setSeqStart(seqStart);
544 mop.setSeqEnd(seqEnd);
545 mop.setSeqName(seq.getName());
546 mop.setSeqResidue(matchedSeq);
548 mop.setStrStart(pdbStart);
549 mop.setStrEnd(pdbEnd);
550 mop.setStrName(structId);
551 mop.setStrResidue(targetStrucSeqs.toString());
554 os.print(getMappingOutput(mop).toString());
560 void processSegments(List<Segment> segments, SegmentHelperPojo shp)
562 SequenceI seq = shp.getSeq();
563 HashMap<Integer, int[]> mapping = shp.getMapping();
564 TreeMap<Integer, String> resNumMap = shp.getResNumMap();
565 List<Integer> omitNonObserved = shp.getOmitNonObserved();
566 int nonObservedShiftIndex = shp.getNonObservedShiftIndex();
567 for (Segment segment : segments)
569 // System.out.println("Mapping segments : " + segment.getSegId() + "\\"s
571 List<Residue> residues = segment.getListResidue().getResidue();
572 for (Residue residue : residues)
574 int currSeqIndex = UNASSIGNED;
575 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
576 CrossRefDb pdbRefDb = null;
577 for (CrossRefDb cRefDb : cRefDbs)
579 if (cRefDb.getDbSource().equalsIgnoreCase(DBRefSource.PDB))
583 if (cRefDb.getDbCoordSys().equalsIgnoreCase(seqCoordSys.getName())
584 && isAccessionMatched(cRefDb.getDbAccessionId()))
586 currSeqIndex = getLeadingIntegerValue(cRefDb.getDbResNum(),
588 if (pdbRefDb != null)
590 break;// exit loop if pdb and uniprot are already found
594 if (currSeqIndex == UNASSIGNED)
598 if (currSeqIndex >= seq.getStart() && currSeqIndex <= seq.getEnd())
601 int resNum = (pdbRefDb == null)
602 ? getLeadingIntegerValue(residue.getDbResNum(),
604 : getLeadingIntegerValue(pdbRefDb.getDbResNum(),
607 if (isResidueObserved(residue)
608 || seqCoordSys == CoordinateSys.UNIPROT)
610 char resCharCode = ResidueProperties
611 .getSingleCharacterCode(ResidueProperties
612 .getCanonicalAminoAcid(residue.getDbResName()));
613 resNumMap.put(currSeqIndex, String.valueOf(resCharCode));
617 omitNonObserved.add(currSeqIndex);
618 ++nonObservedShiftIndex;
620 mapping.put(currSeqIndex - nonObservedShiftIndex,
622 { Integer.valueOf(resNum), UNASSIGNED });
629 * Get the leading integer part of a string that begins with an integer.
632 * - the string input to process
634 * - value returned if unsuccessful
637 static int getLeadingIntegerValue(String input, int failValue)
643 String[] parts = input.split("(?=\\D)(?<=\\d)");
644 if (parts != null && parts.length > 0 && parts[0].matches("[0-9]+"))
646 return Integer.valueOf(parts[0]);
654 * Target chain to populate mapping of its atom positions.
656 * Two dimension array of residue index versus atom position
657 * @throws IllegalArgumentException
658 * Thrown if chainId or mapping is null
659 * @throws SiftsException
661 void populateAtomPositions(String chainId, Map<Integer, int[]> mapping)
662 throws IllegalArgumentException, SiftsException
666 PDBChain chain = pdb.findChain(chainId);
668 if (chain == null || mapping == null)
670 throw new IllegalArgumentException(
671 "Chain id or mapping must not be null.");
673 for (int[] map : mapping.values())
675 if (map[PDB_RES_POS] != UNASSIGNED)
677 map[PDB_ATOM_POS] = getAtomIndex(map[PDB_RES_POS], chain.atoms);
680 } catch (NullPointerException e)
682 throw new SiftsException(e.getMessage());
683 } catch (Exception e)
685 throw new SiftsException(e.getMessage());
691 * @param residueIndex
692 * The residue index used for the search
694 * A collection of Atom to search
695 * @return atom position for the given residue index
697 int getAtomIndex(int residueIndex, Collection<Atom> atoms)
701 throw new IllegalArgumentException(
702 "atoms collection must not be null!");
704 for (Atom atom : atoms)
706 if (atom.resNumber == residueIndex)
708 return atom.atomIndex;
715 * Checks if the residue instance is marked 'Not_observed' or not
720 private boolean isResidueObserved(Residue residue)
722 Set<String> annotations = getResidueAnnotaitons(residue,
723 ResidueDetailType.ANNOTATION);
724 if (annotations == null || annotations.isEmpty())
728 for (String annotation : annotations)
730 if (annotation.equalsIgnoreCase(NOT_OBSERVED))
739 * Get annotation String for a given residue and annotation type
745 private Set<String> getResidueAnnotaitons(Residue residue,
746 ResidueDetailType type)
748 HashSet<String> foundAnnotations = new HashSet<String>();
749 List<ResidueDetail> resDetails = residue.getResidueDetail();
750 for (ResidueDetail resDetail : resDetails)
752 if (resDetail.getProperty().equalsIgnoreCase(type.getCode()))
754 foundAnnotations.add(resDetail.getContent());
757 return foundAnnotations;
761 public boolean isAccessionMatched(String accession)
763 boolean isStrictMatch = true;
764 return isStrictMatch ? curSourceDBRef.equalsIgnoreCase(accession)
765 : curDBRefAccessionIdsString.contains(accession.toLowerCase());
768 private boolean isFoundInSiftsEntry(String accessionId)
770 Set<String> siftsDBRefs = getAllMappingAccession();
771 return accessionId != null
772 && siftsDBRefs.contains(accessionId.toLowerCase());
776 * Pad omitted residue positions in PDB sequence with gaps
780 void padWithGaps(Map<Integer, String> resNumMap,
781 List<Integer> omitNonObserved)
783 if (resNumMap == null || resNumMap.isEmpty())
787 Integer[] keys = resNumMap.keySet().toArray(new Integer[0]);
788 // Arrays.sort(keys);
789 int firstIndex = keys[0];
790 int lastIndex = keys[keys.length - 1];
791 // System.out.println("Min value " + firstIndex);
792 // System.out.println("Max value " + lastIndex);
793 for (int x = firstIndex; x <= lastIndex; x++)
795 if (!resNumMap.containsKey(x) && !omitNonObserved.contains(x))
797 resNumMap.put(x, "-");
803 public Entity getEntityById(String id) throws SiftsException
805 // Determines an entity to process by performing a heuristic matching of all
806 // Entities with the given chainId and choosing the best matching Entity
807 Entity entity = getEntityByMostOptimalMatchedId(id);
812 throw new SiftsException("Entity " + id + " not found");
816 * This method was added because EntityId is NOT always equal to ChainId.
817 * Hence, it provides the logic to greedily detect the "true" Entity for a
818 * given chainId where discrepancies exist.
823 public Entity getEntityByMostOptimalMatchedId(String chainId)
825 // System.out.println("---> advanced greedy entityId matching block
827 List<Entity> entities = siftsEntry.getEntity();
828 SiftsEntitySortPojo[] sPojo = new SiftsEntitySortPojo[entities.size()];
830 for (Entity entity : entities)
832 sPojo[count] = new SiftsEntitySortPojo();
833 sPojo[count].entityId = entity.getEntityId();
835 List<Segment> segments = entity.getSegment();
836 for (Segment segment : segments)
838 List<Residue> residues = segment.getListResidue().getResidue();
839 for (Residue residue : residues)
841 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
842 for (CrossRefDb cRefDb : cRefDbs)
844 if (!cRefDb.getDbSource().equalsIgnoreCase("PDB"))
848 ++sPojo[count].resCount;
849 if (cRefDb.getDbChainId().equalsIgnoreCase(chainId))
851 ++sPojo[count].chainIdFreq;
856 sPojo[count].pid = (100 * sPojo[count].chainIdFreq)
857 / sPojo[count].resCount;
860 Arrays.sort(sPojo, Collections.reverseOrder());
861 // System.out.println("highest matched entity : " + sPojo[0].entityId);
862 // System.out.println("highest matched pid : " + sPojo[0].pid);
864 if (sPojo[0].entityId != null)
866 if (sPojo[0].pid < 1)
870 for (Entity entity : entities)
872 if (!entity.getEntityId().equalsIgnoreCase(sPojo[0].entityId))
882 private class SiftsEntitySortPojo
883 implements Comparable<SiftsEntitySortPojo>
885 public String entityId;
887 public int chainIdFreq;
894 public int compareTo(SiftsEntitySortPojo o)
896 return this.pid - o.pid;
900 private class SegmentHelperPojo
902 private SequenceI seq;
904 private HashMap<Integer, int[]> mapping;
906 private TreeMap<Integer, String> resNumMap;
908 private List<Integer> omitNonObserved;
910 private int nonObservedShiftIndex;
912 public SegmentHelperPojo(SequenceI seq, HashMap<Integer, int[]> mapping,
913 TreeMap<Integer, String> resNumMap,
914 List<Integer> omitNonObserved, int nonObservedShiftIndex)
918 setResNumMap(resNumMap);
919 setOmitNonObserved(omitNonObserved);
920 setNonObservedShiftIndex(nonObservedShiftIndex);
923 public SequenceI getSeq()
928 public void setSeq(SequenceI seq)
933 public HashMap<Integer, int[]> getMapping()
938 public void setMapping(HashMap<Integer, int[]> mapping)
940 this.mapping = mapping;
943 public TreeMap<Integer, String> getResNumMap()
948 public void setResNumMap(TreeMap<Integer, String> resNumMap)
950 this.resNumMap = resNumMap;
953 public List<Integer> getOmitNonObserved()
955 return omitNonObserved;
958 public void setOmitNonObserved(List<Integer> omitNonObserved)
960 this.omitNonObserved = omitNonObserved;
963 public int getNonObservedShiftIndex()
965 return nonObservedShiftIndex;
968 public void setNonObservedShiftIndex(int nonObservedShiftIndex)
970 this.nonObservedShiftIndex = nonObservedShiftIndex;
975 public StringBuilder getMappingOutput(MappingOutputPojo mp)
976 throws SiftsException
978 String seqRes = mp.getSeqResidue();
979 String seqName = mp.getSeqName();
980 int sStart = mp.getSeqStart();
981 int sEnd = mp.getSeqEnd();
983 String strRes = mp.getStrResidue();
984 String strName = mp.getStrName();
985 int pdbStart = mp.getStrStart();
986 int pdbEnd = mp.getStrEnd();
988 String type = mp.getType();
990 int maxid = (seqName.length() >= strName.length()) ? seqName.length()
992 int len = 72 - maxid - 1;
994 int nochunks = ((seqRes.length()) / len)
995 + ((seqRes.length()) % len > 0 ? 1 : 0);
997 StringBuilder output = new StringBuilder(512);
998 output.append(NEWLINE);
999 output.append("Sequence \u27f7 Structure mapping details")
1001 output.append("Method: SIFTS");
1002 output.append(NEWLINE).append(NEWLINE);
1004 output.append(new Format("%" + maxid + "s").form(seqName));
1005 output.append(" : ");
1006 output.append(String.valueOf(sStart));
1007 output.append(" - ");
1008 output.append(String.valueOf(sEnd));
1009 output.append(" Maps to ");
1010 output.append(NEWLINE);
1011 output.append(new Format("%" + maxid + "s").form(structId));
1012 output.append(" : ");
1013 output.append(String.valueOf(pdbStart));
1014 output.append(" - ");
1015 output.append(String.valueOf(pdbEnd));
1016 output.append(NEWLINE).append(NEWLINE);
1018 ScoreMatrix pam250 = ScoreModels.getInstance().getPam250();
1019 int matchedSeqCount = 0;
1020 for (int j = 0; j < nochunks; j++)
1022 // Print the first aligned sequence
1023 output.append(new Format("%" + (maxid) + "s").form(seqName))
1026 for (int i = 0; i < len; i++)
1028 if ((i + (j * len)) < seqRes.length())
1030 output.append(seqRes.charAt(i + (j * len)));
1034 output.append(NEWLINE);
1035 output.append(new Format("%" + (maxid) + "s").form(" ")).append(" ");
1038 * Print out the match symbols:
1039 * | for exact match (ignoring case)
1040 * . if PAM250 score is positive
1043 for (int i = 0; i < len; i++)
1047 if ((i + (j * len)) < seqRes.length())
1049 char c1 = seqRes.charAt(i + (j * len));
1050 char c2 = strRes.charAt(i + (j * len));
1051 boolean sameChar = Comparison.isSameResidue(c1, c2, false);
1052 if (sameChar && !Comparison.isGap(c1))
1057 else if (type.equals("pep"))
1059 if (pam250.getPairwiseScore(c1, c2) > 0)
1073 } catch (IndexOutOfBoundsException e)
1078 // Now print the second aligned sequence
1079 output = output.append(NEWLINE);
1080 output = output.append(new Format("%" + (maxid) + "s").form(strName))
1082 for (int i = 0; i < len; i++)
1084 if ((i + (j * len)) < strRes.length())
1086 output.append(strRes.charAt(i + (j * len)));
1089 output.append(NEWLINE).append(NEWLINE);
1091 float pid = (float) matchedSeqCount / seqRes.length() * 100;
1092 if (pid < SiftsSettings.getFailSafePIDThreshold())
1094 throw new SiftsException(">>> Low PID detected for SIFTs mapping...");
1096 output.append("Length of alignment = " + seqRes.length())
1098 output.append(new Format("Percentage ID = %2.2f").form(pid));
1103 public int getEntityCount()
1105 return siftsEntry.getEntity().size();
1109 public String getDbAccessionId()
1111 return siftsEntry.getDbAccessionId();
1115 public String getDbCoordSys()
1117 return siftsEntry.getDbCoordSys();
1121 public String getDbSource()
1123 return siftsEntry.getDbSource();
1127 public String getDbVersion()
1129 return siftsEntry.getDbVersion();
1132 public static void setMockSiftsFile(File file)
1134 mockSiftsFile = file;