2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.ws.sifts;
23 import jalview.analysis.AlignSeq;
24 import jalview.api.DBRefEntryI;
25 import jalview.api.SiftsClientI;
26 import jalview.datamodel.DBRefEntry;
27 import jalview.datamodel.DBRefSource;
28 import jalview.datamodel.SequenceI;
29 import jalview.io.StructureFile;
30 import jalview.schemes.ResidueProperties;
31 import jalview.structure.StructureMapping;
32 import jalview.util.Comparison;
33 import jalview.util.DBRefUtils;
34 import jalview.util.Format;
35 import jalview.xml.binding.sifts.Entry;
36 import jalview.xml.binding.sifts.Entry.Entity;
37 import jalview.xml.binding.sifts.Entry.Entity.Segment;
38 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListMapRegion.MapRegion;
39 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue;
40 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.CrossRefDb;
41 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.ResidueDetail;
44 import java.io.FileInputStream;
45 import java.io.FileOutputStream;
46 import java.io.IOException;
47 import java.io.InputStream;
48 import java.io.PrintStream;
50 import java.net.URLConnection;
51 import java.nio.file.Files;
52 import java.nio.file.Path;
53 import java.nio.file.attribute.BasicFileAttributes;
54 import java.util.ArrayList;
55 import java.util.Arrays;
56 import java.util.Collection;
57 import java.util.Collections;
58 import java.util.Date;
59 import java.util.HashMap;
60 import java.util.HashSet;
61 import java.util.List;
64 import java.util.TreeMap;
65 import java.util.zip.GZIPInputStream;
67 import javax.xml.bind.JAXBContext;
68 import javax.xml.bind.Unmarshaller;
69 import javax.xml.stream.XMLInputFactory;
70 import javax.xml.stream.XMLStreamReader;
73 import MCview.PDBChain;
75 public class SiftsClient implements SiftsClientI
77 private Entry siftsEntry;
79 private StructureFile pdb;
83 private String structId;
85 private CoordinateSys seqCoordSys = CoordinateSys.UNIPROT;
87 private static final int BUFFER_SIZE = 4096;
89 public static final int UNASSIGNED = -1;
91 private static final int PDB_RES_POS = 0;
93 private static final int PDB_ATOM_POS = 1;
95 private static final String NOT_OBSERVED = "Not_Observed";
97 private static final String SIFTS_FTP_BASE_URL = "http://ftp.ebi.ac.uk/pub/databases/msd/sifts/xml/";
99 private final static String NEWLINE = System.lineSeparator();
101 private String curSourceDBRef;
103 private HashSet<String> curDBRefAccessionIdsString;
105 private enum CoordinateSys
107 UNIPROT("UniProt"), PDB("PDBresnum"), PDBe("PDBe");
110 private CoordinateSys(String name)
115 public String getName()
121 private enum ResidueDetailType
123 NAME_SEC_STRUCTURE("nameSecondaryStructure"), CODE_SEC_STRUCTURE(
124 "codeSecondaryStructure"), ANNOTATION("Annotation");
127 private ResidueDetailType(String code)
132 public String getCode()
139 * Fetch SIFTs file for the given PDBfile and construct an instance of
143 * @throws SiftsException
145 public SiftsClient(StructureFile pdb) throws SiftsException
148 this.pdbId = pdb.getId();
149 File siftsFile = getSiftsFile(pdbId);
150 siftsEntry = parseSIFTs(siftsFile);
154 * Parse the given SIFTs File and return a JAXB POJO of parsed data
157 * - the GZipped SIFTs XML file to parse
160 * if a problem occurs while parsing the SIFTs XML
162 private Entry parseSIFTs(File siftFile) throws SiftsException
164 try (InputStream in = new FileInputStream(siftFile);
165 GZIPInputStream gzis = new GZIPInputStream(in);)
167 // System.out.println("File : " + siftFile.getAbsolutePath());
168 JAXBContext jc = JAXBContext.newInstance("jalview.xml.binding.sifts");
169 XMLStreamReader streamReader = XMLInputFactory.newInstance()
170 .createXMLStreamReader(gzis);
171 Unmarshaller um = jc.createUnmarshaller();
172 return (Entry) um.unmarshal(streamReader);
173 } catch (Exception e)
176 throw new SiftsException(e.getMessage());
181 * Get a SIFTs XML file for a given PDB Id from Cache or download from FTP
182 * repository if not found in cache
185 * @return SIFTs XML file
186 * @throws SiftsException
188 public static File getSiftsFile(String pdbId) throws SiftsException
190 String siftsFileName = SiftsSettings.getSiftDownloadDirectory()
191 + pdbId.toLowerCase() + ".xml.gz";
192 File siftsFile = new File(siftsFileName);
193 if (siftsFile.exists())
195 // The line below is required for unit testing... don't comment it out!!!
196 System.out.println(">>> SIFTS File already downloaded for " + pdbId);
198 if (isFileOlderThanThreshold(siftsFile,
199 SiftsSettings.getCacheThresholdInDays()))
201 File oldSiftsFile = new File(siftsFileName + "_old");
202 siftsFile.renameTo(oldSiftsFile);
205 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
206 oldSiftsFile.delete();
208 } catch (IOException e)
211 oldSiftsFile.renameTo(siftsFile);
212 return new File(siftsFileName);
218 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
219 } catch (IOException e)
221 throw new SiftsException(e.getMessage());
227 * This method enables checking if a cached file has exceeded a certain
233 * the threshold in days
236 public static boolean isFileOlderThanThreshold(File file, int noOfDays)
238 Path filePath = file.toPath();
239 BasicFileAttributes attr;
243 attr = Files.readAttributes(filePath, BasicFileAttributes.class);
244 diffInDays = (int) ((new Date().getTime() - attr.lastModifiedTime()
245 .toMillis()) / (1000 * 60 * 60 * 24));
246 // System.out.println("Diff in days : " + diffInDays);
247 } catch (IOException e)
251 return noOfDays <= diffInDays;
255 * Download a SIFTs XML file for a given PDB Id from an FTP repository
258 * @return downloaded SIFTs XML file
259 * @throws SiftsException
260 * @throws IOException
262 public static File downloadSiftsFile(String pdbId) throws SiftsException,
265 if (pdbId.contains(".cif"))
267 pdbId = pdbId.replace(".cif", "");
269 String siftFile = pdbId + ".xml.gz";
270 String siftsFileFTPURL = SIFTS_FTP_BASE_URL + siftFile;
271 String downloadedSiftsFile = SiftsSettings.getSiftDownloadDirectory()
273 File siftsDownloadDir = new File(
274 SiftsSettings.getSiftDownloadDirectory());
275 if (!siftsDownloadDir.exists())
277 siftsDownloadDir.mkdirs();
279 // System.out.println(">> Download ftp url : " + siftsFileFTPURL);
280 URL url = new URL(siftsFileFTPURL);
281 URLConnection conn = url.openConnection();
282 InputStream inputStream = conn.getInputStream();
283 FileOutputStream outputStream = new FileOutputStream(
284 downloadedSiftsFile);
285 byte[] buffer = new byte[BUFFER_SIZE];
287 while ((bytesRead = inputStream.read(buffer)) != -1)
289 outputStream.write(buffer, 0, bytesRead);
291 outputStream.close();
293 // System.out.println(">>> File downloaded : " + downloadedSiftsFile);
294 return new File(downloadedSiftsFile);
298 * Delete the SIFTs file for the given PDB Id in the local SIFTs download
302 * @return true if the file was deleted or doesn't exist
304 public static boolean deleteSiftsFileByPDBId(String pdbId)
306 File siftsFile = new File(SiftsSettings.getSiftDownloadDirectory()
307 + pdbId.toLowerCase() + ".xml.gz");
308 if (siftsFile.exists())
310 return siftsFile.delete();
316 * Get a valid SIFTs DBRef for the given sequence current SIFTs entry
319 * - the target sequence for the operation
320 * @return a valid DBRefEntry that is SIFTs compatible
322 * if no valid source DBRefEntry was found for the given sequences
324 public DBRefEntryI getValidSourceDBRef(SequenceI seq)
325 throws SiftsException
327 List<DBRefEntry> dbRefs = seq.getPrimaryDBRefs();
328 if (dbRefs == null || dbRefs.size() < 1)
330 throw new SiftsException(
331 "Source DBRef could not be determined. DBRefs might not have been retrieved.");
334 for (DBRefEntry dbRef : dbRefs)
336 if (dbRef == null || dbRef.getAccessionId() == null
337 || dbRef.getSource() == null)
341 String canonicalSource = DBRefUtils.getCanonicalName(dbRef
343 if (isValidDBRefEntry(dbRef)
344 && (canonicalSource.equalsIgnoreCase(DBRefSource.UNIPROT) || canonicalSource
345 .equalsIgnoreCase(DBRefSource.PDB)))
350 throw new SiftsException("Could not get source DB Ref");
354 * Check that the DBRef Entry is properly populated and is available in this
355 * SiftClient instance
358 * - DBRefEntry to validate
359 * @return true validation is successful otherwise false is returned.
361 boolean isValidDBRefEntry(DBRefEntryI entry)
363 return entry != null && entry.getAccessionId() != null
364 && isFoundInSiftsEntry(entry.getAccessionId());
368 public HashSet<String> getAllMappingAccession()
370 HashSet<String> accessions = new HashSet<String>();
371 List<Entity> entities = siftsEntry.getEntity();
372 for (Entity entity : entities)
374 List<Segment> segments = entity.getSegment();
375 for (Segment segment : segments)
377 List<MapRegion> mapRegions = segment.getListMapRegion()
379 for (MapRegion mapRegion : mapRegions)
382 .add(mapRegion.getDb().getDbAccessionId().toLowerCase());
390 public StructureMapping getSiftsStructureMapping(SequenceI seq,
391 String pdbFile, String chain) throws SiftsException
393 structId = (chain == null) ? pdbId : pdbId + "|" + chain;
394 System.out.println("Getting SIFTS mapping for " + structId + ": seq "
397 final StringBuilder mappingDetails = new StringBuilder(128);
398 PrintStream ps = new PrintStream(System.out)
401 public void print(String x)
403 mappingDetails.append(x);
407 public void println()
409 mappingDetails.append(NEWLINE);
412 HashMap<Integer, int[]> mapping = getGreedyMapping(chain, seq, ps);
414 String mappingOutput = mappingDetails.toString();
415 StructureMapping siftsMapping = new StructureMapping(seq, pdbFile,
416 pdbId, chain, mapping, mappingOutput);
421 public HashMap<Integer, int[]> getGreedyMapping(String entityId,
422 SequenceI seq, java.io.PrintStream os) throws SiftsException
424 List<Integer> omitNonObserved = new ArrayList<Integer>();
425 int nonObservedShiftIndex = 0;
426 // System.out.println("Generating mappings for : " + entityId);
427 Entity entity = null;
428 entity = getEntityById(entityId);
429 String originalSeq = AlignSeq.extractGaps(
430 jalview.util.Comparison.GapChars, seq.getSequenceAsString());
431 HashMap<Integer, int[]> mapping = new HashMap<Integer, int[]>();
432 DBRefEntryI sourceDBRef;
433 sourceDBRef = getValidSourceDBRef(seq);
434 // TODO ensure sequence start/end is in the same coordinate system and
435 // consistent with the choosen sourceDBRef
437 // set sequence coordinate system - default value is UniProt
438 if (sourceDBRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
440 seqCoordSys = CoordinateSys.PDB;
443 HashSet<String> dbRefAccessionIdsString = new HashSet<String>();
444 for (DBRefEntry dbref : seq.getDBRefs())
446 dbRefAccessionIdsString.add(dbref.getAccessionId().toLowerCase());
448 dbRefAccessionIdsString.add(sourceDBRef.getAccessionId().toLowerCase());
450 curDBRefAccessionIdsString = dbRefAccessionIdsString;
451 curSourceDBRef = sourceDBRef.getAccessionId();
453 TreeMap<Integer, String> resNumMap = new TreeMap<Integer, String>();
454 List<Segment> segments = entity.getSegment();
455 SegmentHelperPojo shp = new SegmentHelperPojo(seq, mapping, resNumMap,
456 omitNonObserved, nonObservedShiftIndex);
457 processSegments(segments, shp);
460 populateAtomPositions(entityId, mapping);
461 } catch (Exception e)
465 if (seqCoordSys == CoordinateSys.UNIPROT)
467 padWithGaps(resNumMap, omitNonObserved);
469 int seqStart = UNASSIGNED;
470 int seqEnd = UNASSIGNED;
471 int pdbStart = UNASSIGNED;
472 int pdbEnd = UNASSIGNED;
474 if (mapping.isEmpty())
476 throw new SiftsException("SIFTS mapping failed");
479 Integer[] keys = mapping.keySet().toArray(new Integer[0]);
482 seqEnd = keys[keys.length - 1];
484 String matchedSeq = originalSeq;
485 if (seqStart != UNASSIGNED)
487 pdbStart = mapping.get(seqStart)[PDB_RES_POS];
488 pdbEnd = mapping.get(seqEnd)[PDB_RES_POS];
489 int orignalSeqStart = seq.getStart();
490 if (orignalSeqStart >= 1)
492 int subSeqStart = (seqStart >= orignalSeqStart) ? seqStart
493 - orignalSeqStart : 0;
494 int subSeqEnd = seqEnd - (orignalSeqStart - 1);
495 subSeqEnd = originalSeq.length() < subSeqEnd ? originalSeq.length()
497 matchedSeq = originalSeq.substring(subSeqStart, subSeqEnd);
501 matchedSeq = originalSeq.substring(1, originalSeq.length());
505 StringBuilder targetStrucSeqs = new StringBuilder();
506 for (String res : resNumMap.values())
508 targetStrucSeqs.append(res);
513 MappingOutputPojo mop = new MappingOutputPojo();
514 mop.setSeqStart(seqStart);
515 mop.setSeqEnd(seqEnd);
516 mop.setSeqName(seq.getName());
517 mop.setSeqResidue(matchedSeq);
519 mop.setStrStart(pdbStart);
520 mop.setStrEnd(pdbEnd);
521 mop.setStrName(structId);
522 mop.setStrResidue(targetStrucSeqs.toString());
525 os.print(getMappingOutput(mop).toString());
531 void processSegments(List<Segment> segments, SegmentHelperPojo shp)
533 SequenceI seq = shp.getSeq();
534 HashMap<Integer, int[]> mapping = shp.getMapping();
535 TreeMap<Integer, String> resNumMap = shp.getResNumMap();
536 List<Integer> omitNonObserved = shp.getOmitNonObserved();
537 int nonObservedShiftIndex = shp.getNonObservedShiftIndex();
538 for (Segment segment : segments)
540 // System.out.println("Mapping segments : " + segment.getSegId() + "\\"s
542 List<Residue> residues = segment.getListResidue().getResidue();
543 for (Residue residue : residues)
545 int currSeqIndex = UNASSIGNED;
546 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
547 CrossRefDb pdbRefDb = null;
548 for (CrossRefDb cRefDb : cRefDbs)
550 if (cRefDb.getDbSource().equalsIgnoreCase(DBRefSource.PDB))
554 if (cRefDb.getDbCoordSys()
555 .equalsIgnoreCase(seqCoordSys.getName())
556 && isAccessionMatched(cRefDb.getDbAccessionId()))
558 String resNumIndexString = cRefDb.getDbResNum()
559 .equalsIgnoreCase("None") ? String.valueOf(UNASSIGNED)
560 : cRefDb.getDbResNum();
563 currSeqIndex = Integer.valueOf(resNumIndexString);
564 } catch (NumberFormatException nfe)
566 currSeqIndex = Integer.valueOf(resNumIndexString
567 .split("[a-zA-Z]")[0]);
570 if (pdbRefDb != null)
572 break;// exit loop if pdb and uniprot are already found
576 if (currSeqIndex == UNASSIGNED)
580 if (currSeqIndex >= seq.getStart() && currSeqIndex <= seq.getEnd())
585 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
586 .getDbResNum()) : Integer.valueOf(pdbRefDb
588 } catch (NumberFormatException nfe)
590 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
591 .getDbResNum()) : Integer.valueOf(pdbRefDb
592 .getDbResNum().split("[a-zA-Z]")[0]);
596 if (isResidueObserved(residue)
597 || seqCoordSys == CoordinateSys.UNIPROT)
599 char resCharCode = ResidueProperties
600 .getSingleCharacterCode(ResidueProperties
601 .getCanonicalAminoAcid(residue.getDbResName()));
602 resNumMap.put(currSeqIndex, String.valueOf(resCharCode));
606 omitNonObserved.add(currSeqIndex);
607 ++nonObservedShiftIndex;
609 mapping.put(currSeqIndex - nonObservedShiftIndex, new int[] {
610 Integer.valueOf(resNum), UNASSIGNED });
619 * Target chain to populate mapping of its atom positions.
621 * Two dimension array of residue index versus atom position
622 * @throws IllegalArgumentException
623 * Thrown if chainId or mapping is null
624 * @throws SiftsException
626 void populateAtomPositions(String chainId, Map<Integer, int[]> mapping)
627 throws IllegalArgumentException, SiftsException
631 PDBChain chain = pdb.findChain(chainId);
633 if (chain == null || mapping == null)
635 throw new IllegalArgumentException(
636 "Chain id or mapping must not be null.");
638 for (int[] map : mapping.values())
640 if (map[PDB_RES_POS] != UNASSIGNED)
642 map[PDB_ATOM_POS] = getAtomIndex(map[PDB_RES_POS], chain.atoms);
645 } catch (NullPointerException e)
647 throw new SiftsException(e.getMessage());
648 } catch (Exception e)
650 throw new SiftsException(e.getMessage());
656 * @param residueIndex
657 * The residue index used for the search
659 * A collection of Atom to search
660 * @return atom position for the given residue index
662 int getAtomIndex(int residueIndex, Collection<Atom> atoms)
666 throw new IllegalArgumentException(
667 "atoms collection must not be null!");
669 for (Atom atom : atoms)
671 if (atom.resNumber == residueIndex)
673 return atom.atomIndex;
680 * Checks if the residue instance is marked 'Not_observed' or not
685 private boolean isResidueObserved(Residue residue)
687 Set<String> annotations = getResidueAnnotaitons(residue,
688 ResidueDetailType.ANNOTATION);
689 if (annotations == null || annotations.isEmpty())
693 for (String annotation : annotations)
695 if (annotation.equalsIgnoreCase(NOT_OBSERVED))
704 * Get annotation String for a given residue and annotation type
710 private Set<String> getResidueAnnotaitons(Residue residue,
711 ResidueDetailType type)
713 HashSet<String> foundAnnotations = new HashSet<String>();
714 List<ResidueDetail> resDetails = residue.getResidueDetail();
715 for (ResidueDetail resDetail : resDetails)
717 if (resDetail.getProperty().equalsIgnoreCase(type.getCode()))
719 foundAnnotations.add(resDetail.getContent());
722 return foundAnnotations;
726 public boolean isAccessionMatched(String accession)
728 boolean isStrictMatch = true;
729 return isStrictMatch ? curSourceDBRef.equalsIgnoreCase(accession)
730 : curDBRefAccessionIdsString.contains(accession.toLowerCase());
733 private boolean isFoundInSiftsEntry(String accessionId)
735 Set<String> siftsDBRefs = getAllMappingAccession();
736 return accessionId != null
737 && siftsDBRefs.contains(accessionId.toLowerCase());
741 * Pad omitted residue positions in PDB sequence with gaps
745 void padWithGaps(Map<Integer, String> resNumMap,
746 List<Integer> omitNonObserved)
748 if (resNumMap == null || resNumMap.isEmpty())
752 Integer[] keys = resNumMap.keySet().toArray(new Integer[0]);
753 // Arrays.sort(keys);
754 int firstIndex = keys[0];
755 int lastIndex = keys[keys.length - 1];
756 // System.out.println("Min value " + firstIndex);
757 // System.out.println("Max value " + lastIndex);
758 for (int x = firstIndex; x <= lastIndex; x++)
760 if (!resNumMap.containsKey(x) && !omitNonObserved.contains(x))
762 resNumMap.put(x, "-");
768 public Entity getEntityById(String id) throws SiftsException
770 // Determines an entity to process by performing a heuristic matching of all
771 // Entities with the given chainId and choosing the best matching Entity
772 Entity entity = getEntityByMostOptimalMatchedId(id);
777 throw new SiftsException("Entity " + id + " not found");
781 * This method was added because EntityId is NOT always equal to ChainId.
782 * Hence, it provides the logic to greedily detect the "true" Entity for a
783 * given chainId where discrepancies exist.
788 public Entity getEntityByMostOptimalMatchedId(String chainId)
790 // System.out.println("---> advanced greedy entityId matching block entered..");
791 List<Entity> entities = siftsEntry.getEntity();
792 SiftsEntitySortPojo[] sPojo = new SiftsEntitySortPojo[entities.size()];
794 for (Entity entity : entities)
796 sPojo[count] = new SiftsEntitySortPojo();
797 sPojo[count].entityId = entity.getEntityId();
799 List<Segment> segments = entity.getSegment();
800 for (Segment segment : segments)
802 List<Residue> residues = segment.getListResidue().getResidue();
803 for (Residue residue : residues)
805 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
806 for (CrossRefDb cRefDb : cRefDbs)
808 if (!cRefDb.getDbSource().equalsIgnoreCase("PDB"))
812 ++sPojo[count].resCount;
813 if (cRefDb.getDbChainId().equalsIgnoreCase(chainId))
815 ++sPojo[count].chainIdFreq;
820 sPojo[count].pid = (100 * sPojo[count].chainIdFreq)
821 / sPojo[count].resCount;
824 Arrays.sort(sPojo, Collections.reverseOrder());
825 // System.out.println("highest matched entity : " + sPojo[0].entityId);
826 // System.out.println("highest matched pid : " + sPojo[0].pid);
828 if (sPojo[0].entityId != null)
830 if (sPojo[0].pid < 1)
834 for (Entity entity : entities)
836 if (!entity.getEntityId().equalsIgnoreCase(sPojo[0].entityId))
846 private class SiftsEntitySortPojo implements
847 Comparable<SiftsEntitySortPojo>
849 public String entityId;
851 public int chainIdFreq;
858 public int compareTo(SiftsEntitySortPojo o)
860 return this.pid - o.pid;
864 private class SegmentHelperPojo
866 private SequenceI seq;
868 private HashMap<Integer, int[]> mapping;
870 private TreeMap<Integer, String> resNumMap;
872 private List<Integer> omitNonObserved;
874 private int nonObservedShiftIndex;
876 public SegmentHelperPojo(SequenceI seq,
877 HashMap<Integer, int[]> mapping,
878 TreeMap<Integer, String> resNumMap,
879 List<Integer> omitNonObserved, int nonObservedShiftIndex)
883 setResNumMap(resNumMap);
884 setOmitNonObserved(omitNonObserved);
885 setNonObservedShiftIndex(nonObservedShiftIndex);
888 public SequenceI getSeq()
893 public void setSeq(SequenceI seq)
898 public HashMap<Integer, int[]> getMapping()
903 public void setMapping(HashMap<Integer, int[]> mapping)
905 this.mapping = mapping;
908 public TreeMap<Integer, String> getResNumMap()
913 public void setResNumMap(TreeMap<Integer, String> resNumMap)
915 this.resNumMap = resNumMap;
918 public List<Integer> getOmitNonObserved()
920 return omitNonObserved;
923 public void setOmitNonObserved(List<Integer> omitNonObserved)
925 this.omitNonObserved = omitNonObserved;
928 public int getNonObservedShiftIndex()
930 return nonObservedShiftIndex;
933 public void setNonObservedShiftIndex(int nonObservedShiftIndex)
935 this.nonObservedShiftIndex = nonObservedShiftIndex;
940 public StringBuffer getMappingOutput(MappingOutputPojo mp)
941 throws SiftsException
943 String seqRes = mp.getSeqResidue();
944 String seqName = mp.getSeqName();
945 int sStart = mp.getSeqStart();
946 int sEnd = mp.getSeqEnd();
948 String strRes = mp.getStrResidue();
949 String strName = mp.getStrName();
950 int pdbStart = mp.getStrStart();
951 int pdbEnd = mp.getStrEnd();
953 String type = mp.getType();
955 int maxid = (seqName.length() >= strName.length()) ? seqName.length()
957 int len = 72 - maxid - 1;
959 int nochunks = ((seqRes.length()) / len)
960 + ((seqRes.length()) % len > 0 ? 1 : 0);
962 StringBuffer output = new StringBuffer();
963 output.append(NEWLINE);
964 output.append("Sequence \u27f7 Structure mapping details").append(
966 output.append("Method: SIFTS");
967 output.append(NEWLINE).append(NEWLINE);
969 output.append(new Format("%" + maxid + "s").form(seqName));
970 output.append(" : ");
971 output.append(String.valueOf(sStart));
972 output.append(" - ");
973 output.append(String.valueOf(sEnd));
974 output.append(" Maps to ");
975 output.append(NEWLINE);
976 output.append(new Format("%" + maxid + "s").form(structId));
977 output.append(" : ");
978 output.append(String.valueOf(pdbStart));
979 output.append(" - ");
980 output.append(String.valueOf(pdbEnd));
981 output.append(NEWLINE).append(NEWLINE);
983 int matchedSeqCount = 0;
984 for (int j = 0; j < nochunks; j++)
986 // Print the first aligned sequence
987 output.append(new Format("%" + (maxid) + "s").form(seqName)).append(
990 for (int i = 0; i < len; i++)
992 if ((i + (j * len)) < seqRes.length())
994 output.append(seqRes.charAt(i + (j * len)));
998 output.append(NEWLINE);
999 output.append(new Format("%" + (maxid) + "s").form(" ")).append(" ");
1001 // Print out the matching chars
1002 for (int i = 0; i < len; i++)
1006 if ((i + (j * len)) < seqRes.length())
1008 boolean sameChar = Comparison.isSameResidue(
1009 seqRes.charAt(i + (j * len)),
1010 strRes.charAt(i + (j * len)), false);
1012 && !jalview.util.Comparison.isGap(seqRes.charAt(i
1018 else if (type.equals("pep"))
1020 if (ResidueProperties.getPAM250(seqRes.charAt(i + (j * len)),
1021 strRes.charAt(i + (j * len))) > 0)
1035 } catch (IndexOutOfBoundsException e)
1040 // Now print the second aligned sequence
1041 output = output.append(NEWLINE);
1042 output = output.append(new Format("%" + (maxid) + "s").form(strName))
1044 for (int i = 0; i < len; i++)
1046 if ((i + (j * len)) < strRes.length())
1048 output.append(strRes.charAt(i + (j * len)));
1051 output.append(NEWLINE).append(NEWLINE);
1053 float pid = (float) matchedSeqCount / seqRes.length() * 100;
1054 if (pid < SiftsSettings.getFailSafePIDThreshold())
1056 throw new SiftsException(">>> Low PID detected for SIFTs mapping...");
1058 output.append("Length of alignment = " + seqRes.length()).append(
1060 output.append(new Format("Percentage ID = %2.2f").form(pid));
1065 public int getEntityCount()
1067 return siftsEntry.getEntity().size();
1071 public String getDbAccessionId()
1073 return siftsEntry.getDbAccessionId();
1077 public String getDbCoordSys()
1079 return siftsEntry.getDbCoordSys();
1083 public String getDbSource()
1085 return siftsEntry.getDbSource();
1089 public String getDbVersion()
1091 return siftsEntry.getDbVersion();