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;
40 import jalview.xml.binding.sifts.Entry.ListDB.Db;
43 import java.io.FileInputStream;
44 import java.io.FileNotFoundException;
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;
62 import java.util.TreeMap;
63 import java.util.zip.GZIPInputStream;
65 import javax.xml.bind.JAXBContext;
66 import javax.xml.bind.JAXBException;
67 import javax.xml.bind.Unmarshaller;
68 import javax.xml.stream.FactoryConfigurationError;
69 import javax.xml.stream.XMLInputFactory;
70 import javax.xml.stream.XMLStreamException;
71 import javax.xml.stream.XMLStreamReader;
74 import MCview.PDBChain;
75 import MCview.PDBfile;
77 public class SiftsClient implements SiftsClientI
79 private Entry siftsEntry;
81 private StructureFile pdb;
85 private String structId;
87 private String segStartEnd;
89 private CoordinateSys seqCoordSys = CoordinateSys.UNIPROT;
91 private static final int BUFFER_SIZE = 4096;
93 public static final int UNASSIGNED = -1;
95 private static final int PDB_RES_POS = 0;
97 private static final int PDB_ATOM_POS = 1;
99 private static final String NOT_FOUND = "Not_Found";
101 private static final String NOT_OBSERVED = "Not_Observed";
103 private static final String SIFTS_FTP_BASE_URL = "ftp://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 public enum CoordinateSys
113 UNIPROT("UniProt"), PDB("PDBresnum"), PDBe("PDBe");
116 private CoordinateSys(String name)
121 public String getName()
127 public 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 * Construct an instance of SiftsClient using the supplied SIFTs file. Note:
161 * The SIFTs file should correspond to the PDB Id in PDBfile instance
165 * @throws SiftsException
168 public SiftsClient(PDBfile pdb, File siftsFile) throws SiftsException
171 this.pdbId = pdb.getId();
172 siftsEntry = parseSIFTs(siftsFile);
176 * Parse the given SIFTs File and return a JAXB POJO of parsed data
179 * - the GZipped SIFTs XML file to parse
182 * if a problem occurs while parsing the SIFTs XML
184 private Entry parseSIFTs(File siftFile) throws SiftsException
186 try (InputStream in = new FileInputStream(siftFile);
187 GZIPInputStream gzis = new GZIPInputStream(in);)
189 // System.out.println("File : " + siftFile.getAbsolutePath());
190 JAXBContext jc = JAXBContext.newInstance("jalview.xml.binding.sifts");
191 XMLStreamReader streamReader = XMLInputFactory.newInstance()
192 .createXMLStreamReader(gzis);
193 Unmarshaller um = jc.createUnmarshaller();
194 return (Entry) um.unmarshal(streamReader);
195 } catch (JAXBException e)
198 throw new SiftsException(e.getMessage());
199 } catch (FileNotFoundException e)
202 throw new SiftsException(e.getMessage());
203 } catch (XMLStreamException e)
206 throw new SiftsException(e.getMessage());
207 } catch (FactoryConfigurationError e)
210 throw new SiftsException(e.getMessage());
211 } catch (IOException e)
214 throw new SiftsException(e.getMessage());
219 * Get a SIFTs XML file for a given PDB Id from Cache or download from FTP
220 * repository if not found in cache
223 * @return SIFTs XML file
224 * @throws SiftsException
226 public static File getSiftsFile(String pdbId) throws SiftsException
228 File siftsFile = new File(SiftsSettings.getSiftDownloadDirectory()
229 + pdbId.toLowerCase() + ".xml.gz");
230 if (siftsFile.exists())
232 // The line below is required for unit testing... don't comment it out!!!
233 System.out.println(">>> SIFTS File already downloaded for " + pdbId);
235 if (isFileOlderThanThreshold(siftsFile,
236 SiftsSettings.getCacheThresholdInDays()))
238 // System.out.println("Downloaded file is out of date, hence re-downloading...");
239 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
243 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
248 * This method enables checking if a cached file has exceeded a certain
254 * the threshold in days
257 public static boolean isFileOlderThanThreshold(File file, int noOfDays)
259 Path filePath = file.toPath();
260 BasicFileAttributes attr;
264 attr = Files.readAttributes(filePath, BasicFileAttributes.class);
265 diffInDays = (int) ((new Date().getTime() - attr.lastModifiedTime()
266 .toMillis()) / (1000 * 60 * 60 * 24));
267 // System.out.println("Diff in days : " + diffInDays);
268 } catch (IOException e)
272 return noOfDays <= diffInDays;
276 * Download a SIFTs XML file for a given PDB Id from an FTP repository
279 * @return downloaded SIFTs XML file
280 * @throws SiftsException
282 public static File downloadSiftsFile(String pdbId) throws SiftsException
284 if (pdbId.contains(".cif"))
286 pdbId = pdbId.replace(".cif", "");
288 String siftFile = pdbId + ".xml.gz";
289 String siftsFileFTPURL = SIFTS_FTP_BASE_URL + siftFile;
290 String downloadedSiftsFile = SiftsSettings.getSiftDownloadDirectory()
292 File siftsDownloadDir = new File(
293 SiftsSettings.getSiftDownloadDirectory());
294 if (!siftsDownloadDir.exists())
296 siftsDownloadDir.mkdirs();
300 // System.out.println(">> Download ftp url : " + siftsFileFTPURL);
301 URL url = new URL(siftsFileFTPURL);
302 URLConnection conn = url.openConnection();
303 InputStream inputStream = conn.getInputStream();
304 FileOutputStream outputStream = new FileOutputStream(
305 downloadedSiftsFile);
306 byte[] buffer = new byte[BUFFER_SIZE];
308 while ((bytesRead = inputStream.read(buffer)) != -1)
310 outputStream.write(buffer, 0, bytesRead);
312 outputStream.close();
314 // System.out.println(">>> File downloaded : " + downloadedSiftsFile);
315 } catch (IOException ex)
317 throw new SiftsException(ex.getMessage());
319 return new File(downloadedSiftsFile);
323 * Delete the SIFTs file for the given PDB Id in the local SIFTs download
327 * @return true if the file was deleted or doesn't exist
329 public static boolean deleteSiftsFileByPDBId(String pdbId)
331 File siftsFile = new File(SiftsSettings.getSiftDownloadDirectory()
332 + pdbId.toLowerCase() + ".xml.gz");
333 if (siftsFile.exists())
335 return siftsFile.delete();
341 * Get a valid SIFTs DBRef for the given sequence current SIFTs entry
344 * - the target sequence for the operation
345 * @return a valid DBRefEntry that is SIFTs compatible
347 * if no valid source DBRefEntry was found for the given sequences
349 public DBRefEntryI getValidSourceDBRef(SequenceI seq)
350 throws SiftsException
352 DBRefEntryI sourceDBRef = null;
353 sourceDBRef = seq.getSourceDBRef();
354 if (sourceDBRef != null && isValidDBRefEntry(sourceDBRef))
360 DBRefEntry[] dbRefs = seq.getDBRefs();
361 if (dbRefs == null || dbRefs.length < 1)
363 throw new SiftsException(
364 "Source DBRef could not be determined. DBRefs might not have been retrieved.");
367 for (DBRefEntryI dbRef : dbRefs)
369 if (dbRef == null || dbRef.getAccessionId() == null
370 || dbRef.getSource() == null)
374 if (isFoundInSiftsEntry(dbRef.getAccessionId())
375 && (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT) || dbRef
376 .getSource().equalsIgnoreCase(DBRefSource.PDB)))
378 seq.setSourceDBRef(dbRef);
383 if (sourceDBRef != null && isValidDBRefEntry(sourceDBRef))
387 throw new SiftsException("Could not get source DB Ref");
391 * Check that the DBRef Entry is properly populated and is available in this
392 * SiftClient instance
395 * - DBRefEntry to validate
396 * @return true validation is successful otherwise false is returned.
398 private boolean isValidDBRefEntry(DBRefEntryI entry)
400 return entry != null && entry.getAccessionId() != null
401 && isFoundInSiftsEntry(entry.getAccessionId());
405 public HashSet<String> getAllMappingAccession()
407 HashSet<String> accessions = new HashSet<String>();
408 List<Entity> entities = siftsEntry.getEntity();
409 for (Entity entity : entities)
411 List<Segment> segments = entity.getSegment();
412 for (Segment segment : segments)
414 List<MapRegion> mapRegions = segment.getListMapRegion()
416 for (MapRegion mapRegion : mapRegions)
419 .add(mapRegion.getDb().getDbAccessionId().toLowerCase());
427 public StructureMapping getSiftsStructureMapping(SequenceI seq,
428 String pdbFile, String chain) throws SiftsException
430 structId = (chain == null) ? pdbId : pdbId + "|" + chain;
431 System.out.println("Getting mapping for: " + pdbId + "|" + chain
432 + " : seq- " + seq.getName());
434 final StringBuilder mappingDetails = new StringBuilder(128);
435 PrintStream ps = new PrintStream(System.out)
438 public void print(String x)
440 mappingDetails.append(x);
444 public void println()
446 mappingDetails.append(NEWLINE);
449 HashMap<Integer, int[]> mapping = getGreedyMapping(chain, seq, ps);
451 String mappingOutput = mappingDetails.toString();
452 StructureMapping siftsMapping = new StructureMapping(seq, pdbFile,
453 pdbId, chain, mapping, mappingOutput);
458 public HashMap<Integer, int[]> getGreedyMapping(String entityId,
459 SequenceI seq, java.io.PrintStream os) throws SiftsException
461 ArrayList<Integer> omitNonObserved = new ArrayList<Integer>();
462 int nonObservedShiftIndex = 0;
463 // System.out.println("Generating mappings for : " + entityId);
464 Entity entity = null;
465 entity = getEntityById(entityId);
466 String originalSeq = AlignSeq.extractGaps(
467 jalview.util.Comparison.GapChars, seq.getSequenceAsString());
468 HashMap<Integer, int[]> mapping = new HashMap<Integer, int[]>();
469 DBRefEntryI sourceDBRef = seq.getSourceDBRef();
470 sourceDBRef = getValidSourceDBRef(seq);
471 // TODO ensure sequence start/end is in the same coordinate system and
472 // consistent with the choosen sourceDBRef
474 // set sequence coordinate system - default value is UniProt
475 if (sourceDBRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
477 seqCoordSys = CoordinateSys.PDB;
480 HashSet<String> dbRefAccessionIdsString = new HashSet<String>();
481 for (DBRefEntry dbref : seq.getDBRefs())
483 dbRefAccessionIdsString.add(dbref.getAccessionId().toLowerCase());
485 dbRefAccessionIdsString.add(sourceDBRef.getAccessionId().toLowerCase());
487 curDBRefAccessionIdsString = dbRefAccessionIdsString;
488 curSourceDBRef = sourceDBRef.getAccessionId();
490 TreeMap<Integer, String> resNumMap = new TreeMap<Integer, String>();
491 List<Segment> segments = entity.getSegment();
492 for (Segment segment : segments)
494 segStartEnd = segment.getStart() + " - " + segment.getEnd();
495 // System.out.println("Mapping segments : " + segment.getSegId() + "\\"
497 List<Residue> residues = segment.getListResidue().getResidue();
498 for (Residue residue : residues)
500 int currSeqIndex = UNASSIGNED;
501 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
502 CrossRefDb pdbRefDb = null;
503 for (CrossRefDb cRefDb : cRefDbs)
505 if (cRefDb.getDbSource().equalsIgnoreCase(DBRefSource.PDB))
509 if (cRefDb.getDbCoordSys()
510 .equalsIgnoreCase(seqCoordSys.getName())
511 && isAccessionMatched(cRefDb.getDbAccessionId()))
513 String resNumIndexString = cRefDb.getDbResNum()
514 .equalsIgnoreCase("None") ? String.valueOf(UNASSIGNED)
515 : cRefDb.getDbResNum();
518 currSeqIndex = Integer.valueOf(resNumIndexString);
519 } catch (NumberFormatException nfe)
521 currSeqIndex = Integer.valueOf(resNumIndexString
522 .split("[a-zA-Z]")[0]);
525 if (pdbRefDb != null)
527 break;// exit loop if pdb and uniprot are already found
531 if (currSeqIndex == UNASSIGNED)
535 if (currSeqIndex >= seq.getStart() && currSeqIndex <= seq.getEnd())
540 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
541 .getDbResNum()) : Integer.valueOf(pdbRefDb
543 } catch (NumberFormatException nfe)
545 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
546 .getDbResNum()) : Integer.valueOf(pdbRefDb
547 .getDbResNum().split("[a-zA-Z]")[0]);
551 if (isResidueObserved(residue)
552 || seqCoordSys == CoordinateSys.UNIPROT)
554 char resCharCode = ResidueProperties
555 .getSingleCharacterCode(ResidueProperties
556 .getCanonicalAminoAcid(residue.getDbResName()));
557 resNumMap.put(currSeqIndex, String.valueOf(resCharCode));
561 omitNonObserved.add(currSeqIndex);
562 ++nonObservedShiftIndex;
564 mapping.put(currSeqIndex - nonObservedShiftIndex, new int[] {
565 Integer.valueOf(resNum), UNASSIGNED });
571 populateAtomPositions(entityId, mapping);
572 } catch (Exception e)
576 if (seqCoordSys == CoordinateSys.UNIPROT)
578 padWithGaps(resNumMap, omitNonObserved);
580 int seqStart = UNASSIGNED;
581 int seqEnd = UNASSIGNED;
582 int pdbStart = UNASSIGNED;
583 int pdbEnd = UNASSIGNED;
585 Integer[] keys = mapping.keySet().toArray(new Integer[0]);
589 throw new SiftsException(">>> Empty SIFTS mapping generated!!");
592 seqEnd = keys[keys.length - 1];
594 String matchedSeq = originalSeq;
595 if (seqStart != UNASSIGNED)
597 pdbStart = mapping.get(seqStart)[PDB_RES_POS];
598 pdbEnd = mapping.get(seqEnd)[PDB_RES_POS];
599 int orignalSeqStart = seq.getStart();
600 if (orignalSeqStart >= 1)
602 int subSeqStart = (seqStart >= orignalSeqStart) ? seqStart
603 - orignalSeqStart : 0;
604 int subSeqEnd = seqEnd - (orignalSeqStart - 1);
605 subSeqEnd = originalSeq.length() < subSeqEnd ? originalSeq.length()
607 matchedSeq = originalSeq.substring(subSeqStart, subSeqEnd);
611 matchedSeq = originalSeq.substring(1, originalSeq.length());
615 StringBuilder targetStrucSeqs = new StringBuilder();
616 for (String res : resNumMap.values())
618 targetStrucSeqs.append(res);
623 MappingOutputPojo mop = new MappingOutputPojo();
624 mop.setSeqStart(pdbStart);
625 mop.setSeqEnd(pdbEnd);
626 mop.setSeqName(seq.getName());
627 mop.setSeqResidue(matchedSeq);
629 mop.setStrStart(seqStart);
630 mop.setStrEnd(seqEnd);
631 mop.setStrName(structId);
632 mop.setStrResidue(targetStrucSeqs.toString());
635 os.print(getMappingOutput(mop).toString());
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
649 void populateAtomPositions(String chainId,
650 HashMap<Integer, int[]> mapping) throws IllegalArgumentException
654 PDBChain chain = pdb.findChain(chainId);
656 if (chain == null || mapping == null)
658 throw new IllegalArgumentException(
659 "Chain id or mapping must not be null.");
661 for (int[] map : mapping.values())
663 if (map[PDB_RES_POS] != UNASSIGNED)
665 map[PDB_ATOM_POS] = getAtomIndex(map[PDB_RES_POS], chain.atoms);
668 } catch (Exception e)
676 * @param residueIndex
677 * The residue index used for the search
679 * A collection of Atom to search
680 * @return atom position for the given residue index
682 int getAtomIndex(int residueIndex, Collection<Atom> atoms)
686 throw new IllegalArgumentException(
687 "atoms collection must not be null!");
689 for (Atom atom : atoms)
691 if (atom.resNumber == residueIndex)
693 return atom.atomIndex;
700 * Checks if the residue instance is marked 'Not_observed' or not
705 private boolean isResidueObserved(Residue residue)
707 HashSet<String> annotations = getResidueAnnotaitons(residue,
708 ResidueDetailType.ANNOTATION);
709 if (annotations == null || annotations.isEmpty())
713 for (String annotation : annotations)
715 if (annotation.equalsIgnoreCase(NOT_OBSERVED))
724 * Get annotation String for a given residue and annotation type
730 private HashSet<String> getResidueAnnotaitons(Residue residue,
731 ResidueDetailType type)
733 HashSet<String> foundAnnotations = new HashSet<String>();
734 List<ResidueDetail> resDetails = residue.getResidueDetail();
735 for (ResidueDetail resDetail : resDetails)
737 if (resDetail.getProperty().equalsIgnoreCase(type.getCode()))
739 foundAnnotations.add(resDetail.getContent());
742 return foundAnnotations;
746 public boolean isAccessionMatched(String accession)
748 boolean isStrictMatch = true;
749 return isStrictMatch ? curSourceDBRef.equalsIgnoreCase(accession)
750 : curDBRefAccessionIdsString.contains(accession.toLowerCase());
753 private boolean isFoundInSiftsEntry(String accessionId)
755 HashSet<String> siftsDBRefs = getAllMappingAccession();
756 return accessionId != null
757 && siftsDBRefs.contains(accessionId.toLowerCase());
761 * Pad omitted residue positions in PDB sequence with gaps
765 void padWithGaps(TreeMap<Integer, String> resNumMap,
766 ArrayList<Integer> omitNonObserved)
768 if (resNumMap == null || resNumMap.isEmpty())
772 Integer[] keys = resNumMap.keySet().toArray(new Integer[0]);
774 int firstIndex = keys[0];
775 int lastIndex = keys[keys.length - 1];
776 // System.out.println("Min value " + firstIndex);
777 // System.out.println("Max value " + lastIndex);
778 for (int x = firstIndex; x <= lastIndex; x++)
780 if (!resNumMap.containsKey(x) && !omitNonObserved.contains(x))
782 resNumMap.put(x, "-");
790 public Entity getEntityById(String id) throws SiftsException
792 // Sometimes SIFTS mappings are wrongly swapped between different chains of
793 // a PDB entry. This results to wrong mappings being generated. The boolean
794 // flag 'isGetEntityIdDirectly, determines whether an entity to process is
795 // determined by a greedy heuristic search or by just matching the Chain Id
796 // directly against the entity Id tag. Setting the default value to 'false'
797 // utilise the heuristic search which always produces correct mappings but
798 // less optimised processing, where as changing the value to 'true'
799 // optimises performance but might result to incorrect mapping in some cases
800 // where SIFTS mappings are wrongly swapped between different chains.
801 boolean isGetEntityIdDirectly = false;
802 if (isGetEntityIdDirectly)
804 List<Entity> entities = siftsEntry.getEntity();
805 for (Entity entity : entities)
807 if (!entity.getEntityId().equalsIgnoreCase(id))
814 Entity entity = getEntityByMostOptimalMatchedId(id);
819 throw new SiftsException("Entity " + id + " not found");
823 * This method was added because EntityId is NOT always equal to ChainId.
824 * Hence, it provides the logic to greedily detect the "true" Entity for a
825 * given chainId where discrepancies exist.
830 public Entity getEntityByMostOptimalMatchedId(String chainId)
832 // System.out.println("---> advanced greedy entityId matching block entered..");
833 List<Entity> entities = siftsEntry.getEntity();
834 SiftsEntitySortPojo[] sPojo = new SiftsEntitySortPojo[entities.size()];
836 for (Entity entity : entities)
838 sPojo[count] = new SiftsEntitySortPojo();
839 sPojo[count].entityId = entity.getEntityId();
841 List<Segment> segments = entity.getSegment();
842 for (Segment segment : segments)
844 List<Residue> residues = segment.getListResidue().getResidue();
845 for (Residue residue : residues)
847 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
848 for (CrossRefDb cRefDb : cRefDbs)
850 if (!cRefDb.getDbSource().equalsIgnoreCase("PDB"))
854 ++sPojo[count].resCount;
855 if (cRefDb.getDbChainId().equalsIgnoreCase(chainId))
857 ++sPojo[count].chainIdFreq;
862 sPojo[count].pid = 100 * (sPojo[count].chainIdFreq / sPojo[count].resCount);
865 Arrays.sort(sPojo, Collections.reverseOrder());
866 // System.out.println("highest matched entity : " + sPojo[0].entityId);
867 // System.out.println("highest matched pid : " + sPojo[0].pid);
869 if (sPojo[0].entityId != null)
871 for (Entity entity : entities)
873 if (!entity.getEntityId().equalsIgnoreCase(sPojo[0].entityId))
883 public class SiftsEntitySortPojo implements
884 Comparable<SiftsEntitySortPojo>
886 public String entityId;
888 public int chainIdFreq;
895 public int compareTo(SiftsEntitySortPojo o)
897 return this.pid - o.pid;
902 public String[] getEntryDBs()
904 System.out.println("\nListing DB entries...");
905 List<String> availDbs = new ArrayList<String>();
906 List<Db> dbs = siftsEntry.getListDB().getDb();
909 availDbs.add(db.getDbSource());
910 System.out.println(db.getDbSource() + " | " + db.getDbCoordSys());
912 return availDbs.toArray(new String[0]);
916 public StringBuffer getMappingOutput(MappingOutputPojo mp)
917 throws SiftsException
919 String seqRes = mp.getSeqResidue();
920 String seqName = mp.getSeqName();
921 int sStart = mp.getSeqStart();
922 int sEnd = mp.getSeqEnd();
924 String strRes = mp.getStrResidue();
925 String strName = mp.getStrName();
926 int pdbStart = mp.getStrStart();
927 int pdbEnd = mp.getStrEnd();
929 String type = mp.getType();
931 int maxid = (seqName.length() >= strName.length()) ? seqName.length()
933 int len = 72 - maxid - 1;
935 int nochunks = ((seqRes.length()) / len)
936 + ((seqRes.length()) % len > 0 ? 1 : 0);
938 StringBuffer output = new StringBuffer();
939 output.append(NEWLINE);
940 output.append("Sequence \u27f7 Structure mapping details").append(
942 output.append("Method: SIFTS");
943 output.append(NEWLINE).append(NEWLINE);
945 output.append(new Format("%" + maxid + "s").form(seqName));
946 output.append(" : ");
947 output.append(String.valueOf(sStart));
948 output.append(" - ");
949 output.append(String.valueOf(sEnd));
950 output.append(" Maps to ");
951 output.append(NEWLINE);
952 output.append(new Format("%" + maxid + "s").form(structId));
953 output.append(" : ");
954 output.append(String.valueOf(pdbStart));
955 output.append(" - ");
956 output.append(String.valueOf(pdbEnd));
957 output.append(NEWLINE).append(NEWLINE);
959 int matchedSeqCount = 0;
960 for (int j = 0; j < nochunks; j++)
962 // Print the first aligned sequence
963 output.append(new Format("%" + (maxid) + "s").form(seqName)).append(
966 for (int i = 0; i < len; i++)
968 if ((i + (j * len)) < seqRes.length())
970 output.append(seqRes.charAt(i + (j * len)));
974 output.append(NEWLINE);
975 output.append(new Format("%" + (maxid) + "s").form(" ")).append(" ");
977 // Print out the matching chars
978 for (int i = 0; i < len; i++)
982 if ((i + (j * len)) < seqRes.length())
984 if (seqRes.charAt(i + (j * len)) == strRes
985 .charAt(i + (j * len))
986 && !jalview.util.Comparison.isGap(seqRes.charAt(i
992 else if (type.equals("pep"))
994 if (ResidueProperties.getPAM250(seqRes.charAt(i + (j * len)),
995 strRes.charAt(i + (j * len))) > 0)
1009 } catch (IndexOutOfBoundsException e)
1014 // Now print the second aligned sequence
1015 output = output.append(NEWLINE);
1016 output = output.append(new Format("%" + (maxid) + "s").form(strName))
1018 for (int i = 0; i < len; i++)
1020 if ((i + (j * len)) < strRes.length())
1022 output.append(strRes.charAt(i + (j * len)));
1025 output.append(NEWLINE).append(NEWLINE);
1027 float pid = (float) matchedSeqCount / seqRes.length() * 100;
1028 if (pid < SiftsSettings.getFailSafePIDThreshold())
1030 throw new SiftsException(">>> Low PID detected for SIFTs mapping...");
1032 output.append("Length of alignment = " + seqRes.length()).append(
1034 output.append(new Format("Percentage ID = %2.2f").form(pid));
1035 output.append(NEWLINE);
1040 public int getEntityCount()
1042 return siftsEntry.getEntity().size();
1046 public String getDbAccessionId()
1048 return siftsEntry.getDbAccessionId();
1052 public String getDbCoordSys()
1054 return siftsEntry.getDbCoordSys();
1058 public String getDbEvidence()
1060 return siftsEntry.getDbEvidence();
1064 public String getDbSource()
1066 return siftsEntry.getDbSource();
1070 public String getDbVersion()
1072 return siftsEntry.getDbVersion();