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.Comparison;
33 import jalview.util.DBRefUtils;
34 import jalview.util.Format;
35 import jalview.xml.binding.sifts.Entry;
36 import jalview.xml.binding.sifts.Entry.Entity;
37 import jalview.xml.binding.sifts.Entry.Entity.Segment;
38 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListMapRegion.MapRegion;
39 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue;
40 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.CrossRefDb;
41 import jalview.xml.binding.sifts.Entry.Entity.Segment.ListResidue.Residue.ResidueDetail;
44 import java.io.FileInputStream;
45 import java.io.FileOutputStream;
46 import java.io.IOException;
47 import java.io.InputStream;
48 import java.io.PrintStream;
50 import java.net.URLConnection;
51 import java.nio.file.Files;
52 import java.nio.file.Path;
53 import java.nio.file.attribute.BasicFileAttributes;
54 import java.util.ArrayList;
55 import java.util.Arrays;
56 import java.util.Collection;
57 import java.util.Collections;
58 import java.util.Date;
59 import java.util.HashMap;
60 import java.util.HashSet;
61 import java.util.List;
64 import java.util.TreeMap;
65 import java.util.zip.GZIPInputStream;
67 import javax.xml.bind.JAXBContext;
68 import javax.xml.bind.Unmarshaller;
69 import javax.xml.stream.XMLInputFactory;
70 import javax.xml.stream.XMLStreamReader;
73 import MCview.PDBChain;
75 public class SiftsClient implements SiftsClientI
78 * for use in mocking out file fetch for tests only
79 * - reset to null after testing!
81 private static File mockSiftsFile;
83 private Entry siftsEntry;
85 private StructureFile pdb;
89 private String structId;
91 private CoordinateSys seqCoordSys = CoordinateSys.UNIPROT;
93 private static final int BUFFER_SIZE = 4096;
95 public static final int UNASSIGNED = -1;
97 private static final int PDB_RES_POS = 0;
99 private static final int PDB_ATOM_POS = 1;
101 private static final String NOT_OBSERVED = "Not_Observed";
103 private static final String SIFTS_FTP_BASE_URL = "http://ftp.ebi.ac.uk/pub/databases/msd/sifts/xml/";
105 private final static String NEWLINE = System.lineSeparator();
107 private String curSourceDBRef;
109 private HashSet<String> curDBRefAccessionIdsString;
111 private enum CoordinateSys
113 UNIPROT("UniProt"), PDB("PDBresnum"), PDBe("PDBe");
116 private CoordinateSys(String name)
121 public String getName()
127 private enum ResidueDetailType
129 NAME_SEC_STRUCTURE("nameSecondaryStructure"), CODE_SEC_STRUCTURE(
130 "codeSecondaryStructure"), ANNOTATION("Annotation");
133 private ResidueDetailType(String code)
138 public String getCode()
145 * Fetch SIFTs file for the given PDBfile and construct an instance of
149 * @throws SiftsException
151 public SiftsClient(StructureFile pdb) throws SiftsException
154 this.pdbId = pdb.getId();
155 File siftsFile = getSiftsFile(pdbId);
156 siftsEntry = parseSIFTs(siftsFile);
160 * Parse the given SIFTs File and return a JAXB POJO of parsed data
163 * - the GZipped SIFTs XML file to parse
166 * if a problem occurs while parsing the SIFTs XML
168 private Entry parseSIFTs(File siftFile) throws SiftsException
170 try (InputStream in = new FileInputStream(siftFile);
171 GZIPInputStream gzis = new GZIPInputStream(in);)
173 // System.out.println("File : " + siftFile.getAbsolutePath());
174 JAXBContext jc = JAXBContext.newInstance("jalview.xml.binding.sifts");
175 XMLStreamReader streamReader = XMLInputFactory.newInstance()
176 .createXMLStreamReader(gzis);
177 Unmarshaller um = jc.createUnmarshaller();
178 return (Entry) um.unmarshal(streamReader);
179 } catch (Exception e)
182 throw new SiftsException(e.getMessage());
187 * Get a SIFTs XML file for a given PDB Id from Cache or download from FTP
188 * repository if not found in cache
191 * @return SIFTs XML file
192 * @throws SiftsException
194 public static File getSiftsFile(String pdbId) throws SiftsException
197 * return mocked file if it has been set
199 if (mockSiftsFile != null)
201 return mockSiftsFile;
204 String siftsFileName = SiftsSettings.getSiftDownloadDirectory()
205 + pdbId.toLowerCase() + ".xml.gz";
206 File siftsFile = new File(siftsFileName);
207 if (siftsFile.exists())
209 // The line below is required for unit testing... don't comment it out!!!
210 System.out.println(">>> SIFTS File already downloaded for " + pdbId);
212 if (isFileOlderThanThreshold(siftsFile,
213 SiftsSettings.getCacheThresholdInDays()))
215 File oldSiftsFile = new File(siftsFileName + "_old");
216 siftsFile.renameTo(oldSiftsFile);
219 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
220 oldSiftsFile.delete();
222 } catch (IOException e)
225 oldSiftsFile.renameTo(siftsFile);
226 return new File(siftsFileName);
236 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
237 } catch (IOException e)
239 throw new SiftsException(e.getMessage());
245 * This method enables checking if a cached file has exceeded a certain
251 * the threshold in days
254 public static boolean isFileOlderThanThreshold(File file, int noOfDays)
256 Path filePath = file.toPath();
257 BasicFileAttributes attr;
261 attr = Files.readAttributes(filePath, BasicFileAttributes.class);
262 diffInDays = (int) ((new Date().getTime() - attr.lastModifiedTime()
263 .toMillis()) / (1000 * 60 * 60 * 24));
264 // System.out.println("Diff in days : " + diffInDays);
265 } catch (IOException e)
269 return noOfDays <= diffInDays;
273 * Download a SIFTs XML file for a given PDB Id from an FTP repository
276 * @return downloaded SIFTs XML file
277 * @throws SiftsException
278 * @throws IOException
280 public static File downloadSiftsFile(String pdbId) throws SiftsException,
283 if (pdbId.contains(".cif"))
285 pdbId = pdbId.replace(".cif", "");
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();
297 // System.out.println(">> Download ftp url : " + siftsFileFTPURL);
298 // long now = System.currentTimeMillis();
299 URL url = new URL(siftsFileFTPURL);
300 URLConnection conn = url.openConnection();
301 InputStream inputStream = conn.getInputStream();
302 FileOutputStream outputStream = new FileOutputStream(
303 downloadedSiftsFile);
304 byte[] buffer = new byte[BUFFER_SIZE];
306 while ((bytesRead = inputStream.read(buffer)) != -1)
308 outputStream.write(buffer, 0, bytesRead);
310 outputStream.close();
312 // System.out.println(">>> File downloaded : " + downloadedSiftsFile
313 // + " took " + (System.currentTimeMillis() - now) + "ms");
314 return new File(downloadedSiftsFile);
318 * Delete the SIFTs file for the given PDB Id in the local SIFTs download
322 * @return true if the file was deleted or doesn't exist
324 public static boolean deleteSiftsFileByPDBId(String pdbId)
326 File siftsFile = new File(SiftsSettings.getSiftDownloadDirectory()
327 + pdbId.toLowerCase() + ".xml.gz");
328 if (siftsFile.exists())
330 return siftsFile.delete();
336 * Get a valid SIFTs DBRef for the given sequence current SIFTs entry
339 * - the target sequence for the operation
340 * @return a valid DBRefEntry that is SIFTs compatible
342 * if no valid source DBRefEntry was found for the given sequences
344 public DBRefEntryI getValidSourceDBRef(SequenceI seq)
345 throws SiftsException
347 List<DBRefEntry> dbRefs = seq.getPrimaryDBRefs();
348 if (dbRefs == null || dbRefs.size() < 1)
350 throw new SiftsException(
351 "Source DBRef could not be determined. DBRefs might not have been retrieved.");
354 for (DBRefEntry dbRef : dbRefs)
356 if (dbRef == null || dbRef.getAccessionId() == null
357 || dbRef.getSource() == null)
361 String canonicalSource = DBRefUtils.getCanonicalName(dbRef
363 if (isValidDBRefEntry(dbRef)
364 && (canonicalSource.equalsIgnoreCase(DBRefSource.UNIPROT) || canonicalSource
365 .equalsIgnoreCase(DBRefSource.PDB)))
370 throw new SiftsException("Could not get source DB Ref");
374 * Check that the DBRef Entry is properly populated and is available in this
375 * SiftClient instance
378 * - DBRefEntry to validate
379 * @return true validation is successful otherwise false is returned.
381 boolean isValidDBRefEntry(DBRefEntryI entry)
383 return entry != null && entry.getAccessionId() != null
384 && isFoundInSiftsEntry(entry.getAccessionId());
388 public HashSet<String> getAllMappingAccession()
390 HashSet<String> accessions = new HashSet<String>();
391 List<Entity> entities = siftsEntry.getEntity();
392 for (Entity entity : entities)
394 List<Segment> segments = entity.getSegment();
395 for (Segment segment : segments)
397 List<MapRegion> mapRegions = segment.getListMapRegion()
399 for (MapRegion mapRegion : mapRegions)
402 .add(mapRegion.getDb().getDbAccessionId().toLowerCase());
410 public StructureMapping getSiftsStructureMapping(SequenceI seq,
411 String pdbFile, String chain) throws SiftsException
413 structId = (chain == null) ? pdbId : pdbId + "|" + chain;
414 System.out.println("Getting SIFTS mapping for " + structId + ": seq "
417 final StringBuilder mappingDetails = new StringBuilder(128);
418 PrintStream ps = new PrintStream(System.out)
421 public void print(String x)
423 mappingDetails.append(x);
427 public void println()
429 mappingDetails.append(NEWLINE);
432 HashMap<Integer, int[]> mapping = getGreedyMapping(chain, seq, ps);
434 String mappingOutput = mappingDetails.toString();
435 StructureMapping siftsMapping = new StructureMapping(seq, pdbFile,
436 pdbId, chain, mapping, mappingOutput);
441 public HashMap<Integer, int[]> getGreedyMapping(String entityId,
442 SequenceI seq, java.io.PrintStream os) throws SiftsException
444 List<Integer> omitNonObserved = new ArrayList<Integer>();
445 int nonObservedShiftIndex = 0;
446 // System.out.println("Generating mappings for : " + entityId);
447 Entity entity = null;
448 entity = getEntityById(entityId);
449 String originalSeq = AlignSeq.extractGaps(
450 jalview.util.Comparison.GapChars, seq.getSequenceAsString());
451 HashMap<Integer, int[]> mapping = new HashMap<Integer, int[]>();
452 DBRefEntryI sourceDBRef;
453 sourceDBRef = getValidSourceDBRef(seq);
454 // TODO ensure sequence start/end is in the same coordinate system and
455 // consistent with the choosen sourceDBRef
457 // set sequence coordinate system - default value is UniProt
458 if (sourceDBRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
460 seqCoordSys = CoordinateSys.PDB;
463 HashSet<String> dbRefAccessionIdsString = new HashSet<String>();
464 for (DBRefEntry dbref : seq.getDBRefs())
466 dbRefAccessionIdsString.add(dbref.getAccessionId().toLowerCase());
468 dbRefAccessionIdsString.add(sourceDBRef.getAccessionId().toLowerCase());
470 curDBRefAccessionIdsString = dbRefAccessionIdsString;
471 curSourceDBRef = sourceDBRef.getAccessionId();
473 TreeMap<Integer, String> resNumMap = new TreeMap<Integer, String>();
474 List<Segment> segments = entity.getSegment();
475 SegmentHelperPojo shp = new SegmentHelperPojo(seq, mapping, resNumMap,
476 omitNonObserved, nonObservedShiftIndex);
477 processSegments(segments, shp);
480 populateAtomPositions(entityId, mapping);
481 } catch (Exception e)
485 if (seqCoordSys == CoordinateSys.UNIPROT)
487 padWithGaps(resNumMap, omitNonObserved);
489 int seqStart = UNASSIGNED;
490 int seqEnd = UNASSIGNED;
491 int pdbStart = UNASSIGNED;
492 int pdbEnd = UNASSIGNED;
494 if (mapping.isEmpty())
496 throw new SiftsException("SIFTS mapping failed");
499 Integer[] keys = mapping.keySet().toArray(new Integer[0]);
502 seqEnd = keys[keys.length - 1];
504 String matchedSeq = originalSeq;
505 if (seqStart != UNASSIGNED)
507 pdbStart = mapping.get(seqStart)[PDB_RES_POS];
508 pdbEnd = mapping.get(seqEnd)[PDB_RES_POS];
509 int orignalSeqStart = seq.getStart();
510 if (orignalSeqStart >= 1)
512 int subSeqStart = (seqStart >= orignalSeqStart) ? seqStart
513 - orignalSeqStart : 0;
514 int subSeqEnd = seqEnd - (orignalSeqStart - 1);
515 subSeqEnd = originalSeq.length() < subSeqEnd ? originalSeq.length()
517 matchedSeq = originalSeq.substring(subSeqStart, subSeqEnd);
521 matchedSeq = originalSeq.substring(1, originalSeq.length());
525 StringBuilder targetStrucSeqs = new StringBuilder();
526 for (String res : resNumMap.values())
528 targetStrucSeqs.append(res);
533 MappingOutputPojo mop = new MappingOutputPojo();
534 mop.setSeqStart(seqStart);
535 mop.setSeqEnd(seqEnd);
536 mop.setSeqName(seq.getName());
537 mop.setSeqResidue(matchedSeq);
539 mop.setStrStart(pdbStart);
540 mop.setStrEnd(pdbEnd);
541 mop.setStrName(structId);
542 mop.setStrResidue(targetStrucSeqs.toString());
545 os.print(getMappingOutput(mop).toString());
551 void processSegments(List<Segment> segments, SegmentHelperPojo shp)
553 SequenceI seq = shp.getSeq();
554 HashMap<Integer, int[]> mapping = shp.getMapping();
555 TreeMap<Integer, String> resNumMap = shp.getResNumMap();
556 List<Integer> omitNonObserved = shp.getOmitNonObserved();
557 int nonObservedShiftIndex = shp.getNonObservedShiftIndex();
558 for (Segment segment : segments)
560 // System.out.println("Mapping segments : " + segment.getSegId() + "\\"s
562 List<Residue> residues = segment.getListResidue().getResidue();
563 for (Residue residue : residues)
565 int currSeqIndex = UNASSIGNED;
566 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
567 CrossRefDb pdbRefDb = null;
568 for (CrossRefDb cRefDb : cRefDbs)
570 if (cRefDb.getDbSource().equalsIgnoreCase(DBRefSource.PDB))
574 if (cRefDb.getDbCoordSys()
575 .equalsIgnoreCase(seqCoordSys.getName())
576 && isAccessionMatched(cRefDb.getDbAccessionId()))
578 String resNumIndexString = cRefDb.getDbResNum()
579 .equalsIgnoreCase("None") ? String.valueOf(UNASSIGNED)
580 : cRefDb.getDbResNum();
583 currSeqIndex = Integer.valueOf(resNumIndexString);
584 } catch (NumberFormatException nfe)
586 currSeqIndex = Integer.valueOf(resNumIndexString
587 .split("[a-zA-Z]")[0]);
590 if (pdbRefDb != null)
592 break;// exit loop if pdb and uniprot are already found
596 if (currSeqIndex == UNASSIGNED)
600 if (currSeqIndex >= seq.getStart() && currSeqIndex <= seq.getEnd())
605 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
606 .getDbResNum()) : Integer.valueOf(pdbRefDb
608 } catch (NumberFormatException nfe)
610 if (pdbRefDb == null || pdbRefDb.getDbResNum().equals("null"))
615 resNum = Integer.valueOf(pdbRefDb
616 .getDbResNum().split("[a-zA-Z]")[0]);
620 if (isResidueObserved(residue)
621 || seqCoordSys == CoordinateSys.UNIPROT)
623 char resCharCode = ResidueProperties
624 .getSingleCharacterCode(ResidueProperties
625 .getCanonicalAminoAcid(residue.getDbResName()));
626 resNumMap.put(currSeqIndex, String.valueOf(resCharCode));
630 omitNonObserved.add(currSeqIndex);
631 ++nonObservedShiftIndex;
633 mapping.put(currSeqIndex - nonObservedShiftIndex, new int[] {
634 Integer.valueOf(resNum), UNASSIGNED });
643 * Target chain to populate mapping of its atom positions.
645 * Two dimension array of residue index versus atom position
646 * @throws IllegalArgumentException
647 * Thrown if chainId or mapping is null
648 * @throws SiftsException
650 void populateAtomPositions(String chainId, Map<Integer, int[]> mapping)
651 throws IllegalArgumentException, SiftsException
655 PDBChain chain = pdb.findChain(chainId);
657 if (chain == null || mapping == null)
659 throw new IllegalArgumentException(
660 "Chain id or mapping must not be null.");
662 for (int[] map : mapping.values())
664 if (map[PDB_RES_POS] != UNASSIGNED)
666 map[PDB_ATOM_POS] = getAtomIndex(map[PDB_RES_POS], chain.atoms);
669 } catch (NullPointerException e)
671 throw new SiftsException(e.getMessage());
672 } catch (Exception e)
674 throw new SiftsException(e.getMessage());
680 * @param residueIndex
681 * The residue index used for the search
683 * A collection of Atom to search
684 * @return atom position for the given residue index
686 int getAtomIndex(int residueIndex, Collection<Atom> atoms)
690 throw new IllegalArgumentException(
691 "atoms collection must not be null!");
693 for (Atom atom : atoms)
695 if (atom.resNumber == residueIndex)
697 return atom.atomIndex;
704 * Checks if the residue instance is marked 'Not_observed' or not
709 private boolean isResidueObserved(Residue residue)
711 Set<String> annotations = getResidueAnnotaitons(residue,
712 ResidueDetailType.ANNOTATION);
713 if (annotations == null || annotations.isEmpty())
717 for (String annotation : annotations)
719 if (annotation.equalsIgnoreCase(NOT_OBSERVED))
728 * Get annotation String for a given residue and annotation type
734 private Set<String> getResidueAnnotaitons(Residue residue,
735 ResidueDetailType type)
737 HashSet<String> foundAnnotations = new HashSet<String>();
738 List<ResidueDetail> resDetails = residue.getResidueDetail();
739 for (ResidueDetail resDetail : resDetails)
741 if (resDetail.getProperty().equalsIgnoreCase(type.getCode()))
743 foundAnnotations.add(resDetail.getContent());
746 return foundAnnotations;
750 public boolean isAccessionMatched(String accession)
752 boolean isStrictMatch = true;
753 return isStrictMatch ? curSourceDBRef.equalsIgnoreCase(accession)
754 : curDBRefAccessionIdsString.contains(accession.toLowerCase());
757 private boolean isFoundInSiftsEntry(String accessionId)
759 Set<String> siftsDBRefs = getAllMappingAccession();
760 return accessionId != null
761 && siftsDBRefs.contains(accessionId.toLowerCase());
765 * Pad omitted residue positions in PDB sequence with gaps
769 void padWithGaps(Map<Integer, String> resNumMap,
770 List<Integer> omitNonObserved)
772 if (resNumMap == null || resNumMap.isEmpty())
776 Integer[] keys = resNumMap.keySet().toArray(new Integer[0]);
777 // Arrays.sort(keys);
778 int firstIndex = keys[0];
779 int lastIndex = keys[keys.length - 1];
780 // System.out.println("Min value " + firstIndex);
781 // System.out.println("Max value " + lastIndex);
782 for (int x = firstIndex; x <= lastIndex; x++)
784 if (!resNumMap.containsKey(x) && !omitNonObserved.contains(x))
786 resNumMap.put(x, "-");
792 public Entity getEntityById(String id) throws SiftsException
794 // Determines an entity to process by performing a heuristic matching of all
795 // Entities with the given chainId and choosing the best matching Entity
796 Entity entity = getEntityByMostOptimalMatchedId(id);
801 throw new SiftsException("Entity " + id + " not found");
805 * This method was added because EntityId is NOT always equal to ChainId.
806 * Hence, it provides the logic to greedily detect the "true" Entity for a
807 * given chainId where discrepancies exist.
812 public Entity getEntityByMostOptimalMatchedId(String chainId)
814 // System.out.println("---> advanced greedy entityId matching block entered..");
815 List<Entity> entities = siftsEntry.getEntity();
816 SiftsEntitySortPojo[] sPojo = new SiftsEntitySortPojo[entities.size()];
818 for (Entity entity : entities)
820 sPojo[count] = new SiftsEntitySortPojo();
821 sPojo[count].entityId = entity.getEntityId();
823 List<Segment> segments = entity.getSegment();
824 for (Segment segment : segments)
826 List<Residue> residues = segment.getListResidue().getResidue();
827 for (Residue residue : residues)
829 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
830 for (CrossRefDb cRefDb : cRefDbs)
832 if (!cRefDb.getDbSource().equalsIgnoreCase("PDB"))
836 ++sPojo[count].resCount;
837 if (cRefDb.getDbChainId().equalsIgnoreCase(chainId))
839 ++sPojo[count].chainIdFreq;
844 sPojo[count].pid = (100 * sPojo[count].chainIdFreq)
845 / sPojo[count].resCount;
848 Arrays.sort(sPojo, Collections.reverseOrder());
849 // System.out.println("highest matched entity : " + sPojo[0].entityId);
850 // System.out.println("highest matched pid : " + sPojo[0].pid);
852 if (sPojo[0].entityId != null)
854 if (sPojo[0].pid < 1)
858 for (Entity entity : entities)
860 if (!entity.getEntityId().equalsIgnoreCase(sPojo[0].entityId))
870 private class SiftsEntitySortPojo implements
871 Comparable<SiftsEntitySortPojo>
873 public String entityId;
875 public int chainIdFreq;
882 public int compareTo(SiftsEntitySortPojo o)
884 return this.pid - o.pid;
888 private class SegmentHelperPojo
890 private SequenceI seq;
892 private HashMap<Integer, int[]> mapping;
894 private TreeMap<Integer, String> resNumMap;
896 private List<Integer> omitNonObserved;
898 private int nonObservedShiftIndex;
900 public SegmentHelperPojo(SequenceI seq,
901 HashMap<Integer, int[]> mapping,
902 TreeMap<Integer, String> resNumMap,
903 List<Integer> omitNonObserved, int nonObservedShiftIndex)
907 setResNumMap(resNumMap);
908 setOmitNonObserved(omitNonObserved);
909 setNonObservedShiftIndex(nonObservedShiftIndex);
912 public SequenceI getSeq()
917 public void setSeq(SequenceI seq)
922 public HashMap<Integer, int[]> getMapping()
927 public void setMapping(HashMap<Integer, int[]> mapping)
929 this.mapping = mapping;
932 public TreeMap<Integer, String> getResNumMap()
937 public void setResNumMap(TreeMap<Integer, String> resNumMap)
939 this.resNumMap = resNumMap;
942 public List<Integer> getOmitNonObserved()
944 return omitNonObserved;
947 public void setOmitNonObserved(List<Integer> omitNonObserved)
949 this.omitNonObserved = omitNonObserved;
952 public int getNonObservedShiftIndex()
954 return nonObservedShiftIndex;
957 public void setNonObservedShiftIndex(int nonObservedShiftIndex)
959 this.nonObservedShiftIndex = nonObservedShiftIndex;
964 public StringBuffer getMappingOutput(MappingOutputPojo mp)
965 throws SiftsException
967 String seqRes = mp.getSeqResidue();
968 String seqName = mp.getSeqName();
969 int sStart = mp.getSeqStart();
970 int sEnd = mp.getSeqEnd();
972 String strRes = mp.getStrResidue();
973 String strName = mp.getStrName();
974 int pdbStart = mp.getStrStart();
975 int pdbEnd = mp.getStrEnd();
977 String type = mp.getType();
979 int maxid = (seqName.length() >= strName.length()) ? seqName.length()
981 int len = 72 - maxid - 1;
983 int nochunks = ((seqRes.length()) / len)
984 + ((seqRes.length()) % len > 0 ? 1 : 0);
986 StringBuffer output = new StringBuffer();
987 output.append(NEWLINE);
988 output.append("Sequence \u27f7 Structure mapping details").append(
990 output.append("Method: SIFTS");
991 output.append(NEWLINE).append(NEWLINE);
993 output.append(new Format("%" + maxid + "s").form(seqName));
994 output.append(" : ");
995 output.append(String.valueOf(sStart));
996 output.append(" - ");
997 output.append(String.valueOf(sEnd));
998 output.append(" Maps to ");
999 output.append(NEWLINE);
1000 output.append(new Format("%" + maxid + "s").form(structId));
1001 output.append(" : ");
1002 output.append(String.valueOf(pdbStart));
1003 output.append(" - ");
1004 output.append(String.valueOf(pdbEnd));
1005 output.append(NEWLINE).append(NEWLINE);
1007 int matchedSeqCount = 0;
1008 for (int j = 0; j < nochunks; j++)
1010 // Print the first aligned sequence
1011 output.append(new Format("%" + (maxid) + "s").form(seqName)).append(
1014 for (int i = 0; i < len; i++)
1016 if ((i + (j * len)) < seqRes.length())
1018 output.append(seqRes.charAt(i + (j * len)));
1022 output.append(NEWLINE);
1023 output.append(new Format("%" + (maxid) + "s").form(" ")).append(" ");
1025 // Print out the matching chars
1026 for (int i = 0; i < len; i++)
1030 if ((i + (j * len)) < seqRes.length())
1032 boolean sameChar = Comparison.isSameResidue(
1033 seqRes.charAt(i + (j * len)),
1034 strRes.charAt(i + (j * len)), false);
1036 && !jalview.util.Comparison.isGap(seqRes.charAt(i
1042 else if (type.equals("pep"))
1044 if (ResidueProperties.getPAM250(seqRes.charAt(i + (j * len)),
1045 strRes.charAt(i + (j * len))) > 0)
1059 } catch (IndexOutOfBoundsException e)
1064 // Now print the second aligned sequence
1065 output = output.append(NEWLINE);
1066 output = output.append(new Format("%" + (maxid) + "s").form(strName))
1068 for (int i = 0; i < len; i++)
1070 if ((i + (j * len)) < strRes.length())
1072 output.append(strRes.charAt(i + (j * len)));
1075 output.append(NEWLINE).append(NEWLINE);
1077 float pid = (float) matchedSeqCount / seqRes.length() * 100;
1078 if (pid < SiftsSettings.getFailSafePIDThreshold())
1080 throw new SiftsException(">>> Low PID detected for SIFTs mapping...");
1082 output.append("Length of alignment = " + seqRes.length()).append(
1084 output.append(new Format("Percentage ID = %2.2f").form(pid));
1089 public int getEntityCount()
1091 return siftsEntry.getEntity().size();
1095 public String getDbAccessionId()
1097 return siftsEntry.getDbAccessionId();
1101 public String getDbCoordSys()
1103 return siftsEntry.getDbCoordSys();
1107 public String getDbSource()
1109 return siftsEntry.getDbSource();
1113 public String getDbVersion()
1115 return siftsEntry.getDbVersion();
1118 public static void setMockSiftsFile(File file)
1120 mockSiftsFile = file;