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.Format;
33 import jalview.xml.binding.sifts.Entry;
34 import jalview.xml.binding.sifts.Entry.Entity;
35 import jalview.xml.binding.sifts.Entry.Entity.Segment;
36 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListMapRegion.MapRegion;
37 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue;
38 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.CrossRefDb;
39 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.ResidueDetail;
42 import java.io.FileInputStream;
43 import java.io.FileOutputStream;
44 import java.io.IOException;
45 import java.io.InputStream;
46 import java.io.PrintStream;
48 import java.net.URLConnection;
49 import java.nio.file.Files;
50 import java.nio.file.Path;
51 import java.nio.file.attribute.BasicFileAttributes;
52 import java.util.ArrayList;
53 import java.util.Arrays;
54 import java.util.Collection;
55 import java.util.Collections;
56 import java.util.Date;
57 import java.util.HashMap;
58 import java.util.HashSet;
59 import java.util.List;
62 import java.util.TreeMap;
63 import java.util.zip.GZIPInputStream;
65 import javax.xml.bind.JAXBContext;
66 import javax.xml.bind.Unmarshaller;
67 import javax.xml.stream.XMLInputFactory;
68 import javax.xml.stream.XMLStreamReader;
71 import MCview.PDBChain;
73 public class SiftsClient implements SiftsClientI
75 private Entry siftsEntry;
77 private StructureFile pdb;
81 private String structId;
83 // private String segStartEnd;
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 public enum CoordinateSys
107 UNIPROT("UniProt"), PDB("PDBresnum"), PDBe("PDBe");
110 private CoordinateSys(String name)
115 public String getName()
121 public 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);
155 * Parse the given SIFTs File and return a JAXB POJO of parsed data
158 * - the GZipped SIFTs XML file to parse
161 * if a problem occurs while parsing the SIFTs XML
163 private Entry parseSIFTs(File siftFile) throws SiftsException
165 try (InputStream in = new FileInputStream(siftFile);
166 GZIPInputStream gzis = new GZIPInputStream(in);)
168 // System.out.println("File : " + siftFile.getAbsolutePath());
169 JAXBContext jc = JAXBContext.newInstance("jalview.xml.binding.sifts");
170 XMLStreamReader streamReader = XMLInputFactory.newInstance()
171 .createXMLStreamReader(gzis);
172 Unmarshaller um = jc.createUnmarshaller();
173 return (Entry) um.unmarshal(streamReader);
174 } catch (Exception e)
177 throw new SiftsException(e.getMessage());
182 * Get a SIFTs XML file for a given PDB Id from Cache or download from FTP
183 * repository if not found in cache
186 * @return SIFTs XML file
187 * @throws SiftsException
189 public static File getSiftsFile(String pdbId) throws SiftsException
191 String siftsFileName = SiftsSettings.getSiftDownloadDirectory()
192 + pdbId.toLowerCase() + ".xml.gz";
193 File siftsFile = new File(siftsFileName);
194 if (siftsFile.exists())
196 // The line below is required for unit testing... don't comment it out!!!
197 System.out.println(">>> SIFTS File already downloaded for " + pdbId);
199 if (isFileOlderThanThreshold(siftsFile,
200 SiftsSettings.getCacheThresholdInDays()))
202 File oldSiftsFile = new File(siftsFileName + "_old");
203 siftsFile.renameTo(oldSiftsFile);
206 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
207 oldSiftsFile.delete();
209 } catch (IOException e)
212 oldSiftsFile.renameTo(siftsFile);
213 return new File(siftsFileName);
219 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
220 } catch (IOException e)
222 throw new SiftsException(e.getMessage());
228 * This method enables checking if a cached file has exceeded a certain
234 * the threshold in days
237 public static boolean isFileOlderThanThreshold(File file, int noOfDays)
239 Path filePath = file.toPath();
240 BasicFileAttributes attr;
244 attr = Files.readAttributes(filePath, BasicFileAttributes.class);
245 diffInDays = (int) ((new Date().getTime() - attr.lastModifiedTime()
246 .toMillis()) / (1000 * 60 * 60 * 24));
247 // System.out.println("Diff in days : " + diffInDays);
248 } catch (IOException e)
252 return noOfDays <= diffInDays;
256 * Download a SIFTs XML file for a given PDB Id from an FTP repository
259 * @return downloaded SIFTs XML file
260 * @throws SiftsException
261 * @throws IOException
263 public static File downloadSiftsFile(String pdbId) throws SiftsException,
266 if (pdbId.contains(".cif"))
268 pdbId = pdbId.replace(".cif", "");
270 String siftFile = pdbId + ".xml.gz";
271 String siftsFileFTPURL = SIFTS_FTP_BASE_URL + siftFile;
272 String downloadedSiftsFile = SiftsSettings.getSiftDownloadDirectory()
274 File siftsDownloadDir = new File(
275 SiftsSettings.getSiftDownloadDirectory());
276 if (!siftsDownloadDir.exists())
278 siftsDownloadDir.mkdirs();
280 // System.out.println(">> Download ftp url : " + siftsFileFTPURL);
281 URL url = new URL(siftsFileFTPURL);
282 URLConnection conn = url.openConnection();
283 InputStream inputStream = conn.getInputStream();
284 FileOutputStream outputStream = new FileOutputStream(
285 downloadedSiftsFile);
286 byte[] buffer = new byte[BUFFER_SIZE];
288 while ((bytesRead = inputStream.read(buffer)) != -1)
290 outputStream.write(buffer, 0, bytesRead);
292 outputStream.close();
294 // System.out.println(">>> File downloaded : " + downloadedSiftsFile);
295 return new File(downloadedSiftsFile);
299 * Delete the SIFTs file for the given PDB Id in the local SIFTs download
303 * @return true if the file was deleted or doesn't exist
305 public static boolean deleteSiftsFileByPDBId(String pdbId)
307 File siftsFile = new File(SiftsSettings.getSiftDownloadDirectory()
308 + pdbId.toLowerCase() + ".xml.gz");
309 if (siftsFile.exists())
311 return siftsFile.delete();
317 * Get a valid SIFTs DBRef for the given sequence current SIFTs entry
320 * - the target sequence for the operation
321 * @return a valid DBRefEntry that is SIFTs compatible
323 * if no valid source DBRefEntry was found for the given sequences
325 public DBRefEntryI getValidSourceDBRef(SequenceI seq)
326 throws SiftsException
328 DBRefEntryI sourceDBRef = null;
329 sourceDBRef = seq.getSourceDBRef();
330 if (sourceDBRef != null && isValidDBRefEntry(sourceDBRef))
336 DBRefEntry[] dbRefs = seq.getDBRefs();
337 if (dbRefs == null || dbRefs.length < 1)
339 throw new SiftsException(
340 "Source DBRef could not be determined. DBRefs might not have been retrieved.");
343 for (DBRefEntryI dbRef : dbRefs)
345 if (dbRef == null || dbRef.getAccessionId() == null
346 || dbRef.getSource() == null)
350 if (isFoundInSiftsEntry(dbRef.getAccessionId())
351 && (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT) || dbRef
352 .getSource().equalsIgnoreCase(DBRefSource.PDB)))
354 seq.setSourceDBRef(dbRef);
359 if (sourceDBRef != null && isValidDBRefEntry(sourceDBRef))
363 throw new SiftsException("Could not get source DB Ref");
367 * Check that the DBRef Entry is properly populated and is available in this
368 * SiftClient instance
371 * - DBRefEntry to validate
372 * @return true validation is successful otherwise false is returned.
374 boolean isValidDBRefEntry(DBRefEntryI entry)
376 return entry != null && entry.getAccessionId() != null
377 && isFoundInSiftsEntry(entry.getAccessionId());
381 public HashSet<String> getAllMappingAccession()
383 HashSet<String> accessions = new HashSet<String>();
384 List<Entity> entities = siftsEntry.getEntity();
385 for (Entity entity : entities)
387 List<Segment> segments = entity.getSegment();
388 for (Segment segment : segments)
390 List<MapRegion> mapRegions = segment.getListMapRegion()
392 for (MapRegion mapRegion : mapRegions)
395 .add(mapRegion.getDb().getDbAccessionId().toLowerCase());
403 public StructureMapping getSiftsStructureMapping(SequenceI seq,
404 String pdbFile, String chain) throws SiftsException
406 structId = (chain == null) ? pdbId : pdbId + "|" + chain;
407 System.out.println("Getting mapping for: " + pdbId + "|" + chain
408 + " : seq- " + seq.getName());
410 final StringBuilder mappingDetails = new StringBuilder(128);
411 PrintStream ps = new PrintStream(System.out)
414 public void print(String x)
416 mappingDetails.append(x);
420 public void println()
422 mappingDetails.append(NEWLINE);
425 HashMap<Integer, int[]> mapping = getGreedyMapping(chain, seq, ps);
427 String mappingOutput = mappingDetails.toString();
428 StructureMapping siftsMapping = new StructureMapping(seq, pdbFile,
429 pdbId, chain, mapping, mappingOutput);
434 public HashMap<Integer, int[]> getGreedyMapping(String entityId,
435 SequenceI seq, java.io.PrintStream os) throws SiftsException
437 List<Integer> omitNonObserved = new ArrayList<Integer>();
438 int nonObservedShiftIndex = 0;
439 // System.out.println("Generating mappings for : " + entityId);
440 Entity entity = null;
441 entity = getEntityById(entityId);
442 String originalSeq = AlignSeq.extractGaps(
443 jalview.util.Comparison.GapChars, seq.getSequenceAsString());
444 HashMap<Integer, int[]> mapping = new HashMap<Integer, int[]>();
445 DBRefEntryI sourceDBRef = seq.getSourceDBRef();
446 sourceDBRef = getValidSourceDBRef(seq);
447 // TODO ensure sequence start/end is in the same coordinate system and
448 // consistent with the choosen sourceDBRef
450 // set sequence coordinate system - default value is UniProt
451 if (sourceDBRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
453 seqCoordSys = CoordinateSys.PDB;
456 HashSet<String> dbRefAccessionIdsString = new HashSet<String>();
457 for (DBRefEntry dbref : seq.getDBRefs())
459 dbRefAccessionIdsString.add(dbref.getAccessionId().toLowerCase());
461 dbRefAccessionIdsString.add(sourceDBRef.getAccessionId().toLowerCase());
463 curDBRefAccessionIdsString = dbRefAccessionIdsString;
464 curSourceDBRef = sourceDBRef.getAccessionId();
466 TreeMap<Integer, String> resNumMap = new TreeMap<Integer, String>();
467 List<Segment> segments = entity.getSegment();
468 for (Segment segment : segments)
470 // segStartEnd = segment.getStart() + " - " + segment.getEnd();
471 // System.out.println("Mapping segments : " + segment.getSegId() + "\\"
473 List<Residue> residues = segment.getListResidue().getResidue();
474 for (Residue residue : residues)
476 int currSeqIndex = UNASSIGNED;
477 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
478 CrossRefDb pdbRefDb = null;
479 for (CrossRefDb cRefDb : cRefDbs)
481 if (cRefDb.getDbSource().equalsIgnoreCase(DBRefSource.PDB))
485 if (cRefDb.getDbCoordSys()
486 .equalsIgnoreCase(seqCoordSys.getName())
487 && isAccessionMatched(cRefDb.getDbAccessionId()))
489 String resNumIndexString = cRefDb.getDbResNum()
490 .equalsIgnoreCase("None") ? String.valueOf(UNASSIGNED)
491 : cRefDb.getDbResNum();
494 currSeqIndex = Integer.valueOf(resNumIndexString);
495 } catch (NumberFormatException nfe)
497 currSeqIndex = Integer.valueOf(resNumIndexString
498 .split("[a-zA-Z]")[0]);
501 if (pdbRefDb != null)
503 break;// exit loop if pdb and uniprot are already found
507 if (currSeqIndex == UNASSIGNED)
511 if (currSeqIndex >= seq.getStart() && currSeqIndex <= seq.getEnd())
516 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
517 .getDbResNum()) : Integer.valueOf(pdbRefDb
519 } catch (NumberFormatException nfe)
521 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
522 .getDbResNum()) : Integer.valueOf(pdbRefDb
523 .getDbResNum().split("[a-zA-Z]")[0]);
527 if (isResidueObserved(residue)
528 || seqCoordSys == CoordinateSys.UNIPROT)
530 char resCharCode = ResidueProperties
531 .getSingleCharacterCode(ResidueProperties
532 .getCanonicalAminoAcid(residue.getDbResName()));
533 resNumMap.put(currSeqIndex, String.valueOf(resCharCode));
537 omitNonObserved.add(currSeqIndex);
538 ++nonObservedShiftIndex;
540 mapping.put(currSeqIndex - nonObservedShiftIndex, new int[] {
541 Integer.valueOf(resNum), UNASSIGNED });
547 populateAtomPositions(entityId, mapping);
548 } catch (Exception e)
552 if (seqCoordSys == CoordinateSys.UNIPROT)
554 padWithGaps(resNumMap, omitNonObserved);
556 int seqStart = UNASSIGNED;
557 int seqEnd = UNASSIGNED;
558 int pdbStart = UNASSIGNED;
559 int pdbEnd = UNASSIGNED;
561 Integer[] keys = mapping.keySet().toArray(new Integer[0]);
565 throw new SiftsException(">>> Empty SIFTS mapping generated!!");
568 seqEnd = keys[keys.length - 1];
570 String matchedSeq = originalSeq;
571 if (seqStart != UNASSIGNED)
573 pdbStart = mapping.get(seqStart)[PDB_RES_POS];
574 pdbEnd = mapping.get(seqEnd)[PDB_RES_POS];
575 int orignalSeqStart = seq.getStart();
576 if (orignalSeqStart >= 1)
578 int subSeqStart = (seqStart >= orignalSeqStart) ? seqStart
579 - orignalSeqStart : 0;
580 int subSeqEnd = seqEnd - (orignalSeqStart - 1);
581 subSeqEnd = originalSeq.length() < subSeqEnd ? originalSeq.length()
583 matchedSeq = originalSeq.substring(subSeqStart, subSeqEnd);
587 matchedSeq = originalSeq.substring(1, originalSeq.length());
591 StringBuilder targetStrucSeqs = new StringBuilder();
592 for (String res : resNumMap.values())
594 targetStrucSeqs.append(res);
599 MappingOutputPojo mop = new MappingOutputPojo();
600 mop.setSeqStart(pdbStart);
601 mop.setSeqEnd(pdbEnd);
602 mop.setSeqName(seq.getName());
603 mop.setSeqResidue(matchedSeq);
605 mop.setStrStart(seqStart);
606 mop.setStrEnd(seqEnd);
607 mop.setStrName(structId);
608 mop.setStrResidue(targetStrucSeqs.toString());
611 os.print(getMappingOutput(mop).toString());
620 * Target chain to populate mapping of its atom positions.
622 * Two dimension array of residue index versus atom position
623 * @throws IllegalArgumentException
624 * Thrown if chainId or mapping is null
625 * @throws SiftsException
627 void populateAtomPositions(String chainId, Map<Integer, int[]> mapping)
628 throws IllegalArgumentException, SiftsException
632 PDBChain chain = pdb.findChain(chainId);
634 if (chain == null || mapping == null)
636 throw new IllegalArgumentException(
637 "Chain id or mapping must not be null.");
639 for (int[] map : mapping.values())
641 if (map[PDB_RES_POS] != UNASSIGNED)
643 map[PDB_ATOM_POS] = getAtomIndex(map[PDB_RES_POS], chain.atoms);
646 } catch (NullPointerException e)
648 throw new SiftsException(e.getMessage());
649 } catch (Exception e)
651 throw new SiftsException(e.getMessage());
657 * @param residueIndex
658 * The residue index used for the search
660 * A collection of Atom to search
661 * @return atom position for the given residue index
663 int getAtomIndex(int residueIndex, Collection<Atom> atoms)
667 throw new IllegalArgumentException(
668 "atoms collection must not be null!");
670 for (Atom atom : atoms)
672 if (atom.resNumber == residueIndex)
674 return atom.atomIndex;
681 * Checks if the residue instance is marked 'Not_observed' or not
686 private boolean isResidueObserved(Residue residue)
688 Set<String> annotations = getResidueAnnotaitons(residue,
689 ResidueDetailType.ANNOTATION);
690 if (annotations == null || annotations.isEmpty())
694 for (String annotation : annotations)
696 if (annotation.equalsIgnoreCase(NOT_OBSERVED))
705 * Get annotation String for a given residue and annotation type
711 private Set<String> getResidueAnnotaitons(Residue residue,
712 ResidueDetailType type)
714 HashSet<String> foundAnnotations = new HashSet<String>();
715 List<ResidueDetail> resDetails = residue.getResidueDetail();
716 for (ResidueDetail resDetail : resDetails)
718 if (resDetail.getProperty().equalsIgnoreCase(type.getCode()))
720 foundAnnotations.add(resDetail.getContent());
723 return foundAnnotations;
727 public boolean isAccessionMatched(String accession)
729 boolean isStrictMatch = true;
730 return isStrictMatch ? curSourceDBRef.equalsIgnoreCase(accession)
731 : curDBRefAccessionIdsString.contains(accession.toLowerCase());
734 private boolean isFoundInSiftsEntry(String accessionId)
736 Set<String> siftsDBRefs = getAllMappingAccession();
737 return accessionId != null
738 && siftsDBRefs.contains(accessionId.toLowerCase());
742 * Pad omitted residue positions in PDB sequence with gaps
746 void padWithGaps(Map<Integer, String> resNumMap,
747 List<Integer> omitNonObserved)
749 if (resNumMap == null || resNumMap.isEmpty())
753 Integer[] keys = resNumMap.keySet().toArray(new Integer[0]);
755 int firstIndex = keys[0];
756 int lastIndex = keys[keys.length - 1];
757 // System.out.println("Min value " + firstIndex);
758 // System.out.println("Max value " + lastIndex);
759 for (int x = firstIndex; x <= lastIndex; x++)
761 if (!resNumMap.containsKey(x) && !omitNonObserved.contains(x))
763 resNumMap.put(x, "-");
771 public Entity getEntityById(String id) throws SiftsException
773 // Sometimes SIFTS mappings are wrongly swapped between different chains of
774 // a PDB entry. This results to wrong mappings being generated. The boolean
775 // flag 'isGetEntityIdDirectly, determines whether an entity to process is
776 // determined by a greedy heuristic search or by just matching the Chain Id
777 // directly against the entity Id tag. Setting the default value to 'false'
778 // utilise the heuristic search which always produces correct mappings but
779 // less optimised processing, where as changing the value to 'true'
780 // optimises performance but might result to incorrect mapping in some cases
781 // where SIFTS mappings are wrongly swapped between different chains.
782 // boolean isGetEntityIdDirectly = false;
783 // if (isGetEntityIdDirectly)
785 // List<Entity> entities = siftsEntry.getEntity();
786 // for (Entity entity : entities)
788 // if (!entity.getEntityId().equalsIgnoreCase(id))
795 Entity entity = getEntityByMostOptimalMatchedId(id);
800 throw new SiftsException("Entity " + id + " not found");
804 * This method was added because EntityId is NOT always equal to ChainId.
805 * Hence, it provides the logic to greedily detect the "true" Entity for a
806 * given chainId where discrepancies exist.
811 public Entity getEntityByMostOptimalMatchedId(String chainId)
813 // System.out.println("---> advanced greedy entityId matching block entered..");
814 List<Entity> entities = siftsEntry.getEntity();
815 SiftsEntitySortPojo[] sPojo = new SiftsEntitySortPojo[entities.size()];
817 for (Entity entity : entities)
819 sPojo[count] = new SiftsEntitySortPojo();
820 sPojo[count].entityId = entity.getEntityId();
822 List<Segment> segments = entity.getSegment();
823 for (Segment segment : segments)
825 List<Residue> residues = segment.getListResidue().getResidue();
826 for (Residue residue : residues)
828 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
829 for (CrossRefDb cRefDb : cRefDbs)
831 if (!cRefDb.getDbSource().equalsIgnoreCase("PDB"))
835 ++sPojo[count].resCount;
836 if (cRefDb.getDbChainId().equalsIgnoreCase(chainId))
838 ++sPojo[count].chainIdFreq;
843 sPojo[count].pid = 100 * (sPojo[count].chainIdFreq / sPojo[count].resCount);
846 Arrays.sort(sPojo, Collections.reverseOrder());
847 // System.out.println("highest matched entity : " + sPojo[0].entityId);
848 // System.out.println("highest matched pid : " + sPojo[0].pid);
850 if (sPojo[0].entityId != null)
852 for (Entity entity : entities)
854 if (!entity.getEntityId().equalsIgnoreCase(sPojo[0].entityId))
864 public class SiftsEntitySortPojo implements
865 Comparable<SiftsEntitySortPojo>
867 public String entityId;
869 public int chainIdFreq;
876 public int compareTo(SiftsEntitySortPojo o)
878 return this.pid - o.pid;
884 public StringBuffer getMappingOutput(MappingOutputPojo mp)
885 throws SiftsException
887 String seqRes = mp.getSeqResidue();
888 String seqName = mp.getSeqName();
889 int sStart = mp.getSeqStart();
890 int sEnd = mp.getSeqEnd();
892 String strRes = mp.getStrResidue();
893 String strName = mp.getStrName();
894 int pdbStart = mp.getStrStart();
895 int pdbEnd = mp.getStrEnd();
897 String type = mp.getType();
899 int maxid = (seqName.length() >= strName.length()) ? seqName.length()
901 int len = 72 - maxid - 1;
903 int nochunks = ((seqRes.length()) / len)
904 + ((seqRes.length()) % len > 0 ? 1 : 0);
906 StringBuffer output = new StringBuffer();
907 output.append(NEWLINE);
908 output.append("Sequence \u27f7 Structure mapping details").append(
910 output.append("Method: SIFTS");
911 output.append(NEWLINE).append(NEWLINE);
913 output.append(new Format("%" + maxid + "s").form(seqName));
914 output.append(" : ");
915 output.append(String.valueOf(sStart));
916 output.append(" - ");
917 output.append(String.valueOf(sEnd));
918 output.append(" Maps to ");
919 output.append(NEWLINE);
920 output.append(new Format("%" + maxid + "s").form(structId));
921 output.append(" : ");
922 output.append(String.valueOf(pdbStart));
923 output.append(" - ");
924 output.append(String.valueOf(pdbEnd));
925 output.append(NEWLINE).append(NEWLINE);
927 int matchedSeqCount = 0;
928 for (int j = 0; j < nochunks; j++)
930 // Print the first aligned sequence
931 output.append(new Format("%" + (maxid) + "s").form(seqName)).append(
934 for (int i = 0; i < len; i++)
936 if ((i + (j * len)) < seqRes.length())
938 output.append(seqRes.charAt(i + (j * len)));
942 output.append(NEWLINE);
943 output.append(new Format("%" + (maxid) + "s").form(" ")).append(" ");
945 // Print out the matching chars
946 for (int i = 0; i < len; i++)
950 if ((i + (j * len)) < seqRes.length())
952 if (seqRes.charAt(i + (j * len)) == strRes
953 .charAt(i + (j * len))
954 && !jalview.util.Comparison.isGap(seqRes.charAt(i
960 else if (type.equals("pep"))
962 if (ResidueProperties.getPAM250(seqRes.charAt(i + (j * len)),
963 strRes.charAt(i + (j * len))) > 0)
977 } catch (IndexOutOfBoundsException e)
982 // Now print the second aligned sequence
983 output = output.append(NEWLINE);
984 output = output.append(new Format("%" + (maxid) + "s").form(strName))
986 for (int i = 0; i < len; i++)
988 if ((i + (j * len)) < strRes.length())
990 output.append(strRes.charAt(i + (j * len)));
993 output.append(NEWLINE).append(NEWLINE);
995 float pid = (float) matchedSeqCount / seqRes.length() * 100;
996 if (pid < SiftsSettings.getFailSafePIDThreshold())
998 throw new SiftsException(">>> Low PID detected for SIFTs mapping...");
1000 output.append("Length of alignment = " + seqRes.length()).append(
1002 output.append(new Format("Percentage ID = %2.2f").form(pid));
1007 public int getEntityCount()
1009 return siftsEntry.getEntity().size();
1013 public String getDbAccessionId()
1015 return siftsEntry.getDbAccessionId();
1019 public String getDbCoordSys()
1021 return siftsEntry.getDbCoordSys();
1025 public String getDbSource()
1027 return siftsEntry.getDbSource();
1031 public String getDbVersion()
1033 return siftsEntry.getDbVersion();