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 String siftFile = pdbId + ".xml.gz";
288 String siftsFileFTPURL = SIFTS_FTP_BASE_URL + siftFile;
289 String downloadedSiftsFile = SiftsSettings.getSiftDownloadDirectory()
291 File siftsDownloadDir = new File(
292 SiftsSettings.getSiftDownloadDirectory());
293 if (!siftsDownloadDir.exists())
295 siftsDownloadDir.mkdirs();
299 // System.out.println(">> Download ftp url : " + siftsFileFTPURL);
300 URL url = new URL(siftsFileFTPURL);
301 URLConnection conn = url.openConnection();
302 InputStream inputStream = conn.getInputStream();
303 FileOutputStream outputStream = new FileOutputStream(
304 downloadedSiftsFile);
305 byte[] buffer = new byte[BUFFER_SIZE];
307 while ((bytesRead = inputStream.read(buffer)) != -1)
309 outputStream.write(buffer, 0, bytesRead);
311 outputStream.close();
313 // System.out.println(">>> File downloaded : " + downloadedSiftsFile);
314 } catch (IOException ex)
316 throw new SiftsException(ex.getMessage());
318 return new File(downloadedSiftsFile);
322 * Delete the SIFTs file for the given PDB Id in the local SIFTs download
326 * @return true if the file was deleted or doesn't exist
328 public static boolean deleteSiftsFileByPDBId(String pdbId)
330 File siftsFile = new File(SiftsSettings.getSiftDownloadDirectory()
331 + pdbId.toLowerCase() + ".xml.gz");
332 if (siftsFile.exists())
334 return siftsFile.delete();
340 * Get a valid SIFTs DBRef for the given sequence current SIFTs entry
343 * - the target sequence for the operation
344 * @return a valid DBRefEntry that is SIFTs compatible
346 * if no valid source DBRefEntry was found for the given sequences
348 public DBRefEntryI getValidSourceDBRef(SequenceI seq)
349 throws SiftsException
351 DBRefEntryI sourceDBRef = null;
352 sourceDBRef = seq.getSourceDBRef();
353 if (sourceDBRef != null && isValidDBRefEntry(sourceDBRef))
359 DBRefEntry[] dbRefs = seq.getDBRefs();
360 if (dbRefs == null || dbRefs.length < 1)
362 throw new SiftsException("Could not get source DB Ref");
365 for (DBRefEntryI dbRef : dbRefs)
367 if (dbRef == null || dbRef.getAccessionId() == null
368 || dbRef.getSource() == null)
372 if (isFoundInSiftsEntry(dbRef.getAccessionId())
373 && (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT) || dbRef
374 .getSource().equalsIgnoreCase(DBRefSource.PDB)))
380 if (sourceDBRef != null && isValidDBRefEntry(sourceDBRef))
384 throw new SiftsException("Could not get source DB Ref");
388 * Check that the DBRef Entry is properly populated and is available in this
389 * SiftClient instance
392 * - DBRefEntry to validate
393 * @return true validation is successful otherwise false is returned.
395 private boolean isValidDBRefEntry(DBRefEntryI entry)
397 return entry != null && entry.getAccessionId() != null
398 && isFoundInSiftsEntry(entry.getAccessionId());
402 public HashSet<String> getAllMappingAccession()
404 HashSet<String> accessions = new HashSet<String>();
405 List<Entity> entities = siftsEntry.getEntity();
406 for (Entity entity : entities)
408 List<Segment> segments = entity.getSegment();
409 for (Segment segment : segments)
411 List<MapRegion> mapRegions = segment.getListMapRegion()
413 for (MapRegion mapRegion : mapRegions)
415 accessions.add(mapRegion.getDb().getDbAccessionId());
423 public StructureMapping getSiftsStructureMapping(SequenceI seq,
424 String pdbFile, String chain) throws SiftsException
426 structId = (chain == null) ? pdbId : pdbId + "|" + chain;
427 System.out.println("Getting mapping for: " + pdbId + "|" + chain
428 + " : seq- " + seq.getName());
430 final StringBuilder mappingDetails = new StringBuilder(128);
431 PrintStream ps = new PrintStream(System.out)
434 public void print(String x)
436 mappingDetails.append(x);
440 public void println()
442 mappingDetails.append(NEWLINE);
445 HashMap<Integer, int[]> mapping = getGreedyMapping(chain, seq, ps);
447 String mappingOutput = mappingDetails.toString();
448 StructureMapping siftsMapping = new StructureMapping(seq, pdbFile,
449 pdbId, chain, mapping, mappingOutput);
454 public HashMap<Integer, int[]> getGreedyMapping(String entityId,
455 SequenceI seq, java.io.PrintStream os) throws SiftsException
457 ArrayList<Integer> omitNonObserved = new ArrayList<Integer>();
458 int nonObservedShiftIndex = 0;
459 System.out.println("Generating mappings for : " + entityId);
460 Entity entity = null;
461 entity = getEntityById(entityId);
462 String originalSeq = AlignSeq.extractGaps(
463 jalview.util.Comparison.GapChars, seq.getSequenceAsString());
464 HashMap<Integer, int[]> mapping = new HashMap<Integer, int[]>();
465 DBRefEntryI sourceDBRef = seq.getSourceDBRef();
466 if (sourceDBRef == null)
468 sourceDBRef = getValidSourceDBRef(seq);
469 // TODO ensure sequence start/end is in the same coordinate system and
470 // consistent with the choosen sourceDBRef
473 // set sequence coordinate system - default value is UniProt
474 if (sourceDBRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
476 seqCoordSys = CoordinateSys.PDB;
479 HashSet<String> dbRefAccessionIdsString = new HashSet<String>();
480 for (DBRefEntry dbref : seq.getDBRefs())
482 dbRefAccessionIdsString.add(dbref.getAccessionId().toLowerCase());
484 dbRefAccessionIdsString.add(sourceDBRef.getAccessionId().toLowerCase());
486 curDBRefAccessionIdsString = dbRefAccessionIdsString;
487 curSourceDBRef = sourceDBRef.getAccessionId();
489 TreeMap<Integer, String> resNumMap = new TreeMap<Integer, String>();
490 List<Segment> segments = entity.getSegment();
491 for (Segment segment : segments)
493 segStartEnd = segment.getStart() + " - " + segment.getEnd();
494 System.out.println("Mappging segments : " + segment.getSegId() + "\\"
496 List<Residue> residues = segment.getListResidue().getResidue();
497 for (Residue residue : residues)
499 int currSeqIndex = UNASSIGNED;
500 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
501 CrossRefDb pdbRefDb = null;
502 for (CrossRefDb cRefDb : cRefDbs)
504 if (cRefDb.getDbSource().equalsIgnoreCase(DBRefSource.PDB))
508 if (cRefDb.getDbCoordSys()
509 .equalsIgnoreCase(seqCoordSys.getName())
510 && isAccessionMatched(cRefDb.getDbAccessionId()))
512 String resNumIndexString = cRefDb.getDbResNum()
513 .equalsIgnoreCase("None") ? String.valueOf(UNASSIGNED)
514 : cRefDb.getDbResNum();
517 currSeqIndex = Integer.valueOf(resNumIndexString);
518 } catch (NumberFormatException nfe)
520 currSeqIndex = Integer.valueOf(resNumIndexString
521 .split("[a-zA-Z]")[0]);
523 if (pdbRefDb != null)
525 break;// exit loop if pdb and uniprot are already found
529 if (currSeqIndex == UNASSIGNED)
533 if (currSeqIndex > seq.getStart() && currSeqIndex <= seq.getEnd())
538 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
539 .getDbResNum()) : Integer.valueOf(pdbRefDb
541 } catch (NumberFormatException nfe)
543 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
544 .getDbResNum()) : Integer.valueOf(pdbRefDb
545 .getDbResNum().split("[a-zA-Z]")[0]);
548 if (isResidueObserved(residue)
549 || seqCoordSys == CoordinateSys.UNIPROT)
551 char resCharCode = ResidueProperties
552 .getSingleCharacterCode(ResidueProperties
553 .getCanonicalAminoAcid(residue.getDbResName()));
554 resNumMap.put(currSeqIndex, String.valueOf(resCharCode));
558 omitNonObserved.add(currSeqIndex);
559 ++nonObservedShiftIndex;
561 mapping.put(currSeqIndex - nonObservedShiftIndex, new int[] {
562 Integer.valueOf(resNum), UNASSIGNED });
568 populateAtomPositions(entityId, mapping);
569 } catch (Exception e)
573 if (seqCoordSys == CoordinateSys.UNIPROT)
575 padWithGaps(resNumMap, omitNonObserved);
577 int seqStart = UNASSIGNED;
578 int seqEnd = UNASSIGNED;
579 int pdbStart = UNASSIGNED;
580 int pdbEnd = UNASSIGNED;
582 Integer[] keys = mapping.keySet().toArray(new Integer[0]);
586 throw new SiftsException(">>> Empty SIFTS mapping generated!!");
589 seqEnd = keys[keys.length - 1];
591 String matchedSeq = originalSeq;
592 if (seqStart != UNASSIGNED)
594 pdbStart = mapping.get(seqStart)[PDB_RES_POS];
595 pdbEnd = mapping.get(seqEnd)[PDB_RES_POS];
596 int orignalSeqStart = seq.getStart();
597 if (orignalSeqStart >= 1)
599 int subSeqStart = seqStart - orignalSeqStart;
600 int subSeqEnd = seqEnd - (orignalSeqStart - 1);
601 subSeqEnd = originalSeq.length() < subSeqEnd ? originalSeq.length()
603 matchedSeq = originalSeq.substring(subSeqStart, subSeqEnd);
607 StringBuilder targetStrucSeqs = new StringBuilder();
608 for (String res : resNumMap.values())
610 targetStrucSeqs.append(res);
615 MappingOutputPojo mop = new MappingOutputPojo();
616 mop.setSeqStart(seqStart);
617 mop.setSeqEnd(seqEnd);
618 mop.setSeqName(seq.getName());
619 mop.setSeqResidue(matchedSeq);
621 mop.setStrStart(pdbStart);
622 mop.setStrEnd(pdbEnd);
623 mop.setStrName(structId);
624 mop.setStrResidue(targetStrucSeqs.toString());
627 os.print(getMappingOutput(mop).toString());
633 * Checks if the residue instance is marked 'Not_observed' or not
638 private boolean isResidueObserved(Residue residue)
640 HashSet<String> annotations = getResidueAnnotaitons(residue,
641 ResidueDetailType.ANNOTATION);
642 if (annotations == null || annotations.isEmpty())
646 for (String annotation : annotations)
648 if (annotation.equalsIgnoreCase(NOT_OBSERVED))
657 * Get annotation String for a given residue and annotation type
663 private HashSet<String> getResidueAnnotaitons(Residue residue,
664 ResidueDetailType type)
666 HashSet<String> foundAnnotations = new HashSet<String>();
667 List<ResidueDetail> resDetails = residue.getResidueDetail();
668 for (ResidueDetail resDetail : resDetails)
670 if (resDetail.getProperty().equalsIgnoreCase(type.getCode()))
672 foundAnnotations.add(resDetail.getContent());
675 return foundAnnotations;
679 public boolean isAccessionMatched(String accession)
681 boolean isStrictMatch = true;
682 return isStrictMatch ? curSourceDBRef.equalsIgnoreCase(accession)
683 : curDBRefAccessionIdsString.contains(accession.toLowerCase());
686 private boolean isFoundInSiftsEntry(String accessionId)
688 return accessionId != null
689 && getAllMappingAccession().contains(accessionId);
693 * Pad omitted residue positions in PDB sequence with gaps
697 void padWithGaps(TreeMap<Integer, String> resNumMap,
698 ArrayList<Integer> omitNonObserved)
700 if (resNumMap == null || resNumMap.isEmpty())
704 Integer[] keys = resNumMap.keySet().toArray(new Integer[0]);
706 int firstIndex = keys[0];
707 int lastIndex = keys[keys.length - 1];
708 System.out.println("Min value " + firstIndex);
709 System.out.println("Max value " + lastIndex);
710 for (int x = firstIndex; x <= lastIndex; x++)
712 if (!resNumMap.containsKey(x) && !omitNonObserved.contains(x))
714 resNumMap.put(x, "-");
722 * Target chain to populate mapping of its atom positions.
724 * Two dimension array of residue index versus atom position
725 * @throws IllegalArgumentException
726 * Thrown if chainId or mapping is null
728 void populateAtomPositions(String chainId, HashMap<Integer, int[]> mapping)
729 throws IllegalArgumentException
731 PDBChain chain = pdb.findChain(chainId);
732 if (chain == null || mapping == null)
734 throw new IllegalArgumentException(
735 "Chain id or mapping must not be null.");
737 for (int[] map : mapping.values())
739 if (map[PDB_RES_POS] != UNASSIGNED)
741 map[PDB_ATOM_POS] = getAtomIndex(map[PDB_RES_POS], chain.atoms);
748 * @param residueIndex
749 * The residue index used for the search
751 * A collection of Atom to search
752 * @return atom position for the given residue index
754 int getAtomIndex(int residueIndex, Collection<Atom> atoms)
758 throw new IllegalArgumentException(
759 "atoms collection must not be null!");
761 for (Atom atom : atoms)
763 if (atom.resNumber == residueIndex)
765 return atom.atomIndex;
772 public Entity getEntityById(String id) throws SiftsException
774 List<Entity> entities = siftsEntry.getEntity();
775 for (Entity entity : entities)
777 if (!entity.getEntityId().equalsIgnoreCase(id))
783 Entity entity = getEntityByMostOptimalMatchedId(id);
788 throw new SiftsException("Entity " + id + " not found");
792 * This method was added because EntityId is NOT always equal to ChainId.
793 * Hence, it provides the logic to greedily detect the "true" Entity for a
794 * given chainId where discrepancies exist.
799 public Entity getEntityByMostOptimalMatchedId(String chainId)
802 .println("--------------> advanced greedy entityId matching block entered..");
803 List<Entity> entities = siftsEntry.getEntity();
804 SiftsEntitySortPojo[] sPojo = new SiftsEntitySortPojo[entities.size()];
806 for (Entity entity : entities)
808 sPojo[count] = new SiftsEntitySortPojo();
809 sPojo[count].entityId = entity.getEntityId();
811 List<Segment> segments = entity.getSegment();
812 for (Segment segment : segments)
814 List<Residue> residues = segment.getListResidue().getResidue();
815 for (Residue residue : residues)
817 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
818 for (CrossRefDb cRefDb : cRefDbs)
820 if (!cRefDb.getDbSource().equalsIgnoreCase("PDB"))
824 ++sPojo[count].resCount;
825 if (cRefDb.getDbChainId().equalsIgnoreCase(chainId))
827 ++sPojo[count].chainIdFreq;
832 sPojo[count].pid = 100 * (sPojo[count].chainIdFreq / sPojo[count].resCount);
835 Arrays.sort(sPojo, Collections.reverseOrder());
836 System.out.println("highest matched entity : " + sPojo[0].entityId);
837 System.out.println("highest matched pid : " + sPojo[0].pid);
839 if (sPojo[0].entityId != null)
841 for (Entity entity : entities)
843 if (!entity.getEntityId().equalsIgnoreCase(sPojo[0].entityId))
853 public class SiftsEntitySortPojo implements
854 Comparable<SiftsEntitySortPojo>
856 public String entityId;
858 public int chainIdFreq;
865 public int compareTo(SiftsEntitySortPojo o)
867 return this.pid - o.pid;
872 public String[] getEntryDBs()
874 System.out.println("\nListing DB entries...");
875 List<String> availDbs = new ArrayList<String>();
876 List<Db> dbs = siftsEntry.getListDB().getDb();
879 availDbs.add(db.getDbSource());
880 System.out.println(db.getDbSource() + " | " + db.getDbCoordSys());
882 return availDbs.toArray(new String[0]);
886 public StringBuffer getMappingOutput(MappingOutputPojo mp)
887 throws SiftsException
889 String seqRes = mp.getSeqResidue();
890 String seqName = mp.getSeqName();
891 int sStart = mp.getSeqStart();
892 int sEnd = mp.getSeqEnd();
894 String strRes = mp.getStrResidue();
895 String strName = mp.getStrName();
896 int pdbStart = mp.getStrStart();
897 int pdbEnd = mp.getStrEnd();
899 String type = mp.getType();
901 int maxid = (seqName.length() >= strName.length()) ? seqName.length()
903 int len = 72 - maxid - 1;
905 int nochunks = ((seqRes.length()) / len)
906 + ((seqRes.length()) % len > 0 ? 1 : 0);
908 StringBuffer output = new StringBuffer();
909 output.append(NEWLINE);
910 output.append("Sequence ⟷ Structure mapping details").append(NEWLINE);
911 output.append("Method: SIFTS");
912 output.append(NEWLINE).append(NEWLINE);
914 output.append(new Format("%" + maxid + "s").form(seqName));
915 output.append(" : ");
916 output.append(String.valueOf(sStart));
917 output.append(" - ");
918 output.append(String.valueOf(sEnd));
919 output.append(" Maps to ");
920 output.append(NEWLINE);
921 output.append(new Format("%" + maxid + "s").form(structId));
922 output.append(" : ");
923 output.append(String.valueOf(pdbStart));
924 output.append(" - ");
925 output.append(String.valueOf(pdbEnd));
926 output.append(NEWLINE).append(NEWLINE);
928 int matchedSeqCount = 0;
929 for (int j = 0; j < nochunks; j++)
931 // Print the first aligned sequence
932 output.append(new Format("%" + (maxid) + "s").form(seqName)).append(
935 for (int i = 0; i < len; i++)
937 if ((i + (j * len)) < seqRes.length())
939 output.append(seqRes.charAt(i + (j * len)));
943 output.append(NEWLINE);
944 output.append(new Format("%" + (maxid) + "s").form(" ")).append(" ");
946 // Print out the matching chars
947 for (int i = 0; i < len; i++)
951 if ((i + (j * len)) < seqRes.length())
953 if (seqRes.charAt(i + (j * len)) == strRes
954 .charAt(i + (j * len))
955 && !jalview.util.Comparison.isGap(seqRes.charAt(i
961 else if (type.equals("pep"))
963 if (ResidueProperties.getPAM250(seqRes.charAt(i + (j * len)),
964 strRes.charAt(i + (j * len))) > 0)
978 } catch (IndexOutOfBoundsException e)
983 // Now print the second aligned sequence
984 output = output.append(NEWLINE);
985 output = output.append(new Format("%" + (maxid) + "s").form(strName))
987 for (int i = 0; i < len; i++)
989 if ((i + (j * len)) < strRes.length())
991 output.append(strRes.charAt(i + (j * len)));
994 output.append(NEWLINE).append(NEWLINE);
996 float pid = (float) matchedSeqCount / seqRes.length() * 100;
997 if (pid < SiftsSettings.getFailSafePIDThreshold())
999 throw new SiftsException(
1000 ">>> Low PID detected for SIFTs mapping...");
1002 output.append("Length of alignment = " + seqRes.length()).append(
1004 output.append(new Format("Percentage ID = %2.2f").form(pid));
1005 output.append(NEWLINE);
1010 public int getEntityCount()
1012 return siftsEntry.getEntity().size();
1016 public String getDbAccessionId()
1018 return siftsEntry.getDbAccessionId();
1022 public String getDbCoordSys()
1024 return siftsEntry.getDbCoordSys();
1028 public String getDbEvidence()
1030 return siftsEntry.getDbEvidence();
1034 public String getDbSource()
1036 return siftsEntry.getDbSource();
1040 public String getDbVersion()
1042 return siftsEntry.getDbVersion();