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.schemes.ResidueProperties;
30 import jalview.structure.StructureMapping;
31 import jalview.util.Format;
32 import jalview.xml.binding.sifts.Entry;
33 import jalview.xml.binding.sifts.Entry.Entity;
34 import jalview.xml.binding.sifts.Entry.Entity.Segment;
35 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListMapRegion.MapRegion;
36 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue;
37 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.CrossRefDb;
38 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.ResidueDetail;
39 import jalview.xml.binding.sifts.Entry.ListDB.Db;
42 import java.io.FileInputStream;
43 import java.io.FileNotFoundException;
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;
61 import java.util.TreeMap;
62 import java.util.zip.GZIPInputStream;
64 import javax.xml.bind.JAXBContext;
65 import javax.xml.bind.JAXBException;
66 import javax.xml.bind.Unmarshaller;
67 import javax.xml.stream.FactoryConfigurationError;
68 import javax.xml.stream.XMLInputFactory;
69 import javax.xml.stream.XMLStreamException;
70 import javax.xml.stream.XMLStreamReader;
73 import MCview.PDBChain;
74 import MCview.PDBfile;
76 public class SiftsClient implements SiftsClientI
78 private Entry siftsEntry;
84 private String structId;
86 private String segStartEnd;
88 private CoordinateSys seqCoordSys = CoordinateSys.UNIPROT;
90 private static final int BUFFER_SIZE = 4096;
92 public static final int UNASSIGNED = -1;
94 private static final int PDB_RES_POS = 0;
96 private static final int PDB_ATOM_POS = 1;
98 private static final String NOT_FOUND = "Not_Found";
100 private static final String NOT_OBSERVED = "Not_Observed";
102 private static final String SIFTS_FTP_BASE_URL = "ftp://ftp.ebi.ac.uk/pub/databases/msd/sifts/xml/";
104 private final static String NEWLINE = System.lineSeparator();
106 // private final static int CACHE_THRESHOLD_IN_DAYS = 2;
108 // private final static int FAIL_SAFE_PID_THRESHOLD = 30;
110 private String curSourceDBRef;
112 private HashSet<String> curDBRefAccessionIdsString;
114 public enum CoordinateSys
116 UNIPROT("UniProt"), PDB("PDBresnum"), PDBe("PDBe");
119 private CoordinateSys(String name)
124 public String getName()
130 public enum ResidueDetailType
132 NAME_SEC_STRUCTURE("nameSecondaryStructure"), CODE_SEC_STRUCTURE(
133 "codeSecondaryStructure"), ANNOTATION("Annotation");
136 private ResidueDetailType(String code)
141 public String getCode()
148 * Fetch SIFTs file for the given PDBfile and construct an instance of
152 * @throws SiftsException
154 public SiftsClient(PDBfile pdb) throws SiftsException
158 File siftsFile = getSiftsFile(pdbId);
159 siftsEntry = parseSIFTs(siftsFile);
163 * Construct an instance of SiftsClient using the supplied SIFTs file. Note:
164 * The SIFTs file should correspond to the PDB Id in PDBfile instance
168 * @throws SiftsException
171 public SiftsClient(PDBfile pdb, File siftsFile) throws SiftsException
175 siftsEntry = parseSIFTs(siftsFile);
179 * Parse the given SIFTs File and return a JAXB POJO of parsed data
182 * - the GZipped SIFTs XML file to parse
185 * if a problem occurs while parsing the SIFTs XML
187 private Entry parseSIFTs(File siftFile) throws SiftsException
189 try (InputStream in = new FileInputStream(siftFile);
190 GZIPInputStream gzis = new GZIPInputStream(in);)
192 // System.out.println("File : " + siftFile.getAbsolutePath());
193 JAXBContext jc = JAXBContext.newInstance("jalview.xml.binding.sifts");
194 XMLStreamReader streamReader = XMLInputFactory.newInstance()
195 .createXMLStreamReader(gzis);
196 Unmarshaller um = jc.createUnmarshaller();
197 return (Entry) um.unmarshal(streamReader);
198 } catch (JAXBException e)
201 throw new SiftsException(e.getMessage());
202 } catch (FileNotFoundException e)
205 throw new SiftsException(e.getMessage());
206 } catch (XMLStreamException e)
209 throw new SiftsException(e.getMessage());
210 } catch (FactoryConfigurationError e)
213 throw new SiftsException(e.getMessage());
214 } catch (IOException e)
217 throw new SiftsException(e.getMessage());
222 * Get a SIFTs XML file for a given PDB Id from Cache or download from FTP
223 * repository if not found in cache
226 * @return SIFTs XML file
227 * @throws SiftsException
229 public static File getSiftsFile(String pdbId) throws SiftsException
231 File siftsFile = new File(SiftsSettings.getSiftDownloadDirectory()
232 + pdbId.toLowerCase() + ".xml.gz");
233 if (siftsFile.exists())
235 // The line below is required for unit testing... don't comment it out!!!
236 System.out.println(">>> SIFTS File already downloaded for " + pdbId);
238 if (isFileOlderThanThreshold(siftsFile,
239 SiftsSettings.getCacheThresholdInDays()))
241 // System.out.println("Downloaded file is out of date, hence re-downloading...");
242 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
246 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
251 * This method enables checking if a cached file has exceeded a certain
257 * the threshold in days
260 public static boolean isFileOlderThanThreshold(File file, int noOfDays)
262 Path filePath = file.toPath();
263 BasicFileAttributes attr;
267 attr = Files.readAttributes(filePath, BasicFileAttributes.class);
268 diffInDays = (int) ((new Date().getTime() - attr.lastModifiedTime()
269 .toMillis()) / (1000 * 60 * 60 * 24));
270 // System.out.println("Diff in days : " + diffInDays);
271 } catch (IOException e)
275 return noOfDays <= diffInDays;
279 * Download a SIFTs XML file for a given PDB Id from an FTP repository
282 * @return downloaded SIFTs XML file
283 * @throws SiftsException
285 public static File downloadSiftsFile(String pdbId) throws SiftsException
287 if (pdbId.contains(".cif"))
289 pdbId = pdbId.replace(".cif", "");
291 String siftFile = pdbId + ".xml.gz";
292 String siftsFileFTPURL = SIFTS_FTP_BASE_URL + siftFile;
293 String downloadedSiftsFile = SiftsSettings.getSiftDownloadDirectory()
295 File siftsDownloadDir = new File(
296 SiftsSettings.getSiftDownloadDirectory());
297 if (!siftsDownloadDir.exists())
299 siftsDownloadDir.mkdirs();
303 // System.out.println(">> Download ftp url : " + siftsFileFTPURL);
304 URL url = new URL(siftsFileFTPURL);
305 URLConnection conn = url.openConnection();
306 InputStream inputStream = conn.getInputStream();
307 FileOutputStream outputStream = new FileOutputStream(
308 downloadedSiftsFile);
309 byte[] buffer = new byte[BUFFER_SIZE];
311 while ((bytesRead = inputStream.read(buffer)) != -1)
313 outputStream.write(buffer, 0, bytesRead);
315 outputStream.close();
317 // System.out.println(">>> File downloaded : " + downloadedSiftsFile);
318 } catch (IOException ex)
320 throw new SiftsException(ex.getMessage());
322 return new File(downloadedSiftsFile);
326 * Delete the SIFTs file for the given PDB Id in the local SIFTs download
330 * @return true if the file was deleted or doesn't exist
332 public static boolean deleteSiftsFileByPDBId(String pdbId)
334 File siftsFile = new File(SiftsSettings.getSiftDownloadDirectory()
335 + pdbId.toLowerCase() + ".xml.gz");
336 if (siftsFile.exists())
338 return siftsFile.delete();
344 * Get a valid SIFTs DBRef for the given sequence current SIFTs entry
347 * - the target sequence for the operation
348 * @return a valid DBRefEntry that is SIFTs compatible
350 * if no valid source DBRefEntry was found for the given sequences
352 public DBRefEntryI getValidSourceDBRef(SequenceI seq)
353 throws SiftsException
355 DBRefEntryI sourceDBRef = null;
356 sourceDBRef = seq.getSourceDBRef();
357 if (sourceDBRef != null && isValidDBRefEntry(sourceDBRef))
363 DBRefEntry[] dbRefs = seq.getDBRefs();
364 if (dbRefs == null || dbRefs.length < 1)
366 throw new SiftsException("Could not get source DB Ref");
369 for (DBRefEntryI dbRef : dbRefs)
371 if (dbRef == null || dbRef.getAccessionId() == null
372 || dbRef.getSource() == null)
376 if (isFoundInSiftsEntry(dbRef.getAccessionId())
377 && (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT) || dbRef
378 .getSource().equalsIgnoreCase(DBRefSource.PDB)))
384 if (sourceDBRef != null && isValidDBRefEntry(sourceDBRef))
388 throw new SiftsException("Could not get source DB Ref");
392 * Check that the DBRef Entry is properly populated and is available in this
393 * SiftClient instance
396 * - DBRefEntry to validate
397 * @return true validation is successful otherwise false is returned.
399 private boolean isValidDBRefEntry(DBRefEntryI entry)
401 return entry != null && entry.getAccessionId() != null
402 && isFoundInSiftsEntry(entry.getAccessionId());
406 public HashSet<String> getAllMappingAccession()
408 HashSet<String> accessions = new HashSet<String>();
409 List<Entity> entities = siftsEntry.getEntity();
410 for (Entity entity : entities)
412 List<Segment> segments = entity.getSegment();
413 for (Segment segment : segments)
415 List<MapRegion> mapRegions = segment.getListMapRegion()
417 for (MapRegion mapRegion : mapRegions)
419 accessions.add(mapRegion.getDb().getDbAccessionId());
427 public StructureMapping getSiftsStructureMapping(SequenceI seq,
428 String pdbFile, String chain) throws SiftsException
430 structId = (chain == null) ? pdbId : pdbId + "|" + chain;
431 System.out.println("Getting mapping for: " + pdbId + "|" + chain
432 + " : seq- " + seq.getName());
434 final StringBuilder mappingDetails = new StringBuilder(128);
435 PrintStream ps = new PrintStream(System.out)
438 public void print(String x)
440 mappingDetails.append(x);
444 public void println()
446 mappingDetails.append(NEWLINE);
449 HashMap<Integer, int[]> mapping = getGreedyMapping(chain, seq, ps);
451 String mappingOutput = mappingDetails.toString();
452 StructureMapping siftsMapping = new StructureMapping(seq, pdbFile,
453 pdbId, chain, mapping, mappingOutput);
458 public HashMap<Integer, int[]> getGreedyMapping(String entityId,
459 SequenceI seq, java.io.PrintStream os) throws SiftsException
461 ArrayList<Integer> omitNonObserved = new ArrayList<Integer>();
462 int nonObservedShiftIndex = 0;
463 System.out.println("Generating mappings for : " + entityId);
464 Entity entity = null;
465 entity = getEntityById(entityId);
466 String originalSeq = AlignSeq.extractGaps(
467 jalview.util.Comparison.GapChars, seq.getSequenceAsString());
468 HashMap<Integer, int[]> mapping = new HashMap<Integer, int[]>();
469 DBRefEntryI sourceDBRef = seq.getSourceDBRef();
470 if (sourceDBRef == null)
472 sourceDBRef = getValidSourceDBRef(seq);
473 // TODO ensure sequence start/end is in the same coordinate system and
474 // consistent with the choosen sourceDBRef
477 // set sequence coordinate system - default value is UniProt
478 if (sourceDBRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
480 seqCoordSys = CoordinateSys.PDB;
483 HashSet<String> dbRefAccessionIdsString = new HashSet<String>();
484 for (DBRefEntry dbref : seq.getDBRefs())
486 dbRefAccessionIdsString.add(dbref.getAccessionId().toLowerCase());
488 dbRefAccessionIdsString.add(sourceDBRef.getAccessionId().toLowerCase());
490 curDBRefAccessionIdsString = dbRefAccessionIdsString;
491 curSourceDBRef = sourceDBRef.getAccessionId();
493 TreeMap<Integer, String> resNumMap = new TreeMap<Integer, String>();
494 List<Segment> segments = entity.getSegment();
495 for (Segment segment : segments)
497 segStartEnd = segment.getStart() + " - " + segment.getEnd();
498 System.out.println("Mappging segments : " + segment.getSegId() + "\\"
500 List<Residue> residues = segment.getListResidue().getResidue();
501 for (Residue residue : residues)
503 int currSeqIndex = UNASSIGNED;
504 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
505 CrossRefDb pdbRefDb = null;
506 for (CrossRefDb cRefDb : cRefDbs)
508 if (cRefDb.getDbSource().equalsIgnoreCase(DBRefSource.PDB))
512 if (cRefDb.getDbCoordSys()
513 .equalsIgnoreCase(seqCoordSys.getName())
514 && isAccessionMatched(cRefDb.getDbAccessionId()))
516 String resNumIndexString = cRefDb.getDbResNum()
517 .equalsIgnoreCase("None") ? String.valueOf(UNASSIGNED)
518 : cRefDb.getDbResNum();
521 currSeqIndex = Integer.valueOf(resNumIndexString);
522 } catch (NumberFormatException nfe)
524 currSeqIndex = Integer.valueOf(resNumIndexString
525 .split("[a-zA-Z]")[0]);
527 if (pdbRefDb != null)
529 break;// exit loop if pdb and uniprot are already found
533 if (currSeqIndex == UNASSIGNED)
537 if (currSeqIndex > seq.getStart() && currSeqIndex <= seq.getEnd())
542 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
543 .getDbResNum()) : Integer.valueOf(pdbRefDb
545 } catch (NumberFormatException nfe)
547 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
548 .getDbResNum()) : Integer.valueOf(pdbRefDb
549 .getDbResNum().split("[a-zA-Z]")[0]);
552 if (isResidueObserved(residue)
553 || seqCoordSys == CoordinateSys.UNIPROT)
555 char resCharCode = ResidueProperties
556 .getSingleCharacterCode(ResidueProperties
557 .getCanonicalAminoAcid(residue.getDbResName()));
558 resNumMap.put(currSeqIndex, String.valueOf(resCharCode));
562 omitNonObserved.add(currSeqIndex);
563 ++nonObservedShiftIndex;
565 mapping.put(currSeqIndex - nonObservedShiftIndex, new int[] {
566 Integer.valueOf(resNum), UNASSIGNED });
572 populateAtomPositions(entityId, mapping);
573 } catch (Exception e)
577 if (seqCoordSys == CoordinateSys.UNIPROT)
579 padWithGaps(resNumMap, omitNonObserved);
581 int seqStart = UNASSIGNED;
582 int seqEnd = UNASSIGNED;
583 int pdbStart = UNASSIGNED;
584 int pdbEnd = UNASSIGNED;
586 Integer[] keys = mapping.keySet().toArray(new Integer[0]);
590 throw new SiftsException(">>> Empty SIFTS mapping generated!!");
593 seqEnd = keys[keys.length - 1];
595 String matchedSeq = originalSeq;
596 if (seqStart != UNASSIGNED)
598 pdbStart = mapping.get(seqStart)[PDB_RES_POS];
599 pdbEnd = mapping.get(seqEnd)[PDB_RES_POS];
600 int orignalSeqStart = seq.getStart();
601 if (orignalSeqStart >= 1)
603 int subSeqStart = seqStart - orignalSeqStart;
604 int subSeqEnd = seqEnd - (orignalSeqStart - 1);
605 subSeqEnd = originalSeq.length() < subSeqEnd ? originalSeq.length()
607 matchedSeq = originalSeq.substring(subSeqStart, subSeqEnd);
611 StringBuilder targetStrucSeqs = new StringBuilder();
612 for (String res : resNumMap.values())
614 targetStrucSeqs.append(res);
619 MappingOutputPojo mop = new MappingOutputPojo();
620 mop.setSeqStart(seqStart);
621 mop.setSeqEnd(seqEnd);
622 mop.setSeqName(seq.getName());
623 mop.setSeqResidue(matchedSeq);
625 mop.setStrStart(pdbStart);
626 mop.setStrEnd(pdbEnd);
627 mop.setStrName(structId);
628 mop.setStrResidue(targetStrucSeqs.toString());
631 os.print(getMappingOutput(mop).toString());
639 * Target chain to populate mapping of its atom positions.
641 * Two dimension array of residue index versus atom position
642 * @throws IllegalArgumentException
643 * Thrown if chainId or mapping is null
645 void populateAtomPositions(String chainId,
646 HashMap<Integer, int[]> mapping) throws IllegalArgumentException
648 PDBChain chain = pdb.findChain(chainId);
649 if (chain == null || mapping == null)
651 throw new IllegalArgumentException(
652 "Chain id or mapping must not be null.");
654 for (int[] map : mapping.values())
656 if (map[PDB_RES_POS] != UNASSIGNED)
658 map[PDB_ATOM_POS] = getAtomIndex(map[PDB_RES_POS], chain.atoms);
665 * @param residueIndex
666 * The residue index used for the search
668 * A collection of Atom to search
669 * @return atom position for the given residue index
671 int getAtomIndex(int residueIndex, Collection<Atom> atoms)
675 throw new IllegalArgumentException(
676 "atoms collection must not be null!");
678 for (Atom atom : atoms)
680 if (atom.resNumber == residueIndex)
682 return atom.atomIndex;
689 * Checks if the residue instance is marked 'Not_observed' or not
694 private boolean isResidueObserved(Residue residue)
696 HashSet<String> annotations = getResidueAnnotaitons(residue,
697 ResidueDetailType.ANNOTATION);
698 if (annotations == null || annotations.isEmpty())
702 for (String annotation : annotations)
704 if (annotation.equalsIgnoreCase(NOT_OBSERVED))
713 * Get annotation String for a given residue and annotation type
719 private HashSet<String> getResidueAnnotaitons(Residue residue,
720 ResidueDetailType type)
722 HashSet<String> foundAnnotations = new HashSet<String>();
723 List<ResidueDetail> resDetails = residue.getResidueDetail();
724 for (ResidueDetail resDetail : resDetails)
726 if (resDetail.getProperty().equalsIgnoreCase(type.getCode()))
728 foundAnnotations.add(resDetail.getContent());
731 return foundAnnotations;
735 public boolean isAccessionMatched(String accession)
737 boolean isStrictMatch = true;
738 return isStrictMatch ? curSourceDBRef.equalsIgnoreCase(accession)
739 : curDBRefAccessionIdsString.contains(accession.toLowerCase());
742 private boolean isFoundInSiftsEntry(String accessionId)
744 return accessionId != null
745 && getAllMappingAccession().contains(accessionId);
749 * Pad omitted residue positions in PDB sequence with gaps
753 void padWithGaps(TreeMap<Integer, String> resNumMap,
754 ArrayList<Integer> omitNonObserved)
756 if (resNumMap == null || resNumMap.isEmpty())
760 Integer[] keys = resNumMap.keySet().toArray(new Integer[0]);
762 int firstIndex = keys[0];
763 int lastIndex = keys[keys.length - 1];
764 System.out.println("Min value " + firstIndex);
765 System.out.println("Max value " + lastIndex);
766 for (int x = firstIndex; x <= lastIndex; x++)
768 if (!resNumMap.containsKey(x) && !omitNonObserved.contains(x))
770 resNumMap.put(x, "-");
778 public Entity getEntityById(String id) throws SiftsException
780 List<Entity> entities = siftsEntry.getEntity();
781 for (Entity entity : entities)
783 if (!entity.getEntityId().equalsIgnoreCase(id))
789 Entity entity = getEntityByMostOptimalMatchedId(id);
794 throw new SiftsException("Entity " + id + " not found");
798 * This method was added because EntityId is NOT always equal to ChainId.
799 * Hence, it provides the logic to greedily detect the "true" Entity for a
800 * given chainId where discrepancies exist.
805 public Entity getEntityByMostOptimalMatchedId(String chainId)
808 .println("--------------> advanced greedy entityId matching block entered..");
809 List<Entity> entities = siftsEntry.getEntity();
810 SiftsEntitySortPojo[] sPojo = new SiftsEntitySortPojo[entities.size()];
812 for (Entity entity : entities)
814 sPojo[count] = new SiftsEntitySortPojo();
815 sPojo[count].entityId = entity.getEntityId();
817 List<Segment> segments = entity.getSegment();
818 for (Segment segment : segments)
820 List<Residue> residues = segment.getListResidue().getResidue();
821 for (Residue residue : residues)
823 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
824 for (CrossRefDb cRefDb : cRefDbs)
826 if (!cRefDb.getDbSource().equalsIgnoreCase("PDB"))
830 ++sPojo[count].resCount;
831 if (cRefDb.getDbChainId().equalsIgnoreCase(chainId))
833 ++sPojo[count].chainIdFreq;
838 sPojo[count].pid = 100 * (sPojo[count].chainIdFreq / sPojo[count].resCount);
841 Arrays.sort(sPojo, Collections.reverseOrder());
842 System.out.println("highest matched entity : " + sPojo[0].entityId);
843 System.out.println("highest matched pid : " + sPojo[0].pid);
845 if (sPojo[0].entityId != null)
847 for (Entity entity : entities)
849 if (!entity.getEntityId().equalsIgnoreCase(sPojo[0].entityId))
859 public class SiftsEntitySortPojo implements
860 Comparable<SiftsEntitySortPojo>
862 public String entityId;
864 public int chainIdFreq;
871 public int compareTo(SiftsEntitySortPojo o)
873 return this.pid - o.pid;
878 public String[] getEntryDBs()
880 System.out.println("\nListing DB entries...");
881 List<String> availDbs = new ArrayList<String>();
882 List<Db> dbs = siftsEntry.getListDB().getDb();
885 availDbs.add(db.getDbSource());
886 System.out.println(db.getDbSource() + " | " + db.getDbCoordSys());
888 return availDbs.toArray(new String[0]);
892 public StringBuffer getMappingOutput(MappingOutputPojo mp)
893 throws SiftsException
895 String seqRes = mp.getSeqResidue();
896 String seqName = mp.getSeqName();
897 int sStart = mp.getSeqStart();
898 int sEnd = mp.getSeqEnd();
900 String strRes = mp.getStrResidue();
901 String strName = mp.getStrName();
902 int pdbStart = mp.getStrStart();
903 int pdbEnd = mp.getStrEnd();
905 String type = mp.getType();
907 int maxid = (seqName.length() >= strName.length()) ? seqName.length()
909 int len = 72 - maxid - 1;
911 int nochunks = ((seqRes.length()) / len)
912 + ((seqRes.length()) % len > 0 ? 1 : 0);
914 StringBuffer output = new StringBuffer();
915 output.append(NEWLINE);
916 output.append("Sequence ⟷ Structure mapping details").append(NEWLINE);
917 output.append("Method: SIFTS");
918 output.append(NEWLINE).append(NEWLINE);
920 output.append(new Format("%" + maxid + "s").form(seqName));
921 output.append(" : ");
922 output.append(String.valueOf(sStart));
923 output.append(" - ");
924 output.append(String.valueOf(sEnd));
925 output.append(" Maps to ");
926 output.append(NEWLINE);
927 output.append(new Format("%" + maxid + "s").form(structId));
928 output.append(" : ");
929 output.append(String.valueOf(pdbStart));
930 output.append(" - ");
931 output.append(String.valueOf(pdbEnd));
932 output.append(NEWLINE).append(NEWLINE);
934 int matchedSeqCount = 0;
935 for (int j = 0; j < nochunks; j++)
937 // Print the first aligned sequence
938 output.append(new Format("%" + (maxid) + "s").form(seqName)).append(
941 for (int i = 0; i < len; i++)
943 if ((i + (j * len)) < seqRes.length())
945 output.append(seqRes.charAt(i + (j * len)));
949 output.append(NEWLINE);
950 output.append(new Format("%" + (maxid) + "s").form(" ")).append(" ");
952 // Print out the matching chars
953 for (int i = 0; i < len; i++)
957 if ((i + (j * len)) < seqRes.length())
959 if (seqRes.charAt(i + (j * len)) == strRes
960 .charAt(i + (j * len))
961 && !jalview.util.Comparison.isGap(seqRes.charAt(i
967 else if (type.equals("pep"))
969 if (ResidueProperties.getPAM250(seqRes.charAt(i + (j * len)),
970 strRes.charAt(i + (j * len))) > 0)
984 } catch (IndexOutOfBoundsException e)
989 // Now print the second aligned sequence
990 output = output.append(NEWLINE);
991 output = output.append(new Format("%" + (maxid) + "s").form(strName))
993 for (int i = 0; i < len; i++)
995 if ((i + (j * len)) < strRes.length())
997 output.append(strRes.charAt(i + (j * len)));
1000 output.append(NEWLINE).append(NEWLINE);
1002 float pid = (float) matchedSeqCount / seqRes.length() * 100;
1003 if (pid < SiftsSettings.getFailSafePIDThreshold())
1005 throw new SiftsException(
1006 ">>> Low PID detected for SIFTs mapping...");
1008 output.append("Length of alignment = " + seqRes.length()).append(
1010 output.append(new Format("Percentage ID = %2.2f").form(pid));
1011 output.append(NEWLINE);
1016 public int getEntityCount()
1018 return siftsEntry.getEntity().size();
1022 public String getDbAccessionId()
1024 return siftsEntry.getDbAccessionId();
1028 public String getDbCoordSys()
1030 return siftsEntry.getDbCoordSys();
1034 public String getDbEvidence()
1036 return siftsEntry.getDbEvidence();
1040 public String getDbSource()
1042 return siftsEntry.getDbSource();
1046 public String getDbVersion()
1048 return siftsEntry.getDbVersion();