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.DBRefUtils;
33 import jalview.util.Format;
34 import jalview.xml.binding.sifts.Entry;
35 import jalview.xml.binding.sifts.Entry.Entity;
36 import jalview.xml.binding.sifts.Entry.Entity.Segment;
37 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListMapRegion.MapRegion;
38 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue;
39 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.CrossRefDb;
40 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.ResidueDetail;
43 import java.io.FileInputStream;
44 import java.io.FileOutputStream;
45 import java.io.IOException;
46 import java.io.InputStream;
47 import java.io.PrintStream;
49 import java.net.URLConnection;
50 import java.nio.file.Files;
51 import java.nio.file.Path;
52 import java.nio.file.attribute.BasicFileAttributes;
53 import java.util.ArrayList;
54 import java.util.Arrays;
55 import java.util.Collection;
56 import java.util.Collections;
57 import java.util.Date;
58 import java.util.HashMap;
59 import java.util.HashSet;
60 import java.util.List;
63 import java.util.TreeMap;
64 import java.util.zip.GZIPInputStream;
66 import javax.xml.bind.JAXBContext;
67 import javax.xml.bind.Unmarshaller;
68 import javax.xml.stream.XMLInputFactory;
69 import javax.xml.stream.XMLStreamReader;
72 import MCview.PDBChain;
74 public class SiftsClient implements SiftsClientI
76 private Entry siftsEntry;
78 private StructureFile pdb;
82 private String structId;
84 private CoordinateSys seqCoordSys = CoordinateSys.UNIPROT;
86 private static final int BUFFER_SIZE = 4096;
88 public static final int UNASSIGNED = -1;
90 private static final int PDB_RES_POS = 0;
92 private static final int PDB_ATOM_POS = 1;
94 private static final String NOT_OBSERVED = "Not_Observed";
96 private static final String SIFTS_FTP_BASE_URL = "http://ftp.ebi.ac.uk/pub/databases/msd/sifts/xml/";
98 private final static String NEWLINE = System.lineSeparator();
100 private String curSourceDBRef;
102 private HashSet<String> curDBRefAccessionIdsString;
104 private enum CoordinateSys
106 UNIPROT("UniProt"), PDB("PDBresnum"), PDBe("PDBe");
109 private CoordinateSys(String name)
114 public String getName()
120 private enum ResidueDetailType
122 NAME_SEC_STRUCTURE("nameSecondaryStructure"), CODE_SEC_STRUCTURE(
123 "codeSecondaryStructure"), ANNOTATION("Annotation");
126 private ResidueDetailType(String code)
131 public String getCode()
138 * Fetch SIFTs file for the given PDBfile and construct an instance of
142 * @throws SiftsException
144 public SiftsClient(StructureFile pdb) throws SiftsException
147 this.pdbId = pdb.getId();
148 File siftsFile = getSiftsFile(pdbId);
149 siftsEntry = parseSIFTs(siftsFile);
153 * Parse the given SIFTs File and return a JAXB POJO of parsed data
156 * - the GZipped SIFTs XML file to parse
159 * if a problem occurs while parsing the SIFTs XML
161 private Entry parseSIFTs(File siftFile) throws SiftsException
163 try (InputStream in = new FileInputStream(siftFile);
164 GZIPInputStream gzis = new GZIPInputStream(in);)
166 // System.out.println("File : " + siftFile.getAbsolutePath());
167 JAXBContext jc = JAXBContext.newInstance("jalview.xml.binding.sifts");
168 XMLStreamReader streamReader = XMLInputFactory.newInstance()
169 .createXMLStreamReader(gzis);
170 Unmarshaller um = jc.createUnmarshaller();
171 return (Entry) um.unmarshal(streamReader);
172 } catch (Exception e)
175 throw new SiftsException(e.getMessage());
180 * Get a SIFTs XML file for a given PDB Id from Cache or download from FTP
181 * repository if not found in cache
184 * @return SIFTs XML file
185 * @throws SiftsException
187 public static File getSiftsFile(String pdbId) throws SiftsException
189 String siftsFileName = SiftsSettings.getSiftDownloadDirectory()
190 + pdbId.toLowerCase() + ".xml.gz";
191 File siftsFile = new File(siftsFileName);
192 if (siftsFile.exists())
194 // The line below is required for unit testing... don't comment it out!!!
195 System.out.println(">>> SIFTS File already downloaded for " + pdbId);
197 if (isFileOlderThanThreshold(siftsFile,
198 SiftsSettings.getCacheThresholdInDays()))
200 File oldSiftsFile = new File(siftsFileName + "_old");
201 siftsFile.renameTo(oldSiftsFile);
204 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
205 oldSiftsFile.delete();
207 } catch (IOException e)
210 oldSiftsFile.renameTo(siftsFile);
211 return new File(siftsFileName);
217 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
218 } catch (IOException e)
220 throw new SiftsException(e.getMessage());
226 * This method enables checking if a cached file has exceeded a certain
232 * the threshold in days
235 public static boolean isFileOlderThanThreshold(File file, int noOfDays)
237 Path filePath = file.toPath();
238 BasicFileAttributes attr;
242 attr = Files.readAttributes(filePath, BasicFileAttributes.class);
243 diffInDays = (int) ((new Date().getTime() - attr.lastModifiedTime()
244 .toMillis()) / (1000 * 60 * 60 * 24));
245 // System.out.println("Diff in days : " + diffInDays);
246 } catch (IOException e)
250 return noOfDays <= diffInDays;
254 * Download a SIFTs XML file for a given PDB Id from an FTP repository
257 * @return downloaded SIFTs XML file
258 * @throws SiftsException
259 * @throws IOException
261 public static File downloadSiftsFile(String pdbId) throws SiftsException,
264 if (pdbId.contains(".cif"))
266 pdbId = pdbId.replace(".cif", "");
268 String siftFile = pdbId + ".xml.gz";
269 String siftsFileFTPURL = SIFTS_FTP_BASE_URL + siftFile;
270 String downloadedSiftsFile = SiftsSettings.getSiftDownloadDirectory()
272 File siftsDownloadDir = new File(
273 SiftsSettings.getSiftDownloadDirectory());
274 if (!siftsDownloadDir.exists())
276 siftsDownloadDir.mkdirs();
278 // System.out.println(">> Download ftp url : " + siftsFileFTPURL);
279 URL url = new URL(siftsFileFTPURL);
280 URLConnection conn = url.openConnection();
281 InputStream inputStream = conn.getInputStream();
282 FileOutputStream outputStream = new FileOutputStream(
283 downloadedSiftsFile);
284 byte[] buffer = new byte[BUFFER_SIZE];
286 while ((bytesRead = inputStream.read(buffer)) != -1)
288 outputStream.write(buffer, 0, bytesRead);
290 outputStream.close();
292 // System.out.println(">>> File downloaded : " + downloadedSiftsFile);
293 return new File(downloadedSiftsFile);
297 * Delete the SIFTs file for the given PDB Id in the local SIFTs download
301 * @return true if the file was deleted or doesn't exist
303 public static boolean deleteSiftsFileByPDBId(String pdbId)
305 File siftsFile = new File(SiftsSettings.getSiftDownloadDirectory()
306 + pdbId.toLowerCase() + ".xml.gz");
307 if (siftsFile.exists())
309 return siftsFile.delete();
315 * Get a valid SIFTs DBRef for the given sequence current SIFTs entry
318 * - the target sequence for the operation
319 * @return a valid DBRefEntry that is SIFTs compatible
321 * if no valid source DBRefEntry was found for the given sequences
323 public DBRefEntryI getValidSourceDBRef(SequenceI seq)
324 throws SiftsException
326 List<DBRefEntry> dbRefs = seq.getPrimaryDBRefs();
327 if (dbRefs == null || dbRefs.size() < 1)
329 throw new SiftsException(
330 "Source DBRef could not be determined. DBRefs might not have been retrieved.");
333 for (DBRefEntry dbRef : dbRefs)
335 if (dbRef == null || dbRef.getAccessionId() == null
336 || dbRef.getSource() == null)
340 String canonicalSource = DBRefUtils.getCanonicalName(dbRef
342 if (isValidDBRefEntry(dbRef)
343 && (canonicalSource.equalsIgnoreCase(DBRefSource.UNIPROT) || canonicalSource
344 .equalsIgnoreCase(DBRefSource.PDB)))
349 throw new SiftsException("Could not get source DB Ref");
353 * Check that the DBRef Entry is properly populated and is available in this
354 * SiftClient instance
357 * - DBRefEntry to validate
358 * @return true validation is successful otherwise false is returned.
360 boolean isValidDBRefEntry(DBRefEntryI entry)
362 return entry != null && entry.getAccessionId() != null
363 && isFoundInSiftsEntry(entry.getAccessionId());
367 public HashSet<String> getAllMappingAccession()
369 HashSet<String> accessions = new HashSet<String>();
370 List<Entity> entities = siftsEntry.getEntity();
371 for (Entity entity : entities)
373 List<Segment> segments = entity.getSegment();
374 for (Segment segment : segments)
376 List<MapRegion> mapRegions = segment.getListMapRegion()
378 for (MapRegion mapRegion : mapRegions)
381 .add(mapRegion.getDb().getDbAccessionId().toLowerCase());
389 public StructureMapping getSiftsStructureMapping(SequenceI seq,
390 String pdbFile, String chain) throws SiftsException
392 structId = (chain == null) ? pdbId : pdbId + "|" + chain;
393 System.out.println("Getting mapping for: " + pdbId + "|" + chain
394 + " : seq- " + seq.getName());
396 final StringBuilder mappingDetails = new StringBuilder(128);
397 PrintStream ps = new PrintStream(System.out)
400 public void print(String x)
402 mappingDetails.append(x);
406 public void println()
408 mappingDetails.append(NEWLINE);
411 HashMap<Integer, int[]> mapping = getGreedyMapping(chain, seq, ps);
413 String mappingOutput = mappingDetails.toString();
414 StructureMapping siftsMapping = new StructureMapping(seq, pdbFile,
415 pdbId, chain, mapping, mappingOutput);
420 public HashMap<Integer, int[]> getGreedyMapping(String entityId,
421 SequenceI seq, java.io.PrintStream os) throws SiftsException
423 List<Integer> omitNonObserved = new ArrayList<Integer>();
424 int nonObservedShiftIndex = 0;
425 // System.out.println("Generating mappings for : " + entityId);
426 Entity entity = null;
427 entity = getEntityById(entityId);
428 String originalSeq = AlignSeq.extractGaps(
429 jalview.util.Comparison.GapChars, seq.getSequenceAsString());
430 HashMap<Integer, int[]> mapping = new HashMap<Integer, int[]>();
431 DBRefEntryI sourceDBRef;
432 sourceDBRef = getValidSourceDBRef(seq);
433 // TODO ensure sequence start/end is in the same coordinate system and
434 // consistent with the choosen sourceDBRef
436 // set sequence coordinate system - default value is UniProt
437 if (sourceDBRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
439 seqCoordSys = CoordinateSys.PDB;
442 HashSet<String> dbRefAccessionIdsString = new HashSet<String>();
443 for (DBRefEntry dbref : seq.getDBRefs())
445 dbRefAccessionIdsString.add(dbref.getAccessionId().toLowerCase());
447 dbRefAccessionIdsString.add(sourceDBRef.getAccessionId().toLowerCase());
449 curDBRefAccessionIdsString = dbRefAccessionIdsString;
450 curSourceDBRef = sourceDBRef.getAccessionId();
452 TreeMap<Integer, String> resNumMap = new TreeMap<Integer, String>();
453 List<Segment> segments = entity.getSegment();
454 SegmentHelperPojo shp = new SegmentHelperPojo(seq, mapping, resNumMap,
455 omitNonObserved, nonObservedShiftIndex);
456 processSegments(segments, shp);
459 populateAtomPositions(entityId, mapping);
460 } catch (Exception e)
464 if (seqCoordSys == CoordinateSys.UNIPROT)
466 padWithGaps(resNumMap, omitNonObserved);
468 int seqStart = UNASSIGNED;
469 int seqEnd = UNASSIGNED;
470 int pdbStart = UNASSIGNED;
471 int pdbEnd = UNASSIGNED;
473 Integer[] keys = mapping.keySet().toArray(new Integer[0]);
477 throw new SiftsException(">>> Empty SIFTS mapping generated!!");
480 seqEnd = keys[keys.length - 1];
482 String matchedSeq = originalSeq;
483 if (seqStart != UNASSIGNED)
485 pdbStart = mapping.get(seqStart)[PDB_RES_POS];
486 pdbEnd = mapping.get(seqEnd)[PDB_RES_POS];
487 int orignalSeqStart = seq.getStart();
488 if (orignalSeqStart >= 1)
490 int subSeqStart = (seqStart >= orignalSeqStart) ? seqStart
491 - orignalSeqStart : 0;
492 int subSeqEnd = seqEnd - (orignalSeqStart - 1);
493 subSeqEnd = originalSeq.length() < subSeqEnd ? originalSeq.length()
495 matchedSeq = originalSeq.substring(subSeqStart, subSeqEnd);
499 matchedSeq = originalSeq.substring(1, originalSeq.length());
503 StringBuilder targetStrucSeqs = new StringBuilder();
504 for (String res : resNumMap.values())
506 targetStrucSeqs.append(res);
511 MappingOutputPojo mop = new MappingOutputPojo();
512 mop.setSeqStart(pdbStart);
513 mop.setSeqEnd(pdbEnd);
514 mop.setSeqName(seq.getName());
515 mop.setSeqResidue(matchedSeq);
517 mop.setStrStart(seqStart);
518 mop.setStrEnd(seqEnd);
519 mop.setStrName(structId);
520 mop.setStrResidue(targetStrucSeqs.toString());
523 os.print(getMappingOutput(mop).toString());
529 void processSegments(List<Segment> segments, SegmentHelperPojo shp)
531 SequenceI seq = shp.getSeq();
532 HashMap<Integer, int[]> mapping = shp.getMapping();
533 TreeMap<Integer, String> resNumMap = shp.getResNumMap();
534 List<Integer> omitNonObserved = shp.getOmitNonObserved();
535 int nonObservedShiftIndex = shp.getNonObservedShiftIndex();
536 for (Segment segment : segments)
538 // System.out.println("Mapping segments : " + segment.getSegId() + "\\"s
540 List<Residue> residues = segment.getListResidue().getResidue();
541 for (Residue residue : residues)
543 int currSeqIndex = UNASSIGNED;
544 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
545 CrossRefDb pdbRefDb = null;
546 for (CrossRefDb cRefDb : cRefDbs)
548 if (cRefDb.getDbSource().equalsIgnoreCase(DBRefSource.PDB))
552 if (cRefDb.getDbCoordSys()
553 .equalsIgnoreCase(seqCoordSys.getName())
554 && isAccessionMatched(cRefDb.getDbAccessionId()))
556 String resNumIndexString = cRefDb.getDbResNum()
557 .equalsIgnoreCase("None") ? String.valueOf(UNASSIGNED)
558 : cRefDb.getDbResNum();
561 currSeqIndex = Integer.valueOf(resNumIndexString);
562 } catch (NumberFormatException nfe)
564 currSeqIndex = Integer.valueOf(resNumIndexString
565 .split("[a-zA-Z]")[0]);
568 if (pdbRefDb != null)
570 break;// exit loop if pdb and uniprot are already found
574 if (currSeqIndex == UNASSIGNED)
578 if (currSeqIndex >= seq.getStart() && currSeqIndex <= seq.getEnd())
583 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
584 .getDbResNum()) : Integer.valueOf(pdbRefDb
586 } catch (NumberFormatException nfe)
588 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
589 .getDbResNum()) : Integer.valueOf(pdbRefDb
590 .getDbResNum().split("[a-zA-Z]")[0]);
594 if (isResidueObserved(residue)
595 || seqCoordSys == CoordinateSys.UNIPROT)
597 char resCharCode = ResidueProperties
598 .getSingleCharacterCode(ResidueProperties
599 .getCanonicalAminoAcid(residue.getDbResName()));
600 resNumMap.put(currSeqIndex, String.valueOf(resCharCode));
604 omitNonObserved.add(currSeqIndex);
605 ++nonObservedShiftIndex;
607 mapping.put(currSeqIndex - nonObservedShiftIndex, new int[] {
608 Integer.valueOf(resNum), UNASSIGNED });
617 * Target chain to populate mapping of its atom positions.
619 * Two dimension array of residue index versus atom position
620 * @throws IllegalArgumentException
621 * Thrown if chainId or mapping is null
622 * @throws SiftsException
624 void populateAtomPositions(String chainId, Map<Integer, int[]> mapping)
625 throws IllegalArgumentException, SiftsException
629 PDBChain chain = pdb.findChain(chainId);
631 if (chain == null || mapping == null)
633 throw new IllegalArgumentException(
634 "Chain id or mapping must not be null.");
636 for (int[] map : mapping.values())
638 if (map[PDB_RES_POS] != UNASSIGNED)
640 map[PDB_ATOM_POS] = getAtomIndex(map[PDB_RES_POS], chain.atoms);
643 } catch (NullPointerException e)
645 throw new SiftsException(e.getMessage());
646 } catch (Exception e)
648 throw new SiftsException(e.getMessage());
654 * @param residueIndex
655 * The residue index used for the search
657 * A collection of Atom to search
658 * @return atom position for the given residue index
660 int getAtomIndex(int residueIndex, Collection<Atom> atoms)
664 throw new IllegalArgumentException(
665 "atoms collection must not be null!");
667 for (Atom atom : atoms)
669 if (atom.resNumber == residueIndex)
671 return atom.atomIndex;
678 * Checks if the residue instance is marked 'Not_observed' or not
683 private boolean isResidueObserved(Residue residue)
685 Set<String> annotations = getResidueAnnotaitons(residue,
686 ResidueDetailType.ANNOTATION);
687 if (annotations == null || annotations.isEmpty())
691 for (String annotation : annotations)
693 if (annotation.equalsIgnoreCase(NOT_OBSERVED))
702 * Get annotation String for a given residue and annotation type
708 private Set<String> getResidueAnnotaitons(Residue residue,
709 ResidueDetailType type)
711 HashSet<String> foundAnnotations = new HashSet<String>();
712 List<ResidueDetail> resDetails = residue.getResidueDetail();
713 for (ResidueDetail resDetail : resDetails)
715 if (resDetail.getProperty().equalsIgnoreCase(type.getCode()))
717 foundAnnotations.add(resDetail.getContent());
720 return foundAnnotations;
724 public boolean isAccessionMatched(String accession)
726 boolean isStrictMatch = true;
727 return isStrictMatch ? curSourceDBRef.equalsIgnoreCase(accession)
728 : curDBRefAccessionIdsString.contains(accession.toLowerCase());
731 private boolean isFoundInSiftsEntry(String accessionId)
733 Set<String> siftsDBRefs = getAllMappingAccession();
734 return accessionId != null
735 && siftsDBRefs.contains(accessionId.toLowerCase());
739 * Pad omitted residue positions in PDB sequence with gaps
743 void padWithGaps(Map<Integer, String> resNumMap,
744 List<Integer> omitNonObserved)
746 if (resNumMap == null || resNumMap.isEmpty())
750 Integer[] keys = resNumMap.keySet().toArray(new Integer[0]);
751 // Arrays.sort(keys);
752 int firstIndex = keys[0];
753 int lastIndex = keys[keys.length - 1];
754 // System.out.println("Min value " + firstIndex);
755 // System.out.println("Max value " + lastIndex);
756 for (int x = firstIndex; x <= lastIndex; x++)
758 if (!resNumMap.containsKey(x) && !omitNonObserved.contains(x))
760 resNumMap.put(x, "-");
766 public Entity getEntityById(String id) throws SiftsException
768 // Determines an entity to process by performing a heuristic matching of all
769 // Entities with the given chainId and choosing the best matching Entity
770 Entity entity = getEntityByMostOptimalMatchedId(id);
775 throw new SiftsException("Entity " + id + " not found");
779 * This method was added because EntityId is NOT always equal to ChainId.
780 * Hence, it provides the logic to greedily detect the "true" Entity for a
781 * given chainId where discrepancies exist.
786 public Entity getEntityByMostOptimalMatchedId(String chainId)
788 // System.out.println("---> advanced greedy entityId matching block entered..");
789 List<Entity> entities = siftsEntry.getEntity();
790 SiftsEntitySortPojo[] sPojo = new SiftsEntitySortPojo[entities.size()];
792 for (Entity entity : entities)
794 sPojo[count] = new SiftsEntitySortPojo();
795 sPojo[count].entityId = entity.getEntityId();
797 List<Segment> segments = entity.getSegment();
798 for (Segment segment : segments)
800 List<Residue> residues = segment.getListResidue().getResidue();
801 for (Residue residue : residues)
803 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
804 for (CrossRefDb cRefDb : cRefDbs)
806 if (!cRefDb.getDbSource().equalsIgnoreCase("PDB"))
810 ++sPojo[count].resCount;
811 if (cRefDb.getDbChainId().equalsIgnoreCase(chainId))
813 ++sPojo[count].chainIdFreq;
818 sPojo[count].pid = (100 * sPojo[count].chainIdFreq)
819 / sPojo[count].resCount;
822 Arrays.sort(sPojo, Collections.reverseOrder());
823 // System.out.println("highest matched entity : " + sPojo[0].entityId);
824 // System.out.println("highest matched pid : " + sPojo[0].pid);
826 if (sPojo[0].entityId != null)
828 for (Entity entity : entities)
830 if (!entity.getEntityId().equalsIgnoreCase(sPojo[0].entityId))
840 private class SiftsEntitySortPojo implements
841 Comparable<SiftsEntitySortPojo>
843 public String entityId;
845 public int chainIdFreq;
852 public int compareTo(SiftsEntitySortPojo o)
854 return this.pid - o.pid;
858 private class SegmentHelperPojo
860 private SequenceI seq;
862 private HashMap<Integer, int[]> mapping;
864 private TreeMap<Integer, String> resNumMap;
866 private List<Integer> omitNonObserved;
868 private int nonObservedShiftIndex;
870 public SegmentHelperPojo(SequenceI seq,
871 HashMap<Integer, int[]> mapping,
872 TreeMap<Integer, String> resNumMap,
873 List<Integer> omitNonObserved, int nonObservedShiftIndex)
877 setResNumMap(resNumMap);
878 setOmitNonObserved(omitNonObserved);
879 setNonObservedShiftIndex(nonObservedShiftIndex);
882 public SequenceI getSeq()
887 public void setSeq(SequenceI seq)
892 public HashMap<Integer, int[]> getMapping()
897 public void setMapping(HashMap<Integer, int[]> mapping)
899 this.mapping = mapping;
902 public TreeMap<Integer, String> getResNumMap()
907 public void setResNumMap(TreeMap<Integer, String> resNumMap)
909 this.resNumMap = resNumMap;
912 public List<Integer> getOmitNonObserved()
914 return omitNonObserved;
917 public void setOmitNonObserved(List<Integer> omitNonObserved)
919 this.omitNonObserved = omitNonObserved;
922 public int getNonObservedShiftIndex()
924 return nonObservedShiftIndex;
927 public void setNonObservedShiftIndex(int nonObservedShiftIndex)
929 this.nonObservedShiftIndex = nonObservedShiftIndex;
934 public StringBuffer getMappingOutput(MappingOutputPojo mp)
935 throws SiftsException
937 String seqRes = mp.getSeqResidue();
938 String seqName = mp.getSeqName();
939 int sStart = mp.getSeqStart();
940 int sEnd = mp.getSeqEnd();
942 String strRes = mp.getStrResidue();
943 String strName = mp.getStrName();
944 int pdbStart = mp.getStrStart();
945 int pdbEnd = mp.getStrEnd();
947 String type = mp.getType();
949 int maxid = (seqName.length() >= strName.length()) ? seqName.length()
951 int len = 72 - maxid - 1;
953 int nochunks = ((seqRes.length()) / len)
954 + ((seqRes.length()) % len > 0 ? 1 : 0);
956 StringBuffer output = new StringBuffer();
957 output.append(NEWLINE);
958 output.append("Sequence \u27f7 Structure mapping details").append(
960 output.append("Method: SIFTS");
961 output.append(NEWLINE).append(NEWLINE);
963 output.append(new Format("%" + maxid + "s").form(seqName));
964 output.append(" : ");
965 output.append(String.valueOf(sStart));
966 output.append(" - ");
967 output.append(String.valueOf(sEnd));
968 output.append(" Maps to ");
969 output.append(NEWLINE);
970 output.append(new Format("%" + maxid + "s").form(structId));
971 output.append(" : ");
972 output.append(String.valueOf(pdbStart));
973 output.append(" - ");
974 output.append(String.valueOf(pdbEnd));
975 output.append(NEWLINE).append(NEWLINE);
977 int matchedSeqCount = 0;
978 for (int j = 0; j < nochunks; j++)
980 // Print the first aligned sequence
981 output.append(new Format("%" + (maxid) + "s").form(seqName)).append(
984 for (int i = 0; i < len; i++)
986 if ((i + (j * len)) < seqRes.length())
988 output.append(seqRes.charAt(i + (j * len)));
992 output.append(NEWLINE);
993 output.append(new Format("%" + (maxid) + "s").form(" ")).append(" ");
995 // Print out the matching chars
996 for (int i = 0; i < len; i++)
1000 if ((i + (j * len)) < seqRes.length())
1002 if (seqRes.charAt(i + (j * len)) == strRes
1003 .charAt(i + (j * len))
1004 && !jalview.util.Comparison.isGap(seqRes.charAt(i
1010 else if (type.equals("pep"))
1012 if (ResidueProperties.getPAM250(seqRes.charAt(i + (j * len)),
1013 strRes.charAt(i + (j * len))) > 0)
1027 } catch (IndexOutOfBoundsException e)
1032 // Now print the second aligned sequence
1033 output = output.append(NEWLINE);
1034 output = output.append(new Format("%" + (maxid) + "s").form(strName))
1036 for (int i = 0; i < len; i++)
1038 if ((i + (j * len)) < strRes.length())
1040 output.append(strRes.charAt(i + (j * len)));
1043 output.append(NEWLINE).append(NEWLINE);
1045 float pid = (float) matchedSeqCount / seqRes.length() * 100;
1046 if (pid < SiftsSettings.getFailSafePIDThreshold())
1048 throw new SiftsException(">>> Low PID detected for SIFTs mapping...");
1050 output.append("Length of alignment = " + seqRes.length()).append(
1052 output.append(new Format("Percentage ID = %2.2f").form(pid));
1057 public int getEntityCount()
1059 return siftsEntry.getEntity().size();
1063 public String getDbAccessionId()
1065 return siftsEntry.getDbAccessionId();
1069 public String getDbCoordSys()
1071 return siftsEntry.getDbCoordSys();
1075 public String getDbSource()
1077 return siftsEntry.getDbSource();
1081 public String getDbVersion()
1083 return siftsEntry.getDbVersion();