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.structure.StructureMappingClient;
33 import jalview.structures.models.MappingOutputModel;
34 import jalview.util.Comparison;
35 import jalview.util.DBRefUtils;
36 import jalview.util.Format;
37 import jalview.xml.binding.sifts.Entry;
38 import jalview.xml.binding.sifts.Entry.Entity;
39 import jalview.xml.binding.sifts.Entry.Entity.Segment;
40 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListMapRegion.MapRegion;
41 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue;
42 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.CrossRefDb;
43 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.ResidueDetail;
46 import java.io.FileInputStream;
47 import java.io.FileOutputStream;
48 import java.io.IOException;
49 import java.io.InputStream;
50 import java.io.PrintStream;
52 import java.net.URLConnection;
53 import java.nio.file.Files;
54 import java.nio.file.Path;
55 import java.nio.file.attribute.BasicFileAttributes;
56 import java.util.ArrayList;
57 import java.util.Arrays;
58 import java.util.Collections;
59 import java.util.Date;
60 import java.util.HashMap;
61 import java.util.HashSet;
62 import java.util.List;
65 import java.util.TreeMap;
66 import java.util.zip.GZIPInputStream;
68 import javax.xml.bind.JAXBContext;
69 import javax.xml.bind.Unmarshaller;
70 import javax.xml.stream.XMLInputFactory;
71 import javax.xml.stream.XMLStreamReader;
73 public class SiftsClient extends StructureMappingClient implements
76 private Entry siftsEntry;
80 private String structId;
82 private CoordinateSys seqCoordSys = CoordinateSys.UNIPROT;
84 private static final int BUFFER_SIZE = 4096;
86 public static final int UNASSIGNED = -1;
88 private static final int PDB_RES_POS = 0;
90 private static final String NOT_OBSERVED = "Not_Observed";
92 private static final String SIFTS_FTP_BASE_URL = "http://ftp.ebi.ac.uk/pub/databases/msd/sifts/xml/";
94 private final static String NEWLINE = System.lineSeparator();
96 private String curSourceDBRef;
98 private HashSet<String> curDBRefAccessionIdsString;
100 private enum CoordinateSys
102 UNIPROT("UniProt"), PDB("PDBresnum"), PDBe("PDBe");
105 private CoordinateSys(String name)
110 public String getName()
116 private enum ResidueDetailType
118 NAME_SEC_STRUCTURE("nameSecondaryStructure"), CODE_SEC_STRUCTURE(
119 "codeSecondaryStructure"), ANNOTATION("Annotation");
122 private ResidueDetailType(String code)
127 public String getCode()
134 * Fetch SIFTs file for the given PDBfile and construct an instance of
138 * @throws SiftsException
140 public SiftsClient(StructureFile structureFile) throws SiftsException
142 this.structureFile = structureFile;
143 this.pdbId = structureFile.getId();
144 File siftsFile = getSiftsFile(pdbId);
145 siftsEntry = parseSIFTs(siftsFile);
149 * Parse the given SIFTs File and return a JAXB POJO of parsed data
152 * - the GZipped SIFTs XML file to parse
155 * if a problem occurs while parsing the SIFTs XML
157 private Entry parseSIFTs(File siftFile) throws SiftsException
159 try (InputStream in = new FileInputStream(siftFile);
160 GZIPInputStream gzis = new GZIPInputStream(in);)
162 // System.out.println("File : " + siftFile.getAbsolutePath());
163 JAXBContext jc = JAXBContext.newInstance("jalview.xml.binding.sifts");
164 XMLStreamReader streamReader = XMLInputFactory.newInstance()
165 .createXMLStreamReader(gzis);
166 Unmarshaller um = jc.createUnmarshaller();
167 return (Entry) um.unmarshal(streamReader);
168 } catch (Exception e)
171 throw new SiftsException(e.getMessage());
176 * Get a SIFTs XML file for a given PDB Id from Cache or download from FTP
177 * repository if not found in cache
180 * @return SIFTs XML file
181 * @throws SiftsException
183 public static File getSiftsFile(String pdbId) throws SiftsException
185 String siftsFileName = SiftsSettings.getSiftDownloadDirectory()
186 + pdbId.toLowerCase() + ".xml.gz";
187 File siftsFile = new File(siftsFileName);
188 if (siftsFile.exists())
190 // The line below is required for unit testing... don't comment it out!!!
191 System.out.println(">>> SIFTS File already downloaded for " + pdbId);
193 if (isFileOlderThanThreshold(siftsFile,
194 SiftsSettings.getCacheThresholdInDays()))
196 File oldSiftsFile = new File(siftsFileName + "_old");
197 siftsFile.renameTo(oldSiftsFile);
200 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
201 oldSiftsFile.delete();
203 } catch (IOException e)
206 oldSiftsFile.renameTo(siftsFile);
207 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 // long now = System.currentTimeMillis();
280 URL url = new URL(siftsFileFTPURL);
281 URLConnection conn = url.openConnection();
282 InputStream inputStream = conn.getInputStream();
283 FileOutputStream outputStream = new FileOutputStream(
284 downloadedSiftsFile);
285 byte[] buffer = new byte[BUFFER_SIZE];
287 while ((bytesRead = inputStream.read(buffer)) != -1)
289 outputStream.write(buffer, 0, bytesRead);
291 outputStream.close();
293 // System.out.println(">>> File downloaded : " + downloadedSiftsFile
294 // + " took " + (System.currentTimeMillis() - now) + "ms");
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 List<DBRefEntry> dbRefs = seq.getPrimaryDBRefs();
329 if (dbRefs == null || dbRefs.size() < 1)
331 throw new SiftsException(
332 "Source DBRef could not be determined. DBRefs might not have been retrieved.");
335 for (DBRefEntry dbRef : dbRefs)
337 if (dbRef == null || dbRef.getAccessionId() == null
338 || dbRef.getSource() == null)
342 String canonicalSource = DBRefUtils.getCanonicalName(dbRef
344 if (isValidDBRefEntry(dbRef)
345 && (canonicalSource.equalsIgnoreCase(DBRefSource.UNIPROT) || canonicalSource
346 .equalsIgnoreCase(DBRefSource.PDB)))
351 throw new SiftsException("Could not get source DB Ref");
355 * Check that the DBRef Entry is properly populated and is available in this
356 * SiftClient instance
359 * - DBRefEntry to validate
360 * @return true validation is successful otherwise false is returned.
362 boolean isValidDBRefEntry(DBRefEntryI entry)
364 return entry != null && entry.getAccessionId() != null
365 && isFoundInSiftsEntry(entry.getAccessionId());
369 public HashSet<String> getAllMappingAccession()
371 HashSet<String> accessions = new HashSet<String>();
372 List<Entity> entities = siftsEntry.getEntity();
373 for (Entity entity : entities)
375 List<Segment> segments = entity.getSegment();
376 for (Segment segment : segments)
378 List<MapRegion> mapRegions = segment.getListMapRegion()
380 for (MapRegion mapRegion : mapRegions)
383 .add(mapRegion.getDb().getDbAccessionId().toLowerCase());
391 public StructureMapping getStructureMapping(SequenceI seq,
392 String pdbFile, String chain) throws Exception,
393 StructureMappingException
395 structId = (chain == null) ? pdbId : pdbId + "|" + chain;
396 System.out.println("Getting SIFTS mapping for " + structId + ": seq "
399 final StringBuilder mappingDetails = new StringBuilder(128);
400 PrintStream ps = new PrintStream(System.out)
403 public void print(String x)
405 mappingDetails.append(x);
409 public void println()
411 mappingDetails.append(NEWLINE);
414 HashMap<Integer, int[]> mapping = getGreedyMapping(chain, seq, ps);
416 String mappingOutput = mappingDetails.toString();
417 StructureMapping siftsMapping = new StructureMapping(seq, pdbFile,
418 pdbId, chain, mapping, mappingOutput);
423 public HashMap<Integer, int[]> getGreedyMapping(String entityId,
424 SequenceI seq, java.io.PrintStream os) throws SiftsException,
425 StructureMappingException
427 List<Integer> omitNonObserved = new ArrayList<Integer>();
428 int nonObservedShiftIndex = 0;
429 // System.out.println("Generating mappings for : " + entityId);
430 Entity entity = null;
431 entity = getEntityById(entityId);
432 String originalSeq = AlignSeq.extractGaps(
433 jalview.util.Comparison.GapChars, seq.getSequenceAsString());
434 HashMap<Integer, int[]> mapping = new HashMap<Integer, int[]>();
435 DBRefEntryI sourceDBRef;
436 sourceDBRef = getValidSourceDBRef(seq);
437 // TODO ensure sequence start/end is in the same coordinate system and
438 // consistent with the choosen sourceDBRef
440 // set sequence coordinate system - default value is UniProt
441 if (sourceDBRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
443 seqCoordSys = CoordinateSys.PDB;
446 HashSet<String> dbRefAccessionIdsString = new HashSet<String>();
447 for (DBRefEntry dbref : seq.getDBRefs())
449 dbRefAccessionIdsString.add(dbref.getAccessionId().toLowerCase());
451 dbRefAccessionIdsString.add(sourceDBRef.getAccessionId().toLowerCase());
453 curDBRefAccessionIdsString = dbRefAccessionIdsString;
454 curSourceDBRef = sourceDBRef.getAccessionId();
456 TreeMap<Integer, String> resNumMap = new TreeMap<Integer, String>();
457 List<Segment> segments = entity.getSegment();
458 SegmentHelperPojo shp = new SegmentHelperPojo(seq, mapping, resNumMap,
459 omitNonObserved, nonObservedShiftIndex);
460 processSegments(segments, shp);
463 populateAtomPositions(entityId, mapping);
464 } catch (Exception e)
468 if (seqCoordSys == CoordinateSys.UNIPROT)
470 padWithGaps(resNumMap, omitNonObserved);
472 int seqStart = UNASSIGNED;
473 int seqEnd = UNASSIGNED;
474 int pdbStart = UNASSIGNED;
475 int pdbEnd = UNASSIGNED;
477 if (mapping.isEmpty())
479 throw new SiftsException("SIFTS mapping failed");
482 Integer[] keys = mapping.keySet().toArray(new Integer[0]);
485 seqEnd = keys[keys.length - 1];
487 String matchedSeq = originalSeq;
488 if (seqStart != UNASSIGNED)
490 pdbStart = mapping.get(seqStart)[PDB_RES_POS];
491 pdbEnd = mapping.get(seqEnd)[PDB_RES_POS];
492 int orignalSeqStart = seq.getStart();
493 if (orignalSeqStart >= 1)
495 int subSeqStart = (seqStart >= orignalSeqStart) ? seqStart
496 - orignalSeqStart : 0;
497 int subSeqEnd = seqEnd - (orignalSeqStart - 1);
498 subSeqEnd = originalSeq.length() < subSeqEnd ? originalSeq.length()
500 matchedSeq = originalSeq.substring(subSeqStart, subSeqEnd);
504 matchedSeq = originalSeq.substring(1, originalSeq.length());
508 StringBuilder targetStrucSeqs = new StringBuilder();
509 for (String res : resNumMap.values())
511 targetStrucSeqs.append(res);
516 MappingOutputModel mop = new MappingOutputModel();
517 mop.setSeqStart(seqStart);
518 mop.setSeqEnd(seqEnd);
519 mop.setSeqName(seq.getName());
520 mop.setSeqResidue(matchedSeq);
522 mop.setStrStart(pdbStart);
523 mop.setStrEnd(pdbEnd);
524 mop.setStrName(structId);
525 mop.setStrResidue(targetStrucSeqs.toString());
528 os.print(getMappingOutput(mop).toString());
534 void processSegments(List<Segment> segments, SegmentHelperPojo shp)
536 SequenceI seq = shp.getSeq();
537 HashMap<Integer, int[]> mapping = shp.getMapping();
538 TreeMap<Integer, String> resNumMap = shp.getResNumMap();
539 List<Integer> omitNonObserved = shp.getOmitNonObserved();
540 int nonObservedShiftIndex = shp.getNonObservedShiftIndex();
541 for (Segment segment : segments)
543 // System.out.println("Mapping segments : " + segment.getSegId() + "\\"s
545 List<Residue> residues = segment.getListResidue().getResidue();
546 for (Residue residue : residues)
548 int currSeqIndex = UNASSIGNED;
549 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
550 CrossRefDb pdbRefDb = null;
551 for (CrossRefDb cRefDb : cRefDbs)
553 if (cRefDb.getDbSource().equalsIgnoreCase(DBRefSource.PDB))
557 if (cRefDb.getDbCoordSys()
558 .equalsIgnoreCase(seqCoordSys.getName())
559 && isAccessionMatched(cRefDb.getDbAccessionId()))
561 String resNumIndexString = cRefDb.getDbResNum()
562 .equalsIgnoreCase("None") ? String.valueOf(UNASSIGNED)
563 : cRefDb.getDbResNum();
566 currSeqIndex = Integer.valueOf(resNumIndexString);
567 } catch (NumberFormatException nfe)
569 currSeqIndex = Integer.valueOf(resNumIndexString
570 .split("[a-zA-Z]")[0]);
573 if (pdbRefDb != null)
575 break;// exit loop if pdb and uniprot are already found
579 if (currSeqIndex == UNASSIGNED)
583 if (currSeqIndex >= seq.getStart() && currSeqIndex <= seq.getEnd())
588 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
589 .getDbResNum()) : Integer.valueOf(pdbRefDb
591 } catch (NumberFormatException nfe)
593 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
594 .getDbResNum()) : Integer.valueOf(pdbRefDb
595 .getDbResNum().split("[a-zA-Z]")[0]);
599 if (isResidueObserved(residue)
600 || seqCoordSys == CoordinateSys.UNIPROT)
602 char resCharCode = ResidueProperties
603 .getSingleCharacterCode(ResidueProperties
604 .getCanonicalAminoAcid(residue.getDbResName()));
605 resNumMap.put(currSeqIndex, String.valueOf(resCharCode));
609 omitNonObserved.add(currSeqIndex);
610 ++nonObservedShiftIndex;
612 mapping.put(currSeqIndex - nonObservedShiftIndex, new int[] {
613 Integer.valueOf(resNum), UNASSIGNED });
621 * Checks if the residue instance is marked 'Not_observed' or not
626 private boolean isResidueObserved(Residue residue)
628 Set<String> annotations = getResidueAnnotaitons(residue,
629 ResidueDetailType.ANNOTATION);
630 if (annotations == null || annotations.isEmpty())
634 for (String annotation : annotations)
636 if (annotation.equalsIgnoreCase(NOT_OBSERVED))
645 * Get annotation String for a given residue and annotation type
651 private Set<String> getResidueAnnotaitons(Residue residue,
652 ResidueDetailType type)
654 HashSet<String> foundAnnotations = new HashSet<String>();
655 List<ResidueDetail> resDetails = residue.getResidueDetail();
656 for (ResidueDetail resDetail : resDetails)
658 if (resDetail.getProperty().equalsIgnoreCase(type.getCode()))
660 foundAnnotations.add(resDetail.getContent());
663 return foundAnnotations;
667 public boolean isAccessionMatched(String accession)
669 boolean isStrictMatch = true;
670 return isStrictMatch ? curSourceDBRef.equalsIgnoreCase(accession)
671 : curDBRefAccessionIdsString.contains(accession.toLowerCase());
674 private boolean isFoundInSiftsEntry(String accessionId)
676 Set<String> siftsDBRefs = getAllMappingAccession();
677 return accessionId != null
678 && siftsDBRefs.contains(accessionId.toLowerCase());
682 * Pad omitted residue positions in PDB sequence with gaps
686 void padWithGaps(Map<Integer, String> resNumMap,
687 List<Integer> omitNonObserved)
689 if (resNumMap == null || resNumMap.isEmpty())
693 Integer[] keys = resNumMap.keySet().toArray(new Integer[0]);
694 // Arrays.sort(keys);
695 int firstIndex = keys[0];
696 int lastIndex = keys[keys.length - 1];
697 // System.out.println("Min value " + firstIndex);
698 // System.out.println("Max value " + lastIndex);
699 for (int x = firstIndex; x <= lastIndex; x++)
701 if (!resNumMap.containsKey(x) && !omitNonObserved.contains(x))
703 resNumMap.put(x, "-");
709 public Entity getEntityById(String id) throws SiftsException
711 // Determines an entity to process by performing a heuristic matching of all
712 // Entities with the given chainId and choosing the best matching Entity
713 Entity entity = getEntityByMostOptimalMatchedId(id);
718 throw new SiftsException("Entity " + id + " not found");
722 * This method was added because EntityId is NOT always equal to ChainId.
723 * Hence, it provides the logic to greedily detect the "true" Entity for a
724 * given chainId where discrepancies exist.
729 public Entity getEntityByMostOptimalMatchedId(String chainId)
731 // System.out.println("---> advanced greedy entityId matching block entered..");
732 List<Entity> entities = siftsEntry.getEntity();
733 SiftsEntitySortPojo[] sPojo = new SiftsEntitySortPojo[entities.size()];
735 for (Entity entity : entities)
737 sPojo[count] = new SiftsEntitySortPojo();
738 sPojo[count].entityId = entity.getEntityId();
740 List<Segment> segments = entity.getSegment();
741 for (Segment segment : segments)
743 List<Residue> residues = segment.getListResidue().getResidue();
744 for (Residue residue : residues)
746 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
747 for (CrossRefDb cRefDb : cRefDbs)
749 if (!cRefDb.getDbSource().equalsIgnoreCase("PDB"))
753 ++sPojo[count].resCount;
754 if (cRefDb.getDbChainId().equalsIgnoreCase(chainId))
756 ++sPojo[count].chainIdFreq;
761 sPojo[count].pid = (100 * sPojo[count].chainIdFreq)
762 / sPojo[count].resCount;
765 Arrays.sort(sPojo, Collections.reverseOrder());
766 // System.out.println("highest matched entity : " + sPojo[0].entityId);
767 // System.out.println("highest matched pid : " + sPojo[0].pid);
769 if (sPojo[0].entityId != null)
771 if (sPojo[0].pid < 1)
775 for (Entity entity : entities)
777 if (!entity.getEntityId().equalsIgnoreCase(sPojo[0].entityId))
787 private class SiftsEntitySortPojo implements
788 Comparable<SiftsEntitySortPojo>
790 public String entityId;
792 public int chainIdFreq;
799 public int compareTo(SiftsEntitySortPojo o)
801 return this.pid - o.pid;
805 private class SegmentHelperPojo
807 private SequenceI seq;
809 private HashMap<Integer, int[]> mapping;
811 private TreeMap<Integer, String> resNumMap;
813 private List<Integer> omitNonObserved;
815 private int nonObservedShiftIndex;
817 public SegmentHelperPojo(SequenceI seq,
818 HashMap<Integer, int[]> mapping,
819 TreeMap<Integer, String> resNumMap,
820 List<Integer> omitNonObserved, int nonObservedShiftIndex)
824 setResNumMap(resNumMap);
825 setOmitNonObserved(omitNonObserved);
826 setNonObservedShiftIndex(nonObservedShiftIndex);
829 public SequenceI getSeq()
834 public void setSeq(SequenceI seq)
839 public HashMap<Integer, int[]> getMapping()
844 public void setMapping(HashMap<Integer, int[]> mapping)
846 this.mapping = mapping;
849 public TreeMap<Integer, String> getResNumMap()
854 public void setResNumMap(TreeMap<Integer, String> resNumMap)
856 this.resNumMap = resNumMap;
859 public List<Integer> getOmitNonObserved()
861 return omitNonObserved;
864 public void setOmitNonObserved(List<Integer> omitNonObserved)
866 this.omitNonObserved = omitNonObserved;
869 public int getNonObservedShiftIndex()
871 return nonObservedShiftIndex;
874 public void setNonObservedShiftIndex(int nonObservedShiftIndex)
876 this.nonObservedShiftIndex = nonObservedShiftIndex;
881 public StringBuffer getMappingOutput(MappingOutputModel mp)
882 throws StructureMappingException
884 String seqRes = mp.getSeqResidue();
885 String seqName = mp.getSeqName();
886 int sStart = mp.getSeqStart();
887 int sEnd = mp.getSeqEnd();
889 String strRes = mp.getStrResidue();
890 String strName = mp.getStrName();
891 int pdbStart = mp.getStrStart();
892 int pdbEnd = mp.getStrEnd();
894 String type = mp.getType();
896 int maxid = (seqName.length() >= strName.length()) ? seqName.length()
898 int len = 72 - maxid - 1;
900 int nochunks = ((seqRes.length()) / len)
901 + ((seqRes.length()) % len > 0 ? 1 : 0);
903 StringBuffer output = new StringBuffer();
904 output.append(NEWLINE);
905 output.append("Sequence \u27f7 Structure mapping details").append(
907 output.append("Method: SIFTS");
908 output.append(NEWLINE).append(NEWLINE);
910 output.append(new Format("%" + maxid + "s").form(seqName));
911 output.append(" : ");
912 output.append(String.valueOf(sStart));
913 output.append(" - ");
914 output.append(String.valueOf(sEnd));
915 output.append(" Maps to ");
916 output.append(NEWLINE);
917 output.append(new Format("%" + maxid + "s").form(structId));
918 output.append(" : ");
919 output.append(String.valueOf(pdbStart));
920 output.append(" - ");
921 output.append(String.valueOf(pdbEnd));
922 output.append(NEWLINE).append(NEWLINE);
924 int matchedSeqCount = 0;
925 for (int j = 0; j < nochunks; j++)
927 // Print the first aligned sequence
928 output.append(new Format("%" + (maxid) + "s").form(seqName)).append(
931 for (int i = 0; i < len; i++)
933 if ((i + (j * len)) < seqRes.length())
935 output.append(seqRes.charAt(i + (j * len)));
939 output.append(NEWLINE);
940 output.append(new Format("%" + (maxid) + "s").form(" ")).append(" ");
942 // Print out the matching chars
943 for (int i = 0; i < len; i++)
947 if ((i + (j * len)) < seqRes.length())
949 boolean sameChar = Comparison.isSameResidue(
950 seqRes.charAt(i + (j * len)),
951 strRes.charAt(i + (j * len)), false);
953 && !jalview.util.Comparison.isGap(seqRes.charAt(i
959 else if (type.equals("pep"))
961 if (ResidueProperties.getPAM250(seqRes.charAt(i + (j * len)),
962 strRes.charAt(i + (j * len))) > 0)
976 } catch (IndexOutOfBoundsException e)
981 // Now print the second aligned sequence
982 output = output.append(NEWLINE);
983 output = output.append(new Format("%" + (maxid) + "s").form(strName))
985 for (int i = 0; i < len; i++)
987 if ((i + (j * len)) < strRes.length())
989 output.append(strRes.charAt(i + (j * len)));
992 output.append(NEWLINE).append(NEWLINE);
994 float pid = (float) matchedSeqCount / seqRes.length() * 100;
995 if (pid < SiftsSettings.getFailSafePIDThreshold())
997 throw new StructureMappingException(
998 ">>> 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();