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 String curSourceDBRef;
108 private HashSet<String> curDBRefAccessionIdsString;
110 public enum CoordinateSys
112 UNIPROT("UniProt"), PDB("PDBresnum"), PDBe("PDBe");
115 private CoordinateSys(String name)
120 public String getName()
126 public enum ResidueDetailType
128 NAME_SEC_STRUCTURE("nameSecondaryStructure"), CODE_SEC_STRUCTURE(
129 "codeSecondaryStructure"), ANNOTATION("Annotation");
132 private ResidueDetailType(String code)
137 public String getCode()
144 * Fetch SIFTs file for the given PDBfile and construct an instance of
148 * @throws SiftsException
150 public SiftsClient(PDBfile pdb) throws SiftsException
153 this.pdbId = pdb.getId();
154 File siftsFile = getSiftsFile(pdbId);
155 siftsEntry = parseSIFTs(siftsFile);
159 * Construct an instance of SiftsClient using the supplied SIFTs file. Note:
160 * The SIFTs file should correspond to the PDB Id in PDBfile instance
164 * @throws SiftsException
167 public SiftsClient(PDBfile pdb, File siftsFile) throws SiftsException
170 this.pdbId = pdb.getId();
171 siftsEntry = parseSIFTs(siftsFile);
175 * Parse the given SIFTs File and return a JAXB POJO of parsed data
178 * - the GZipped SIFTs XML file to parse
181 * if a problem occurs while parsing the SIFTs XML
183 private Entry parseSIFTs(File siftFile) throws SiftsException
185 try (InputStream in = new FileInputStream(siftFile);
186 GZIPInputStream gzis = new GZIPInputStream(in);)
188 // System.out.println("File : " + siftFile.getAbsolutePath());
189 JAXBContext jc = JAXBContext.newInstance("jalview.xml.binding.sifts");
190 XMLStreamReader streamReader = XMLInputFactory.newInstance()
191 .createXMLStreamReader(gzis);
192 Unmarshaller um = jc.createUnmarshaller();
193 return (Entry) um.unmarshal(streamReader);
194 } catch (JAXBException e)
197 throw new SiftsException(e.getMessage());
198 } catch (FileNotFoundException e)
201 throw new SiftsException(e.getMessage());
202 } catch (XMLStreamException e)
205 throw new SiftsException(e.getMessage());
206 } catch (FactoryConfigurationError e)
209 throw new SiftsException(e.getMessage());
210 } catch (IOException e)
213 throw new SiftsException(e.getMessage());
218 * Get a SIFTs XML file for a given PDB Id from Cache or download from FTP
219 * repository if not found in cache
222 * @return SIFTs XML file
223 * @throws SiftsException
225 public static File getSiftsFile(String pdbId) throws SiftsException
227 File siftsFile = new File(SiftsSettings.getSiftDownloadDirectory()
228 + pdbId.toLowerCase() + ".xml.gz");
229 if (siftsFile.exists())
231 // The line below is required for unit testing... don't comment it out!!!
232 System.out.println(">>> SIFTS File already downloaded for " + pdbId);
234 if (isFileOlderThanThreshold(siftsFile,
235 SiftsSettings.getCacheThresholdInDays()))
237 // System.out.println("Downloaded file is out of date, hence re-downloading...");
238 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
242 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
247 * This method enables checking if a cached file has exceeded a certain
253 * the threshold in days
256 public static boolean isFileOlderThanThreshold(File file, int noOfDays)
258 Path filePath = file.toPath();
259 BasicFileAttributes attr;
263 attr = Files.readAttributes(filePath, BasicFileAttributes.class);
264 diffInDays = (int) ((new Date().getTime() - attr.lastModifiedTime()
265 .toMillis()) / (1000 * 60 * 60 * 24));
266 // System.out.println("Diff in days : " + diffInDays);
267 } catch (IOException e)
271 return noOfDays <= diffInDays;
275 * Download a SIFTs XML file for a given PDB Id from an FTP repository
278 * @return downloaded SIFTs XML file
279 * @throws SiftsException
281 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();
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]);
524 if (pdbRefDb != null)
526 break;// exit loop if pdb and uniprot are already found
530 if (currSeqIndex == UNASSIGNED)
534 if (currSeqIndex >= seq.getStart() && currSeqIndex <= seq.getEnd())
539 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
540 .getDbResNum()) : Integer.valueOf(pdbRefDb
542 } catch (NumberFormatException nfe)
544 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
545 .getDbResNum()) : Integer.valueOf(pdbRefDb
546 .getDbResNum().split("[a-zA-Z]")[0]);
550 if (isResidueObserved(residue)
551 || seqCoordSys == CoordinateSys.UNIPROT)
553 char resCharCode = ResidueProperties
554 .getSingleCharacterCode(ResidueProperties
555 .getCanonicalAminoAcid(residue.getDbResName()));
556 resNumMap.put(currSeqIndex, String.valueOf(resCharCode));
560 omitNonObserved.add(currSeqIndex);
561 ++nonObservedShiftIndex;
563 mapping.put(currSeqIndex - nonObservedShiftIndex, new int[] {
564 Integer.valueOf(resNum), UNASSIGNED });
570 populateAtomPositions(entityId, mapping);
571 } catch (Exception e)
575 if (seqCoordSys == CoordinateSys.UNIPROT)
577 padWithGaps(resNumMap, omitNonObserved);
579 int seqStart = UNASSIGNED;
580 int seqEnd = UNASSIGNED;
581 int pdbStart = UNASSIGNED;
582 int pdbEnd = UNASSIGNED;
584 Integer[] keys = mapping.keySet().toArray(new Integer[0]);
588 throw new SiftsException(">>> Empty SIFTS mapping generated!!");
591 seqEnd = keys[keys.length - 1];
593 String matchedSeq = originalSeq;
594 if (seqStart != UNASSIGNED)
596 pdbStart = mapping.get(seqStart)[PDB_RES_POS];
597 pdbEnd = mapping.get(seqEnd)[PDB_RES_POS];
598 int orignalSeqStart = seq.getStart();
599 if (orignalSeqStart >= 1)
601 int subSeqStart = (seqStart >= orignalSeqStart) ? seqStart
602 - orignalSeqStart : 0;
603 int subSeqEnd = seqEnd - (orignalSeqStart - 1);
604 subSeqEnd = originalSeq.length() < subSeqEnd ? originalSeq.length()
606 matchedSeq = originalSeq.substring(subSeqStart, subSeqEnd);
610 matchedSeq = originalSeq.substring(1, originalSeq.length());
614 StringBuilder targetStrucSeqs = new StringBuilder();
615 for (String res : resNumMap.values())
617 targetStrucSeqs.append(res);
622 MappingOutputPojo mop = new MappingOutputPojo();
623 mop.setSeqStart(pdbStart);
624 mop.setSeqEnd(pdbEnd);
625 mop.setSeqName(seq.getName());
626 mop.setSeqResidue(matchedSeq);
628 mop.setStrStart(seqStart);
629 mop.setStrEnd(seqEnd);
630 mop.setStrName(structId);
631 mop.setStrResidue(targetStrucSeqs.toString());
634 os.print(getMappingOutput(mop).toString());
642 * Target chain to populate mapping of its atom positions.
644 * Two dimension array of residue index versus atom position
645 * @throws IllegalArgumentException
646 * Thrown if chainId or mapping is null
648 void populateAtomPositions(String chainId,
649 HashMap<Integer, int[]> mapping) throws IllegalArgumentException
653 PDBChain chain = pdb.findChain(chainId);
655 if (chain == null || mapping == null)
657 throw new IllegalArgumentException(
658 "Chain id or mapping must not be null.");
660 for (int[] map : mapping.values())
662 if (map[PDB_RES_POS] != UNASSIGNED)
664 map[PDB_ATOM_POS] = getAtomIndex(map[PDB_RES_POS], chain.atoms);
667 } catch (Exception e)
675 * @param residueIndex
676 * The residue index used for the search
678 * A collection of Atom to search
679 * @return atom position for the given residue index
681 int getAtomIndex(int residueIndex, Collection<Atom> atoms)
685 throw new IllegalArgumentException(
686 "atoms collection must not be null!");
688 for (Atom atom : atoms)
690 if (atom.resNumber == residueIndex)
692 return atom.atomIndex;
699 * Checks if the residue instance is marked 'Not_observed' or not
704 private boolean isResidueObserved(Residue residue)
706 HashSet<String> annotations = getResidueAnnotaitons(residue,
707 ResidueDetailType.ANNOTATION);
708 if (annotations == null || annotations.isEmpty())
712 for (String annotation : annotations)
714 if (annotation.equalsIgnoreCase(NOT_OBSERVED))
723 * Get annotation String for a given residue and annotation type
729 private HashSet<String> getResidueAnnotaitons(Residue residue,
730 ResidueDetailType type)
732 HashSet<String> foundAnnotations = new HashSet<String>();
733 List<ResidueDetail> resDetails = residue.getResidueDetail();
734 for (ResidueDetail resDetail : resDetails)
736 if (resDetail.getProperty().equalsIgnoreCase(type.getCode()))
738 foundAnnotations.add(resDetail.getContent());
741 return foundAnnotations;
745 public boolean isAccessionMatched(String accession)
747 boolean isStrictMatch = true;
748 return isStrictMatch ? curSourceDBRef.equalsIgnoreCase(accession)
749 : curDBRefAccessionIdsString.contains(accession.toLowerCase());
752 private boolean isFoundInSiftsEntry(String accessionId)
754 return accessionId != null
755 && getAllMappingAccession().contains(accessionId);
759 * Pad omitted residue positions in PDB sequence with gaps
763 void padWithGaps(TreeMap<Integer, String> resNumMap,
764 ArrayList<Integer> omitNonObserved)
766 if (resNumMap == null || resNumMap.isEmpty())
770 Integer[] keys = resNumMap.keySet().toArray(new Integer[0]);
772 int firstIndex = keys[0];
773 int lastIndex = keys[keys.length - 1];
774 System.out.println("Min value " + firstIndex);
775 System.out.println("Max value " + lastIndex);
776 for (int x = firstIndex; x <= lastIndex; x++)
778 if (!resNumMap.containsKey(x) && !omitNonObserved.contains(x))
780 resNumMap.put(x, "-");
788 public Entity getEntityById(String id) throws SiftsException
790 // Sometimes SIFTS mappings are wrongly swapped between different chains of
791 // a PDB entry. This results to wrong mappings being generated. The boolean
792 // flag 'isGetEntityIdDirectly, determines whether an entity to process is
793 // determined by a greedy heuristic search or by just matching the Chain Id
794 // directly against the entity Id tag. Setting the default value to 'false'
795 // utilise the heuristic search which always produces correct mappings but
796 // less optimised processing, where as changing the value to 'true'
797 // optimises performance but might result to incorrect mapping in some cases
798 // where SIFTS mappings are wrongly swapped between different chains.
799 boolean isGetEntityIdDirectly = false;
800 if (isGetEntityIdDirectly)
802 List<Entity> entities = siftsEntry.getEntity();
803 for (Entity entity : entities)
805 if (!entity.getEntityId().equalsIgnoreCase(id))
812 Entity entity = getEntityByMostOptimalMatchedId(id);
817 throw new SiftsException("Entity " + id + " not found");
821 * This method was added because EntityId is NOT always equal to ChainId.
822 * Hence, it provides the logic to greedily detect the "true" Entity for a
823 * given chainId where discrepancies exist.
828 public Entity getEntityByMostOptimalMatchedId(String chainId)
830 // System.out.println("---> advanced greedy entityId matching block entered..");
831 List<Entity> entities = siftsEntry.getEntity();
832 SiftsEntitySortPojo[] sPojo = new SiftsEntitySortPojo[entities.size()];
834 for (Entity entity : entities)
836 sPojo[count] = new SiftsEntitySortPojo();
837 sPojo[count].entityId = entity.getEntityId();
839 List<Segment> segments = entity.getSegment();
840 for (Segment segment : segments)
842 List<Residue> residues = segment.getListResidue().getResidue();
843 for (Residue residue : residues)
845 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
846 for (CrossRefDb cRefDb : cRefDbs)
848 if (!cRefDb.getDbSource().equalsIgnoreCase("PDB"))
852 ++sPojo[count].resCount;
853 if (cRefDb.getDbChainId().equalsIgnoreCase(chainId))
855 ++sPojo[count].chainIdFreq;
860 sPojo[count].pid = 100 * (sPojo[count].chainIdFreq / sPojo[count].resCount);
863 Arrays.sort(sPojo, Collections.reverseOrder());
864 System.out.println("highest matched entity : " + sPojo[0].entityId);
865 System.out.println("highest matched pid : " + sPojo[0].pid);
867 if (sPojo[0].entityId != null)
869 for (Entity entity : entities)
871 if (!entity.getEntityId().equalsIgnoreCase(sPojo[0].entityId))
881 public class SiftsEntitySortPojo implements
882 Comparable<SiftsEntitySortPojo>
884 public String entityId;
886 public int chainIdFreq;
893 public int compareTo(SiftsEntitySortPojo o)
895 return this.pid - o.pid;
900 public String[] getEntryDBs()
902 System.out.println("\nListing DB entries...");
903 List<String> availDbs = new ArrayList<String>();
904 List<Db> dbs = siftsEntry.getListDB().getDb();
907 availDbs.add(db.getDbSource());
908 System.out.println(db.getDbSource() + " | " + db.getDbCoordSys());
910 return availDbs.toArray(new String[0]);
914 public StringBuffer getMappingOutput(MappingOutputPojo mp)
915 throws SiftsException
917 String seqRes = mp.getSeqResidue();
918 String seqName = mp.getSeqName();
919 int sStart = mp.getSeqStart();
920 int sEnd = mp.getSeqEnd();
922 String strRes = mp.getStrResidue();
923 String strName = mp.getStrName();
924 int pdbStart = mp.getStrStart();
925 int pdbEnd = mp.getStrEnd();
927 String type = mp.getType();
929 int maxid = (seqName.length() >= strName.length()) ? seqName.length()
931 int len = 72 - maxid - 1;
933 int nochunks = ((seqRes.length()) / len)
934 + ((seqRes.length()) % len > 0 ? 1 : 0);
936 StringBuffer output = new StringBuffer();
937 output.append(NEWLINE);
938 output.append("Sequence ⟷ Structure mapping details").append(NEWLINE);
939 output.append("Method: SIFTS");
940 output.append(NEWLINE).append(NEWLINE);
942 output.append(new Format("%" + maxid + "s").form(seqName));
943 output.append(" : ");
944 output.append(String.valueOf(sStart));
945 output.append(" - ");
946 output.append(String.valueOf(sEnd));
947 output.append(" Maps to ");
948 output.append(NEWLINE);
949 output.append(new Format("%" + maxid + "s").form(structId));
950 output.append(" : ");
951 output.append(String.valueOf(pdbStart));
952 output.append(" - ");
953 output.append(String.valueOf(pdbEnd));
954 output.append(NEWLINE).append(NEWLINE);
956 int matchedSeqCount = 0;
957 for (int j = 0; j < nochunks; j++)
959 // Print the first aligned sequence
960 output.append(new Format("%" + (maxid) + "s").form(seqName)).append(
963 for (int i = 0; i < len; i++)
965 if ((i + (j * len)) < seqRes.length())
967 output.append(seqRes.charAt(i + (j * len)));
971 output.append(NEWLINE);
972 output.append(new Format("%" + (maxid) + "s").form(" ")).append(" ");
974 // Print out the matching chars
975 for (int i = 0; i < len; i++)
979 if ((i + (j * len)) < seqRes.length())
981 if (seqRes.charAt(i + (j * len)) == strRes
982 .charAt(i + (j * len))
983 && !jalview.util.Comparison.isGap(seqRes.charAt(i
989 else if (type.equals("pep"))
991 if (ResidueProperties.getPAM250(seqRes.charAt(i + (j * len)),
992 strRes.charAt(i + (j * len))) > 0)
1006 } catch (IndexOutOfBoundsException e)
1011 // Now print the second aligned sequence
1012 output = output.append(NEWLINE);
1013 output = output.append(new Format("%" + (maxid) + "s").form(strName))
1015 for (int i = 0; i < len; i++)
1017 if ((i + (j * len)) < strRes.length())
1019 output.append(strRes.charAt(i + (j * len)));
1022 output.append(NEWLINE).append(NEWLINE);
1024 float pid = (float) matchedSeqCount / seqRes.length() * 100;
1025 if (pid < SiftsSettings.getFailSafePIDThreshold())
1027 throw new SiftsException(">>> Low PID detected for SIFTs mapping...");
1029 output.append("Length of alignment = " + seqRes.length()).append(
1031 output.append(new Format("Percentage ID = %2.2f").form(pid));
1032 output.append(NEWLINE);
1037 public int getEntityCount()
1039 return siftsEntry.getEntity().size();
1043 public String getDbAccessionId()
1045 return siftsEntry.getDbAccessionId();
1049 public String getDbCoordSys()
1051 return siftsEntry.getDbCoordSys();
1055 public String getDbEvidence()
1057 return siftsEntry.getDbEvidence();
1061 public String getDbSource()
1063 return siftsEntry.getDbSource();
1067 public String getDbVersion()
1069 return siftsEntry.getDbVersion();