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
78 * for use in mocking out file fetch for tests only
79 * - reset to null after testing!
81 private static File mockSiftsFile;
83 private Entry siftsEntry;
85 private StructureFile pdb;
89 private String structId;
91 private CoordinateSys seqCoordSys = CoordinateSys.UNIPROT;
93 private static final int BUFFER_SIZE = 4096;
95 public static final int UNASSIGNED = -1;
97 private static final int PDB_RES_POS = 0;
99 private static final int PDB_ATOM_POS = 1;
101 private static final String NOT_OBSERVED = "Not_Observed";
103 private static final String SIFTS_FTP_BASE_URL = "http://ftp.ebi.ac.uk/pub/databases/msd/sifts/xml/";
105 private final static String NEWLINE = System.lineSeparator();
107 private String curSourceDBRef;
109 private HashSet<String> curDBRefAccessionIdsString;
111 private enum CoordinateSys
113 UNIPROT("UniProt"), PDB("PDBresnum"), PDBe("PDBe");
116 private CoordinateSys(String name)
121 public String getName()
127 private enum ResidueDetailType
129 NAME_SEC_STRUCTURE("nameSecondaryStructure"), CODE_SEC_STRUCTURE(
130 "codeSecondaryStructure"), ANNOTATION("Annotation");
133 private ResidueDetailType(String code)
138 public String getCode()
145 * Fetch SIFTs file for the given PDBfile and construct an instance of
149 * @throws SiftsException
151 public SiftsClient(StructureFile pdb) throws SiftsException
154 this.pdbId = pdb.getId();
155 File siftsFile = getSiftsFile(pdbId);
156 siftsEntry = parseSIFTs(siftsFile);
160 * Parse the given SIFTs File and return a JAXB POJO of parsed data
163 * - the GZipped SIFTs XML file to parse
166 * if a problem occurs while parsing the SIFTs XML
168 private Entry parseSIFTs(File siftFile) throws SiftsException
170 try (InputStream in = new FileInputStream(siftFile);
171 GZIPInputStream gzis = new GZIPInputStream(in);)
173 // System.out.println("File : " + siftFile.getAbsolutePath());
174 JAXBContext jc = JAXBContext.newInstance("jalview.xml.binding.sifts");
175 XMLStreamReader streamReader = XMLInputFactory.newInstance()
176 .createXMLStreamReader(gzis);
177 Unmarshaller um = jc.createUnmarshaller();
178 return (Entry) um.unmarshal(streamReader);
179 } catch (Exception e)
182 throw new SiftsException(e.getMessage());
187 * Get a SIFTs XML file for a given PDB Id from Cache or download from FTP
188 * repository if not found in cache
191 * @return SIFTs XML file
192 * @throws SiftsException
194 public static File getSiftsFile(String pdbId) throws SiftsException
197 * return mocked file if it has been set
199 if (mockSiftsFile != null)
201 return mockSiftsFile;
204 String siftsFileName = SiftsSettings.getSiftDownloadDirectory()
205 + pdbId.toLowerCase() + ".xml.gz";
206 File siftsFile = new File(siftsFileName);
207 if (siftsFile.exists())
209 // The line below is required for unit testing... don't comment it out!!!
210 System.out.println(">>> SIFTS File already downloaded for " + pdbId);
212 if (isFileOlderThanThreshold(siftsFile,
213 SiftsSettings.getCacheThresholdInDays()))
215 File oldSiftsFile = new File(siftsFileName + "_old");
216 siftsFile.renameTo(oldSiftsFile);
219 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
220 oldSiftsFile.delete();
222 } catch (IOException e)
225 oldSiftsFile.renameTo(siftsFile);
226 return new File(siftsFileName);
232 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
233 } catch (IOException e)
235 throw new SiftsException(e.getMessage());
241 * This method enables checking if a cached file has exceeded a certain
247 * the threshold in days
250 public static boolean isFileOlderThanThreshold(File file, int noOfDays)
252 Path filePath = file.toPath();
253 BasicFileAttributes attr;
257 attr = Files.readAttributes(filePath, BasicFileAttributes.class);
258 diffInDays = (int) ((new Date().getTime() - attr.lastModifiedTime()
259 .toMillis()) / (1000 * 60 * 60 * 24));
260 // System.out.println("Diff in days : " + diffInDays);
261 } catch (IOException e)
265 return noOfDays <= diffInDays;
269 * Download a SIFTs XML file for a given PDB Id from an FTP repository
272 * @return downloaded SIFTs XML file
273 * @throws SiftsException
274 * @throws IOException
276 public static File downloadSiftsFile(String pdbId) throws SiftsException,
279 if (pdbId.contains(".cif"))
281 pdbId = pdbId.replace(".cif", "");
283 String siftFile = pdbId + ".xml.gz";
284 String siftsFileFTPURL = SIFTS_FTP_BASE_URL + siftFile;
285 String downloadedSiftsFile = SiftsSettings.getSiftDownloadDirectory()
287 File siftsDownloadDir = new File(
288 SiftsSettings.getSiftDownloadDirectory());
289 if (!siftsDownloadDir.exists())
291 siftsDownloadDir.mkdirs();
293 // System.out.println(">> Download ftp url : " + siftsFileFTPURL);
294 URL url = new URL(siftsFileFTPURL);
295 URLConnection conn = url.openConnection();
296 InputStream inputStream = conn.getInputStream();
297 FileOutputStream outputStream = new FileOutputStream(
298 downloadedSiftsFile);
299 byte[] buffer = new byte[BUFFER_SIZE];
301 while ((bytesRead = inputStream.read(buffer)) != -1)
303 outputStream.write(buffer, 0, bytesRead);
305 outputStream.close();
307 // System.out.println(">>> File downloaded : " + downloadedSiftsFile);
308 return new File(downloadedSiftsFile);
312 * Delete the SIFTs file for the given PDB Id in the local SIFTs download
316 * @return true if the file was deleted or doesn't exist
318 public static boolean deleteSiftsFileByPDBId(String pdbId)
320 File siftsFile = new File(SiftsSettings.getSiftDownloadDirectory()
321 + pdbId.toLowerCase() + ".xml.gz");
322 if (siftsFile.exists())
324 return siftsFile.delete();
330 * Get a valid SIFTs DBRef for the given sequence current SIFTs entry
333 * - the target sequence for the operation
334 * @return a valid DBRefEntry that is SIFTs compatible
336 * if no valid source DBRefEntry was found for the given sequences
338 public DBRefEntryI getValidSourceDBRef(SequenceI seq)
339 throws SiftsException
341 List<DBRefEntry> dbRefs = seq.getPrimaryDBRefs();
342 if (dbRefs == null || dbRefs.size() < 1)
344 throw new SiftsException(
345 "Source DBRef could not be determined. DBRefs might not have been retrieved.");
348 for (DBRefEntry dbRef : dbRefs)
350 if (dbRef == null || dbRef.getAccessionId() == null
351 || dbRef.getSource() == null)
355 String canonicalSource = DBRefUtils.getCanonicalName(dbRef
357 if (isValidDBRefEntry(dbRef)
358 && (canonicalSource.equalsIgnoreCase(DBRefSource.UNIPROT) || canonicalSource
359 .equalsIgnoreCase(DBRefSource.PDB)))
364 throw new SiftsException("Could not get source DB Ref");
368 * Check that the DBRef Entry is properly populated and is available in this
369 * SiftClient instance
372 * - DBRefEntry to validate
373 * @return true validation is successful otherwise false is returned.
375 boolean isValidDBRefEntry(DBRefEntryI entry)
377 return entry != null && entry.getAccessionId() != null
378 && isFoundInSiftsEntry(entry.getAccessionId());
382 public HashSet<String> getAllMappingAccession()
384 HashSet<String> accessions = new HashSet<String>();
385 List<Entity> entities = siftsEntry.getEntity();
386 for (Entity entity : entities)
388 List<Segment> segments = entity.getSegment();
389 for (Segment segment : segments)
391 List<MapRegion> mapRegions = segment.getListMapRegion()
393 for (MapRegion mapRegion : mapRegions)
396 .add(mapRegion.getDb().getDbAccessionId().toLowerCase());
404 public StructureMapping getSiftsStructureMapping(SequenceI seq,
405 String pdbFile, String chain) throws SiftsException
407 structId = (chain == null) ? pdbId : pdbId + "|" + chain;
408 System.out.println("Getting SIFTS mapping for " + structId + ": seq "
411 final StringBuilder mappingDetails = new StringBuilder(128);
412 PrintStream ps = new PrintStream(System.out)
415 public void print(String x)
417 mappingDetails.append(x);
421 public void println()
423 mappingDetails.append(NEWLINE);
426 HashMap<Integer, int[]> mapping = getGreedyMapping(chain, seq, ps);
428 String mappingOutput = mappingDetails.toString();
429 StructureMapping siftsMapping = new StructureMapping(seq, pdbFile,
430 pdbId, chain, mapping, mappingOutput);
435 public HashMap<Integer, int[]> getGreedyMapping(String entityId,
436 SequenceI seq, java.io.PrintStream os) throws SiftsException
438 List<Integer> omitNonObserved = new ArrayList<Integer>();
439 int nonObservedShiftIndex = 0;
440 // System.out.println("Generating mappings for : " + entityId);
441 Entity entity = null;
442 entity = getEntityById(entityId);
443 String originalSeq = AlignSeq.extractGaps(
444 jalview.util.Comparison.GapChars, seq.getSequenceAsString());
445 HashMap<Integer, int[]> mapping = new HashMap<Integer, int[]>();
446 DBRefEntryI sourceDBRef;
447 sourceDBRef = getValidSourceDBRef(seq);
448 // TODO ensure sequence start/end is in the same coordinate system and
449 // consistent with the choosen sourceDBRef
451 // set sequence coordinate system - default value is UniProt
452 if (sourceDBRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
454 seqCoordSys = CoordinateSys.PDB;
457 HashSet<String> dbRefAccessionIdsString = new HashSet<String>();
458 for (DBRefEntry dbref : seq.getDBRefs())
460 dbRefAccessionIdsString.add(dbref.getAccessionId().toLowerCase());
462 dbRefAccessionIdsString.add(sourceDBRef.getAccessionId().toLowerCase());
464 curDBRefAccessionIdsString = dbRefAccessionIdsString;
465 curSourceDBRef = sourceDBRef.getAccessionId();
467 TreeMap<Integer, String> resNumMap = new TreeMap<Integer, String>();
468 List<Segment> segments = entity.getSegment();
469 SegmentHelperPojo shp = new SegmentHelperPojo(seq, mapping, resNumMap,
470 omitNonObserved, nonObservedShiftIndex);
471 processSegments(segments, shp);
474 populateAtomPositions(entityId, mapping);
475 } catch (Exception e)
479 if (seqCoordSys == CoordinateSys.UNIPROT)
481 padWithGaps(resNumMap, omitNonObserved);
483 int seqStart = UNASSIGNED;
484 int seqEnd = UNASSIGNED;
485 int pdbStart = UNASSIGNED;
486 int pdbEnd = UNASSIGNED;
488 if (mapping.isEmpty())
490 throw new SiftsException("SIFTS mapping failed");
493 Integer[] keys = mapping.keySet().toArray(new Integer[0]);
496 seqEnd = keys[keys.length - 1];
498 String matchedSeq = originalSeq;
499 if (seqStart != UNASSIGNED)
501 pdbStart = mapping.get(seqStart)[PDB_RES_POS];
502 pdbEnd = mapping.get(seqEnd)[PDB_RES_POS];
503 int orignalSeqStart = seq.getStart();
504 if (orignalSeqStart >= 1)
506 int subSeqStart = (seqStart >= orignalSeqStart) ? seqStart
507 - orignalSeqStart : 0;
508 int subSeqEnd = seqEnd - (orignalSeqStart - 1);
509 subSeqEnd = originalSeq.length() < subSeqEnd ? originalSeq.length()
511 matchedSeq = originalSeq.substring(subSeqStart, subSeqEnd);
515 matchedSeq = originalSeq.substring(1, originalSeq.length());
519 StringBuilder targetStrucSeqs = new StringBuilder();
520 for (String res : resNumMap.values())
522 targetStrucSeqs.append(res);
527 MappingOutputPojo mop = new MappingOutputPojo();
528 mop.setSeqStart(seqStart);
529 mop.setSeqEnd(seqEnd);
530 mop.setSeqName(seq.getName());
531 mop.setSeqResidue(matchedSeq);
533 mop.setStrStart(pdbStart);
534 mop.setStrEnd(pdbEnd);
535 mop.setStrName(structId);
536 mop.setStrResidue(targetStrucSeqs.toString());
539 os.print(getMappingOutput(mop).toString());
545 void processSegments(List<Segment> segments, SegmentHelperPojo shp)
547 SequenceI seq = shp.getSeq();
548 HashMap<Integer, int[]> mapping = shp.getMapping();
549 TreeMap<Integer, String> resNumMap = shp.getResNumMap();
550 List<Integer> omitNonObserved = shp.getOmitNonObserved();
551 int nonObservedShiftIndex = shp.getNonObservedShiftIndex();
552 for (Segment segment : segments)
554 // System.out.println("Mapping segments : " + segment.getSegId() + "\\"s
556 List<Residue> residues = segment.getListResidue().getResidue();
557 for (Residue residue : residues)
559 int currSeqIndex = UNASSIGNED;
560 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
561 CrossRefDb pdbRefDb = null;
562 for (CrossRefDb cRefDb : cRefDbs)
564 if (cRefDb.getDbSource().equalsIgnoreCase(DBRefSource.PDB))
568 if (cRefDb.getDbCoordSys()
569 .equalsIgnoreCase(seqCoordSys.getName())
570 && isAccessionMatched(cRefDb.getDbAccessionId()))
572 String resNumIndexString = cRefDb.getDbResNum()
573 .equalsIgnoreCase("None") ? String.valueOf(UNASSIGNED)
574 : cRefDb.getDbResNum();
577 currSeqIndex = Integer.valueOf(resNumIndexString);
578 } catch (NumberFormatException nfe)
580 currSeqIndex = Integer.valueOf(resNumIndexString
581 .split("[a-zA-Z]")[0]);
584 if (pdbRefDb != null)
586 break;// exit loop if pdb and uniprot are already found
590 if (currSeqIndex == UNASSIGNED)
594 if (currSeqIndex >= seq.getStart() && currSeqIndex <= seq.getEnd())
599 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
600 .getDbResNum()) : Integer.valueOf(pdbRefDb
602 } catch (NumberFormatException nfe)
604 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
605 .getDbResNum()) : Integer.valueOf(pdbRefDb
606 .getDbResNum().split("[a-zA-Z]")[0]);
610 if (isResidueObserved(residue)
611 || seqCoordSys == CoordinateSys.UNIPROT)
613 char resCharCode = ResidueProperties
614 .getSingleCharacterCode(ResidueProperties
615 .getCanonicalAminoAcid(residue.getDbResName()));
616 resNumMap.put(currSeqIndex, String.valueOf(resCharCode));
620 omitNonObserved.add(currSeqIndex);
621 ++nonObservedShiftIndex;
623 mapping.put(currSeqIndex - nonObservedShiftIndex, new int[] {
624 Integer.valueOf(resNum), UNASSIGNED });
633 * Target chain to populate mapping of its atom positions.
635 * Two dimension array of residue index versus atom position
636 * @throws IllegalArgumentException
637 * Thrown if chainId or mapping is null
638 * @throws SiftsException
640 void populateAtomPositions(String chainId, Map<Integer, int[]> mapping)
641 throws IllegalArgumentException, SiftsException
645 PDBChain chain = pdb.findChain(chainId);
647 if (chain == null || mapping == null)
649 throw new IllegalArgumentException(
650 "Chain id or mapping must not be null.");
652 for (int[] map : mapping.values())
654 if (map[PDB_RES_POS] != UNASSIGNED)
656 map[PDB_ATOM_POS] = getAtomIndex(map[PDB_RES_POS], chain.atoms);
659 } catch (NullPointerException e)
661 throw new SiftsException(e.getMessage());
662 } catch (Exception e)
664 throw new SiftsException(e.getMessage());
670 * @param residueIndex
671 * The residue index used for the search
673 * A collection of Atom to search
674 * @return atom position for the given residue index
676 int getAtomIndex(int residueIndex, Collection<Atom> atoms)
680 throw new IllegalArgumentException(
681 "atoms collection must not be null!");
683 for (Atom atom : atoms)
685 if (atom.resNumber == residueIndex)
687 return atom.atomIndex;
694 * Checks if the residue instance is marked 'Not_observed' or not
699 private boolean isResidueObserved(Residue residue)
701 Set<String> annotations = getResidueAnnotaitons(residue,
702 ResidueDetailType.ANNOTATION);
703 if (annotations == null || annotations.isEmpty())
707 for (String annotation : annotations)
709 if (annotation.equalsIgnoreCase(NOT_OBSERVED))
718 * Get annotation String for a given residue and annotation type
724 private Set<String> getResidueAnnotaitons(Residue residue,
725 ResidueDetailType type)
727 HashSet<String> foundAnnotations = new HashSet<String>();
728 List<ResidueDetail> resDetails = residue.getResidueDetail();
729 for (ResidueDetail resDetail : resDetails)
731 if (resDetail.getProperty().equalsIgnoreCase(type.getCode()))
733 foundAnnotations.add(resDetail.getContent());
736 return foundAnnotations;
740 public boolean isAccessionMatched(String accession)
742 boolean isStrictMatch = true;
743 return isStrictMatch ? curSourceDBRef.equalsIgnoreCase(accession)
744 : curDBRefAccessionIdsString.contains(accession.toLowerCase());
747 private boolean isFoundInSiftsEntry(String accessionId)
749 Set<String> siftsDBRefs = getAllMappingAccession();
750 return accessionId != null
751 && siftsDBRefs.contains(accessionId.toLowerCase());
755 * Pad omitted residue positions in PDB sequence with gaps
759 void padWithGaps(Map<Integer, String> resNumMap,
760 List<Integer> omitNonObserved)
762 if (resNumMap == null || resNumMap.isEmpty())
766 Integer[] keys = resNumMap.keySet().toArray(new Integer[0]);
767 // Arrays.sort(keys);
768 int firstIndex = keys[0];
769 int lastIndex = keys[keys.length - 1];
770 // System.out.println("Min value " + firstIndex);
771 // System.out.println("Max value " + lastIndex);
772 for (int x = firstIndex; x <= lastIndex; x++)
774 if (!resNumMap.containsKey(x) && !omitNonObserved.contains(x))
776 resNumMap.put(x, "-");
782 public Entity getEntityById(String id) throws SiftsException
784 // Determines an entity to process by performing a heuristic matching of all
785 // Entities with the given chainId and choosing the best matching Entity
786 Entity entity = getEntityByMostOptimalMatchedId(id);
791 throw new SiftsException("Entity " + id + " not found");
795 * This method was added because EntityId is NOT always equal to ChainId.
796 * Hence, it provides the logic to greedily detect the "true" Entity for a
797 * given chainId where discrepancies exist.
802 public Entity getEntityByMostOptimalMatchedId(String chainId)
804 // System.out.println("---> advanced greedy entityId matching block entered..");
805 List<Entity> entities = siftsEntry.getEntity();
806 SiftsEntitySortPojo[] sPojo = new SiftsEntitySortPojo[entities.size()];
808 for (Entity entity : entities)
810 sPojo[count] = new SiftsEntitySortPojo();
811 sPojo[count].entityId = entity.getEntityId();
813 List<Segment> segments = entity.getSegment();
814 for (Segment segment : segments)
816 List<Residue> residues = segment.getListResidue().getResidue();
817 for (Residue residue : residues)
819 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
820 for (CrossRefDb cRefDb : cRefDbs)
822 if (!cRefDb.getDbSource().equalsIgnoreCase("PDB"))
826 ++sPojo[count].resCount;
827 if (cRefDb.getDbChainId().equalsIgnoreCase(chainId))
829 ++sPojo[count].chainIdFreq;
834 sPojo[count].pid = (100 * sPojo[count].chainIdFreq)
835 / sPojo[count].resCount;
838 Arrays.sort(sPojo, Collections.reverseOrder());
839 // System.out.println("highest matched entity : " + sPojo[0].entityId);
840 // System.out.println("highest matched pid : " + sPojo[0].pid);
842 if (sPojo[0].entityId != null)
844 if (sPojo[0].pid < 1)
848 for (Entity entity : entities)
850 if (!entity.getEntityId().equalsIgnoreCase(sPojo[0].entityId))
860 private class SiftsEntitySortPojo implements
861 Comparable<SiftsEntitySortPojo>
863 public String entityId;
865 public int chainIdFreq;
872 public int compareTo(SiftsEntitySortPojo o)
874 return this.pid - o.pid;
878 private class SegmentHelperPojo
880 private SequenceI seq;
882 private HashMap<Integer, int[]> mapping;
884 private TreeMap<Integer, String> resNumMap;
886 private List<Integer> omitNonObserved;
888 private int nonObservedShiftIndex;
890 public SegmentHelperPojo(SequenceI seq,
891 HashMap<Integer, int[]> mapping,
892 TreeMap<Integer, String> resNumMap,
893 List<Integer> omitNonObserved, int nonObservedShiftIndex)
897 setResNumMap(resNumMap);
898 setOmitNonObserved(omitNonObserved);
899 setNonObservedShiftIndex(nonObservedShiftIndex);
902 public SequenceI getSeq()
907 public void setSeq(SequenceI seq)
912 public HashMap<Integer, int[]> getMapping()
917 public void setMapping(HashMap<Integer, int[]> mapping)
919 this.mapping = mapping;
922 public TreeMap<Integer, String> getResNumMap()
927 public void setResNumMap(TreeMap<Integer, String> resNumMap)
929 this.resNumMap = resNumMap;
932 public List<Integer> getOmitNonObserved()
934 return omitNonObserved;
937 public void setOmitNonObserved(List<Integer> omitNonObserved)
939 this.omitNonObserved = omitNonObserved;
942 public int getNonObservedShiftIndex()
944 return nonObservedShiftIndex;
947 public void setNonObservedShiftIndex(int nonObservedShiftIndex)
949 this.nonObservedShiftIndex = nonObservedShiftIndex;
954 public StringBuffer getMappingOutput(MappingOutputPojo mp)
955 throws SiftsException
957 String seqRes = mp.getSeqResidue();
958 String seqName = mp.getSeqName();
959 int sStart = mp.getSeqStart();
960 int sEnd = mp.getSeqEnd();
962 String strRes = mp.getStrResidue();
963 String strName = mp.getStrName();
964 int pdbStart = mp.getStrStart();
965 int pdbEnd = mp.getStrEnd();
967 String type = mp.getType();
969 int maxid = (seqName.length() >= strName.length()) ? seqName.length()
971 int len = 72 - maxid - 1;
973 int nochunks = ((seqRes.length()) / len)
974 + ((seqRes.length()) % len > 0 ? 1 : 0);
976 StringBuffer output = new StringBuffer();
977 output.append(NEWLINE);
978 output.append("Sequence \u27f7 Structure mapping details").append(
980 output.append("Method: SIFTS");
981 output.append(NEWLINE).append(NEWLINE);
983 output.append(new Format("%" + maxid + "s").form(seqName));
984 output.append(" : ");
985 output.append(String.valueOf(sStart));
986 output.append(" - ");
987 output.append(String.valueOf(sEnd));
988 output.append(" Maps to ");
989 output.append(NEWLINE);
990 output.append(new Format("%" + maxid + "s").form(structId));
991 output.append(" : ");
992 output.append(String.valueOf(pdbStart));
993 output.append(" - ");
994 output.append(String.valueOf(pdbEnd));
995 output.append(NEWLINE).append(NEWLINE);
997 int matchedSeqCount = 0;
998 for (int j = 0; j < nochunks; j++)
1000 // Print the first aligned sequence
1001 output.append(new Format("%" + (maxid) + "s").form(seqName)).append(
1004 for (int i = 0; i < len; i++)
1006 if ((i + (j * len)) < seqRes.length())
1008 output.append(seqRes.charAt(i + (j * len)));
1012 output.append(NEWLINE);
1013 output.append(new Format("%" + (maxid) + "s").form(" ")).append(" ");
1015 // Print out the matching chars
1016 for (int i = 0; i < len; i++)
1020 if ((i + (j * len)) < seqRes.length())
1022 boolean sameChar = Comparison.isSameResidue(
1023 seqRes.charAt(i + (j * len)),
1024 strRes.charAt(i + (j * len)), false);
1026 && !jalview.util.Comparison.isGap(seqRes.charAt(i
1032 else if (type.equals("pep"))
1034 if (ResidueProperties.getPAM250(seqRes.charAt(i + (j * len)),
1035 strRes.charAt(i + (j * len))) > 0)
1049 } catch (IndexOutOfBoundsException e)
1054 // Now print the second aligned sequence
1055 output = output.append(NEWLINE);
1056 output = output.append(new Format("%" + (maxid) + "s").form(strName))
1058 for (int i = 0; i < len; i++)
1060 if ((i + (j * len)) < strRes.length())
1062 output.append(strRes.charAt(i + (j * len)));
1065 output.append(NEWLINE).append(NEWLINE);
1067 float pid = (float) matchedSeqCount / seqRes.length() * 100;
1068 if (pid < SiftsSettings.getFailSafePIDThreshold())
1070 throw new SiftsException(">>> Low PID detected for SIFTs mapping...");
1072 output.append("Length of alignment = " + seqRes.length()).append(
1074 output.append(new Format("Percentage ID = %2.2f").form(pid));
1079 public int getEntityCount()
1081 return siftsEntry.getEntity().size();
1085 public String getDbAccessionId()
1087 return siftsEntry.getDbAccessionId();
1091 public String getDbCoordSys()
1093 return siftsEntry.getDbCoordSys();
1097 public String getDbSource()
1099 return siftsEntry.getDbSource();
1103 public String getDbVersion()
1105 return siftsEntry.getDbVersion();
1108 public static void setMockSiftsFile(File file)
1110 mockSiftsFile = file;