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"), CODE_SEC_STRUCTURE(
132 "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() - attr.lastModifiedTime()
265 .toMillis()) / (1000 * 60 * 60 * 24));
266 // System.out.println("Diff in days : " + diffInDays);
267 } catch (IOException e)
271 return noOfDays <= diffInDays;
275 * Download a SIFTs XML file for a given PDB Id from an FTP repository
278 * @return downloaded SIFTs XML file
279 * @throws SiftsException
280 * @throws IOException
282 public static File downloadSiftsFile(String pdbId) throws SiftsException,
285 if (pdbId.contains(".cif"))
287 pdbId = pdbId.replace(".cif", "");
289 String siftFile = pdbId + ".xml.gz";
290 String siftsFileFTPURL = SIFTS_FTP_BASE_URL + siftFile;
291 String downloadedSiftsFile = SiftsSettings.getSiftDownloadDirectory()
293 File siftsDownloadDir = new File(
294 SiftsSettings.getSiftDownloadDirectory());
295 if (!siftsDownloadDir.exists())
297 siftsDownloadDir.mkdirs();
299 // System.out.println(">> Download ftp url : " + siftsFileFTPURL);
300 // long now = System.currentTimeMillis();
301 URL url = new URL(siftsFileFTPURL);
302 URLConnection conn = url.openConnection();
303 InputStream inputStream = conn.getInputStream();
304 FileOutputStream outputStream = new FileOutputStream(
305 downloadedSiftsFile);
306 byte[] buffer = new byte[BUFFER_SIZE];
308 while ((bytesRead = inputStream.read(buffer)) != -1)
310 outputStream.write(buffer, 0, bytesRead);
312 outputStream.close();
314 // System.out.println(">>> File downloaded : " + downloadedSiftsFile
315 // + " took " + (System.currentTimeMillis() - now) + "ms");
316 return new File(downloadedSiftsFile);
320 * Delete the SIFTs file for the given PDB Id in the local SIFTs download
324 * @return true if the file was deleted or doesn't exist
326 public static boolean deleteSiftsFileByPDBId(String pdbId)
328 File siftsFile = new File(SiftsSettings.getSiftDownloadDirectory()
329 + pdbId.toLowerCase() + ".xml.gz");
330 if (siftsFile.exists())
332 return siftsFile.delete();
338 * Get a valid SIFTs DBRef for the given sequence current SIFTs entry
341 * - the target sequence for the operation
342 * @return a valid DBRefEntry that is SIFTs compatible
344 * if no valid source DBRefEntry was found for the given sequences
346 public DBRefEntryI getValidSourceDBRef(SequenceI seq)
347 throws SiftsException
349 List<DBRefEntry> dbRefs = seq.getPrimaryDBRefs();
350 if (dbRefs == null || dbRefs.size() < 1)
352 throw new SiftsException(
353 "Source DBRef could not be determined. DBRefs might not have been retrieved.");
356 for (DBRefEntry dbRef : dbRefs)
358 if (dbRef == null || dbRef.getAccessionId() == null
359 || dbRef.getSource() == null)
363 String canonicalSource = DBRefUtils.getCanonicalName(dbRef
365 if (isValidDBRefEntry(dbRef)
366 && (canonicalSource.equalsIgnoreCase(DBRefSource.UNIPROT) || canonicalSource
367 .equalsIgnoreCase(DBRefSource.PDB)))
372 throw new SiftsException("Could not get source DB Ref");
376 * Check that the DBRef Entry is properly populated and is available in this
377 * SiftClient instance
380 * - DBRefEntry to validate
381 * @return true validation is successful otherwise false is returned.
383 boolean isValidDBRefEntry(DBRefEntryI entry)
385 return entry != null && entry.getAccessionId() != null
386 && isFoundInSiftsEntry(entry.getAccessionId());
390 public HashSet<String> getAllMappingAccession()
392 HashSet<String> accessions = new HashSet<String>();
393 List<Entity> entities = siftsEntry.getEntity();
394 for (Entity entity : entities)
396 List<Segment> segments = entity.getSegment();
397 for (Segment segment : segments)
399 List<MapRegion> mapRegions = segment.getListMapRegion()
401 for (MapRegion mapRegion : mapRegions)
404 .add(mapRegion.getDb().getDbAccessionId().toLowerCase());
412 public StructureMapping getSiftsStructureMapping(SequenceI seq,
413 String pdbFile, String chain) throws SiftsException
415 structId = (chain == null) ? pdbId : pdbId + "|" + chain;
416 System.out.println("Getting SIFTS mapping for " + structId + ": seq "
419 final StringBuilder mappingDetails = new StringBuilder(128);
420 PrintStream ps = new PrintStream(System.out)
423 public void print(String x)
425 mappingDetails.append(x);
429 public void println()
431 mappingDetails.append(NEWLINE);
434 HashMap<Integer, int[]> mapping = getGreedyMapping(chain, seq, ps);
436 String mappingOutput = mappingDetails.toString();
437 StructureMapping siftsMapping = new StructureMapping(seq, pdbFile,
438 pdbId, chain, mapping, mappingOutput);
443 public HashMap<Integer, int[]> getGreedyMapping(String entityId,
444 SequenceI seq, java.io.PrintStream os) throws SiftsException
446 List<Integer> omitNonObserved = new ArrayList<Integer>();
447 int nonObservedShiftIndex = 0;
448 // System.out.println("Generating mappings for : " + entityId);
449 Entity entity = null;
450 entity = getEntityById(entityId);
451 String originalSeq = AlignSeq.extractGaps(
452 jalview.util.Comparison.GapChars, seq.getSequenceAsString());
453 HashMap<Integer, int[]> mapping = new HashMap<Integer, int[]>();
454 DBRefEntryI sourceDBRef;
455 sourceDBRef = getValidSourceDBRef(seq);
456 // TODO ensure sequence start/end is in the same coordinate system and
457 // consistent with the choosen sourceDBRef
459 // set sequence coordinate system - default value is UniProt
460 if (sourceDBRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
462 seqCoordSys = CoordinateSys.PDB;
465 HashSet<String> dbRefAccessionIdsString = new HashSet<String>();
466 for (DBRefEntry dbref : seq.getDBRefs())
468 dbRefAccessionIdsString.add(dbref.getAccessionId().toLowerCase());
470 dbRefAccessionIdsString.add(sourceDBRef.getAccessionId().toLowerCase());
472 curDBRefAccessionIdsString = dbRefAccessionIdsString;
473 curSourceDBRef = sourceDBRef.getAccessionId();
475 TreeMap<Integer, String> resNumMap = new TreeMap<Integer, String>();
476 List<Segment> segments = entity.getSegment();
477 SegmentHelperPojo shp = new SegmentHelperPojo(seq, mapping, resNumMap,
478 omitNonObserved, nonObservedShiftIndex);
479 processSegments(segments, shp);
482 populateAtomPositions(entityId, mapping);
483 } catch (Exception e)
487 if (seqCoordSys == CoordinateSys.UNIPROT)
489 padWithGaps(resNumMap, omitNonObserved);
491 int seqStart = UNASSIGNED;
492 int seqEnd = UNASSIGNED;
493 int pdbStart = UNASSIGNED;
494 int pdbEnd = UNASSIGNED;
496 if (mapping.isEmpty())
498 throw new SiftsException("SIFTS mapping failed");
501 Integer[] keys = mapping.keySet().toArray(new Integer[0]);
504 seqEnd = keys[keys.length - 1];
506 String matchedSeq = originalSeq;
507 if (seqStart != UNASSIGNED)
509 pdbStart = mapping.get(seqStart)[PDB_RES_POS];
510 pdbEnd = mapping.get(seqEnd)[PDB_RES_POS];
511 int orignalSeqStart = seq.getStart();
512 if (orignalSeqStart >= 1)
514 int subSeqStart = (seqStart >= orignalSeqStart) ? seqStart
515 - orignalSeqStart : 0;
516 int subSeqEnd = seqEnd - (orignalSeqStart - 1);
517 subSeqEnd = originalSeq.length() < subSeqEnd ? originalSeq.length()
519 matchedSeq = originalSeq.substring(subSeqStart, subSeqEnd);
523 matchedSeq = originalSeq.substring(1, originalSeq.length());
527 StringBuilder targetStrucSeqs = new StringBuilder();
528 for (String res : resNumMap.values())
530 targetStrucSeqs.append(res);
535 MappingOutputPojo mop = new MappingOutputPojo();
536 mop.setSeqStart(seqStart);
537 mop.setSeqEnd(seqEnd);
538 mop.setSeqName(seq.getName());
539 mop.setSeqResidue(matchedSeq);
541 mop.setStrStart(pdbStart);
542 mop.setStrEnd(pdbEnd);
543 mop.setStrName(structId);
544 mop.setStrResidue(targetStrucSeqs.toString());
547 os.print(getMappingOutput(mop).toString());
553 void processSegments(List<Segment> segments, SegmentHelperPojo shp)
555 SequenceI seq = shp.getSeq();
556 HashMap<Integer, int[]> mapping = shp.getMapping();
557 TreeMap<Integer, String> resNumMap = shp.getResNumMap();
558 List<Integer> omitNonObserved = shp.getOmitNonObserved();
559 int nonObservedShiftIndex = shp.getNonObservedShiftIndex();
560 for (Segment segment : segments)
562 // System.out.println("Mapping segments : " + segment.getSegId() + "\\"s
564 List<Residue> residues = segment.getListResidue().getResidue();
565 for (Residue residue : residues)
567 int currSeqIndex = UNASSIGNED;
568 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
569 CrossRefDb pdbRefDb = null;
570 for (CrossRefDb cRefDb : cRefDbs)
572 if (cRefDb.getDbSource().equalsIgnoreCase(DBRefSource.PDB))
576 if (cRefDb.getDbCoordSys()
577 .equalsIgnoreCase(seqCoordSys.getName())
578 && isAccessionMatched(cRefDb.getDbAccessionId()))
580 String resNumIndexString = cRefDb.getDbResNum()
581 .equalsIgnoreCase("None") ? String.valueOf(UNASSIGNED)
582 : cRefDb.getDbResNum();
585 currSeqIndex = Integer.valueOf(resNumIndexString);
586 } catch (NumberFormatException nfe)
588 currSeqIndex = Integer.valueOf(resNumIndexString
589 .split("[a-zA-Z]")[0]);
592 if (pdbRefDb != null)
594 break;// exit loop if pdb and uniprot are already found
598 if (currSeqIndex == UNASSIGNED)
602 if (currSeqIndex >= seq.getStart() && currSeqIndex <= seq.getEnd())
607 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
608 .getDbResNum()) : Integer.valueOf(pdbRefDb
610 } catch (NumberFormatException nfe)
612 if (pdbRefDb == null || pdbRefDb.getDbResNum().equals("null"))
617 resNum = Integer.valueOf(pdbRefDb
618 .getDbResNum().split("[a-zA-Z]")[0]);
622 if (isResidueObserved(residue)
623 || seqCoordSys == CoordinateSys.UNIPROT)
625 char resCharCode = ResidueProperties
626 .getSingleCharacterCode(ResidueProperties
627 .getCanonicalAminoAcid(residue.getDbResName()));
628 resNumMap.put(currSeqIndex, String.valueOf(resCharCode));
632 omitNonObserved.add(currSeqIndex);
633 ++nonObservedShiftIndex;
635 mapping.put(currSeqIndex - nonObservedShiftIndex, new int[] {
636 Integer.valueOf(resNum), UNASSIGNED });
645 * Target chain to populate mapping of its atom positions.
647 * Two dimension array of residue index versus atom position
648 * @throws IllegalArgumentException
649 * Thrown if chainId or mapping is null
650 * @throws SiftsException
652 void populateAtomPositions(String chainId, Map<Integer, int[]> mapping)
653 throws IllegalArgumentException, SiftsException
657 PDBChain chain = pdb.findChain(chainId);
659 if (chain == null || mapping == null)
661 throw new IllegalArgumentException(
662 "Chain id or mapping must not be null.");
664 for (int[] map : mapping.values())
666 if (map[PDB_RES_POS] != UNASSIGNED)
668 map[PDB_ATOM_POS] = getAtomIndex(map[PDB_RES_POS], chain.atoms);
671 } catch (NullPointerException e)
673 throw new SiftsException(e.getMessage());
674 } catch (Exception e)
676 throw new SiftsException(e.getMessage());
682 * @param residueIndex
683 * The residue index used for the search
685 * A collection of Atom to search
686 * @return atom position for the given residue index
688 int getAtomIndex(int residueIndex, Collection<Atom> atoms)
692 throw new IllegalArgumentException(
693 "atoms collection must not be null!");
695 for (Atom atom : atoms)
697 if (atom.resNumber == residueIndex)
699 return atom.atomIndex;
706 * Checks if the residue instance is marked 'Not_observed' or not
711 private boolean isResidueObserved(Residue residue)
713 Set<String> annotations = getResidueAnnotaitons(residue,
714 ResidueDetailType.ANNOTATION);
715 if (annotations == null || annotations.isEmpty())
719 for (String annotation : annotations)
721 if (annotation.equalsIgnoreCase(NOT_OBSERVED))
730 * Get annotation String for a given residue and annotation type
736 private Set<String> getResidueAnnotaitons(Residue residue,
737 ResidueDetailType type)
739 HashSet<String> foundAnnotations = new HashSet<String>();
740 List<ResidueDetail> resDetails = residue.getResidueDetail();
741 for (ResidueDetail resDetail : resDetails)
743 if (resDetail.getProperty().equalsIgnoreCase(type.getCode()))
745 foundAnnotations.add(resDetail.getContent());
748 return foundAnnotations;
752 public boolean isAccessionMatched(String accession)
754 boolean isStrictMatch = true;
755 return isStrictMatch ? curSourceDBRef.equalsIgnoreCase(accession)
756 : curDBRefAccessionIdsString.contains(accession.toLowerCase());
759 private boolean isFoundInSiftsEntry(String accessionId)
761 Set<String> siftsDBRefs = getAllMappingAccession();
762 return accessionId != null
763 && siftsDBRefs.contains(accessionId.toLowerCase());
767 * Pad omitted residue positions in PDB sequence with gaps
771 void padWithGaps(Map<Integer, String> resNumMap,
772 List<Integer> omitNonObserved)
774 if (resNumMap == null || resNumMap.isEmpty())
778 Integer[] keys = resNumMap.keySet().toArray(new Integer[0]);
779 // Arrays.sort(keys);
780 int firstIndex = keys[0];
781 int lastIndex = keys[keys.length - 1];
782 // System.out.println("Min value " + firstIndex);
783 // System.out.println("Max value " + lastIndex);
784 for (int x = firstIndex; x <= lastIndex; x++)
786 if (!resNumMap.containsKey(x) && !omitNonObserved.contains(x))
788 resNumMap.put(x, "-");
794 public Entity getEntityById(String id) throws SiftsException
796 // Determines an entity to process by performing a heuristic matching of all
797 // Entities with the given chainId and choosing the best matching Entity
798 Entity entity = getEntityByMostOptimalMatchedId(id);
803 throw new SiftsException("Entity " + id + " not found");
807 * This method was added because EntityId is NOT always equal to ChainId.
808 * Hence, it provides the logic to greedily detect the "true" Entity for a
809 * given chainId where discrepancies exist.
814 public Entity getEntityByMostOptimalMatchedId(String chainId)
816 // System.out.println("---> advanced greedy entityId matching block entered..");
817 List<Entity> entities = siftsEntry.getEntity();
818 SiftsEntitySortPojo[] sPojo = new SiftsEntitySortPojo[entities.size()];
820 for (Entity entity : entities)
822 sPojo[count] = new SiftsEntitySortPojo();
823 sPojo[count].entityId = entity.getEntityId();
825 List<Segment> segments = entity.getSegment();
826 for (Segment segment : segments)
828 List<Residue> residues = segment.getListResidue().getResidue();
829 for (Residue residue : residues)
831 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
832 for (CrossRefDb cRefDb : cRefDbs)
834 if (!cRefDb.getDbSource().equalsIgnoreCase("PDB"))
838 ++sPojo[count].resCount;
839 if (cRefDb.getDbChainId().equalsIgnoreCase(chainId))
841 ++sPojo[count].chainIdFreq;
846 sPojo[count].pid = (100 * sPojo[count].chainIdFreq)
847 / sPojo[count].resCount;
850 Arrays.sort(sPojo, Collections.reverseOrder());
851 // System.out.println("highest matched entity : " + sPojo[0].entityId);
852 // System.out.println("highest matched pid : " + sPojo[0].pid);
854 if (sPojo[0].entityId != null)
856 if (sPojo[0].pid < 1)
860 for (Entity entity : entities)
862 if (!entity.getEntityId().equalsIgnoreCase(sPojo[0].entityId))
872 private class SiftsEntitySortPojo implements
873 Comparable<SiftsEntitySortPojo>
875 public String entityId;
877 public int chainIdFreq;
884 public int compareTo(SiftsEntitySortPojo o)
886 return this.pid - o.pid;
890 private class SegmentHelperPojo
892 private SequenceI seq;
894 private HashMap<Integer, int[]> mapping;
896 private TreeMap<Integer, String> resNumMap;
898 private List<Integer> omitNonObserved;
900 private int nonObservedShiftIndex;
902 public SegmentHelperPojo(SequenceI seq,
903 HashMap<Integer, int[]> mapping,
904 TreeMap<Integer, String> resNumMap,
905 List<Integer> omitNonObserved, int nonObservedShiftIndex)
909 setResNumMap(resNumMap);
910 setOmitNonObserved(omitNonObserved);
911 setNonObservedShiftIndex(nonObservedShiftIndex);
914 public SequenceI getSeq()
919 public void setSeq(SequenceI seq)
924 public HashMap<Integer, int[]> getMapping()
929 public void setMapping(HashMap<Integer, int[]> mapping)
931 this.mapping = mapping;
934 public TreeMap<Integer, String> getResNumMap()
939 public void setResNumMap(TreeMap<Integer, String> resNumMap)
941 this.resNumMap = resNumMap;
944 public List<Integer> getOmitNonObserved()
946 return omitNonObserved;
949 public void setOmitNonObserved(List<Integer> omitNonObserved)
951 this.omitNonObserved = omitNonObserved;
954 public int getNonObservedShiftIndex()
956 return nonObservedShiftIndex;
959 public void setNonObservedShiftIndex(int nonObservedShiftIndex)
961 this.nonObservedShiftIndex = nonObservedShiftIndex;
966 public StringBuilder getMappingOutput(MappingOutputPojo mp)
967 throws SiftsException
969 String seqRes = mp.getSeqResidue();
970 String seqName = mp.getSeqName();
971 int sStart = mp.getSeqStart();
972 int sEnd = mp.getSeqEnd();
974 String strRes = mp.getStrResidue();
975 String strName = mp.getStrName();
976 int pdbStart = mp.getStrStart();
977 int pdbEnd = mp.getStrEnd();
979 String type = mp.getType();
981 int maxid = (seqName.length() >= strName.length()) ? seqName.length()
983 int len = 72 - maxid - 1;
985 int nochunks = ((seqRes.length()) / len)
986 + ((seqRes.length()) % len > 0 ? 1 : 0);
988 StringBuilder output = new StringBuilder(512);
989 output.append(NEWLINE);
990 output.append("Sequence \u27f7 Structure mapping details").append(
992 output.append("Method: SIFTS");
993 output.append(NEWLINE).append(NEWLINE);
995 output.append(new Format("%" + maxid + "s").form(seqName));
996 output.append(" : ");
997 output.append(String.valueOf(sStart));
998 output.append(" - ");
999 output.append(String.valueOf(sEnd));
1000 output.append(" Maps to ");
1001 output.append(NEWLINE);
1002 output.append(new Format("%" + maxid + "s").form(structId));
1003 output.append(" : ");
1004 output.append(String.valueOf(pdbStart));
1005 output.append(" - ");
1006 output.append(String.valueOf(pdbEnd));
1007 output.append(NEWLINE).append(NEWLINE);
1009 ScoreMatrix pam250 = ScoreModels.getInstance().getPam250();
1010 int matchedSeqCount = 0;
1011 for (int j = 0; j < nochunks; j++)
1013 // Print the first aligned sequence
1014 output.append(new Format("%" + (maxid) + "s").form(seqName)).append(
1017 for (int i = 0; i < len; i++)
1019 if ((i + (j * len)) < seqRes.length())
1021 output.append(seqRes.charAt(i + (j * len)));
1025 output.append(NEWLINE);
1026 output.append(new Format("%" + (maxid) + "s").form(" ")).append(" ");
1029 * Print out the match symbols:
1030 * | for exact match (ignoring case)
1031 * . if PAM250 score is positive
1034 for (int i = 0; i < len; i++)
1038 if ((i + (j * len)) < seqRes.length())
1040 char c1 = seqRes.charAt(i + (j * len));
1041 char c2 = strRes.charAt(i + (j * len));
1042 boolean sameChar = Comparison.isSameResidue(c1, c2, false);
1043 if (sameChar && !Comparison.isGap(c1))
1048 else if (type.equals("pep"))
1050 if (pam250.getPairwiseScore(c1, c2) > 0)
1064 } catch (IndexOutOfBoundsException e)
1069 // Now print the second aligned sequence
1070 output = output.append(NEWLINE);
1071 output = output.append(new Format("%" + (maxid) + "s").form(strName))
1073 for (int i = 0; i < len; i++)
1075 if ((i + (j * len)) < strRes.length())
1077 output.append(strRes.charAt(i + (j * len)));
1080 output.append(NEWLINE).append(NEWLINE);
1082 float pid = (float) matchedSeqCount / seqRes.length() * 100;
1083 if (pid < SiftsSettings.getFailSafePIDThreshold())
1085 throw new SiftsException(">>> Low PID detected for SIFTs mapping...");
1087 output.append("Length of alignment = " + seqRes.length()).append(
1089 output.append(new Format("Percentage ID = %2.2f").form(pid));
1094 public int getEntityCount()
1096 return siftsEntry.getEntity().size();
1100 public String getDbAccessionId()
1102 return siftsEntry.getDbAccessionId();
1106 public String getDbCoordSys()
1108 return siftsEntry.getDbCoordSys();
1112 public String getDbSource()
1114 return siftsEntry.getDbSource();
1118 public String getDbVersion()
1120 return siftsEntry.getDbVersion();
1123 public static void setMockSiftsFile(File file)
1125 mockSiftsFile = file;