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("Could not get source DB Ref");
366 for (DBRefEntryI dbRef : dbRefs)
368 if (dbRef == null || dbRef.getAccessionId() == null
369 || dbRef.getSource() == null)
373 if (isFoundInSiftsEntry(dbRef.getAccessionId())
374 && (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT) || dbRef
375 .getSource().equalsIgnoreCase(DBRefSource.PDB)))
381 if (sourceDBRef != null && isValidDBRefEntry(sourceDBRef))
385 throw new SiftsException("Could not get source DB Ref");
389 * Check that the DBRef Entry is properly populated and is available in this
390 * SiftClient instance
393 * - DBRefEntry to validate
394 * @return true validation is successful otherwise false is returned.
396 private boolean isValidDBRefEntry(DBRefEntryI entry)
398 return entry != null && entry.getAccessionId() != null
399 && isFoundInSiftsEntry(entry.getAccessionId());
403 public HashSet<String> getAllMappingAccession()
405 HashSet<String> accessions = new HashSet<String>();
406 List<Entity> entities = siftsEntry.getEntity();
407 for (Entity entity : entities)
409 List<Segment> segments = entity.getSegment();
410 for (Segment segment : segments)
412 List<MapRegion> mapRegions = segment.getListMapRegion()
414 for (MapRegion mapRegion : mapRegions)
416 accessions.add(mapRegion.getDb().getDbAccessionId());
424 public StructureMapping getSiftsStructureMapping(SequenceI seq,
425 String pdbFile, String chain) throws SiftsException
427 structId = (chain == null) ? pdbId : pdbId + "|" + chain;
428 System.out.println("Getting mapping for: " + pdbId + "|" + chain
429 + " : seq- " + seq.getName());
431 final StringBuilder mappingDetails = new StringBuilder(128);
432 PrintStream ps = new PrintStream(System.out)
435 public void print(String x)
437 mappingDetails.append(x);
441 public void println()
443 mappingDetails.append(NEWLINE);
446 HashMap<Integer, int[]> mapping = getGreedyMapping(chain, seq, ps);
448 String mappingOutput = mappingDetails.toString();
449 StructureMapping siftsMapping = new StructureMapping(seq, pdbFile,
450 pdbId, chain, mapping, mappingOutput);
455 public HashMap<Integer, int[]> getGreedyMapping(String entityId,
456 SequenceI seq, java.io.PrintStream os) throws SiftsException
458 ArrayList<Integer> omitNonObserved = new ArrayList<Integer>();
459 int nonObservedShiftIndex = 0;
460 // System.out.println("Generating mappings for : " + entityId);
461 Entity entity = null;
462 entity = getEntityById(entityId);
463 String originalSeq = AlignSeq.extractGaps(
464 jalview.util.Comparison.GapChars, seq.getSequenceAsString());
465 HashMap<Integer, int[]> mapping = new HashMap<Integer, int[]>();
466 DBRefEntryI sourceDBRef = seq.getSourceDBRef();
467 if (sourceDBRef == null)
469 sourceDBRef = getValidSourceDBRef(seq);
470 // TODO ensure sequence start/end is in the same coordinate system and
471 // 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 return accessionId != null
756 && getAllMappingAccession().contains(accessionId);
760 * Pad omitted residue positions in PDB sequence with gaps
764 void padWithGaps(TreeMap<Integer, String> resNumMap,
765 ArrayList<Integer> omitNonObserved)
767 if (resNumMap == null || resNumMap.isEmpty())
771 Integer[] keys = resNumMap.keySet().toArray(new Integer[0]);
773 int firstIndex = keys[0];
774 int lastIndex = keys[keys.length - 1];
775 // System.out.println("Min value " + firstIndex);
776 // System.out.println("Max value " + lastIndex);
777 for (int x = firstIndex; x <= lastIndex; x++)
779 if (!resNumMap.containsKey(x) && !omitNonObserved.contains(x))
781 resNumMap.put(x, "-");
789 public Entity getEntityById(String id) throws SiftsException
791 // Sometimes SIFTS mappings are wrongly swapped between different chains of
792 // a PDB entry. This results to wrong mappings being generated. The boolean
793 // flag 'isGetEntityIdDirectly, determines whether an entity to process is
794 // determined by a greedy heuristic search or by just matching the Chain Id
795 // directly against the entity Id tag. Setting the default value to 'false'
796 // utilise the heuristic search which always produces correct mappings but
797 // less optimised processing, where as changing the value to 'true'
798 // optimises performance but might result to incorrect mapping in some cases
799 // where SIFTS mappings are wrongly swapped between different chains.
800 boolean isGetEntityIdDirectly = false;
801 if (isGetEntityIdDirectly)
803 List<Entity> entities = siftsEntry.getEntity();
804 for (Entity entity : entities)
806 if (!entity.getEntityId().equalsIgnoreCase(id))
813 Entity entity = getEntityByMostOptimalMatchedId(id);
818 throw new SiftsException("Entity " + id + " not found");
822 * This method was added because EntityId is NOT always equal to ChainId.
823 * Hence, it provides the logic to greedily detect the "true" Entity for a
824 * given chainId where discrepancies exist.
829 public Entity getEntityByMostOptimalMatchedId(String chainId)
831 // System.out.println("---> advanced greedy entityId matching block entered..");
832 List<Entity> entities = siftsEntry.getEntity();
833 SiftsEntitySortPojo[] sPojo = new SiftsEntitySortPojo[entities.size()];
835 for (Entity entity : entities)
837 sPojo[count] = new SiftsEntitySortPojo();
838 sPojo[count].entityId = entity.getEntityId();
840 List<Segment> segments = entity.getSegment();
841 for (Segment segment : segments)
843 List<Residue> residues = segment.getListResidue().getResidue();
844 for (Residue residue : residues)
846 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
847 for (CrossRefDb cRefDb : cRefDbs)
849 if (!cRefDb.getDbSource().equalsIgnoreCase("PDB"))
853 ++sPojo[count].resCount;
854 if (cRefDb.getDbChainId().equalsIgnoreCase(chainId))
856 ++sPojo[count].chainIdFreq;
861 sPojo[count].pid = 100 * (sPojo[count].chainIdFreq / sPojo[count].resCount);
864 Arrays.sort(sPojo, Collections.reverseOrder());
865 // System.out.println("highest matched entity : " + sPojo[0].entityId);
866 // System.out.println("highest matched pid : " + sPojo[0].pid);
868 if (sPojo[0].entityId != null)
870 for (Entity entity : entities)
872 if (!entity.getEntityId().equalsIgnoreCase(sPojo[0].entityId))
882 public class SiftsEntitySortPojo implements
883 Comparable<SiftsEntitySortPojo>
885 public String entityId;
887 public int chainIdFreq;
894 public int compareTo(SiftsEntitySortPojo o)
896 return this.pid - o.pid;
901 public String[] getEntryDBs()
903 System.out.println("\nListing DB entries...");
904 List<String> availDbs = new ArrayList<String>();
905 List<Db> dbs = siftsEntry.getListDB().getDb();
908 availDbs.add(db.getDbSource());
909 System.out.println(db.getDbSource() + " | " + db.getDbCoordSys());
911 return availDbs.toArray(new String[0]);
915 public StringBuffer getMappingOutput(MappingOutputPojo mp)
916 throws SiftsException
918 String seqRes = mp.getSeqResidue();
919 String seqName = mp.getSeqName();
920 int sStart = mp.getSeqStart();
921 int sEnd = mp.getSeqEnd();
923 String strRes = mp.getStrResidue();
924 String strName = mp.getStrName();
925 int pdbStart = mp.getStrStart();
926 int pdbEnd = mp.getStrEnd();
928 String type = mp.getType();
930 int maxid = (seqName.length() >= strName.length()) ? seqName.length()
932 int len = 72 - maxid - 1;
934 int nochunks = ((seqRes.length()) / len)
935 + ((seqRes.length()) % len > 0 ? 1 : 0);
937 StringBuffer output = new StringBuffer();
938 output.append(NEWLINE);
939 output.append("Sequence \u27f7 Structure mapping details").append(
941 output.append("Method: SIFTS");
942 output.append(NEWLINE).append(NEWLINE);
944 output.append(new Format("%" + maxid + "s").form(seqName));
945 output.append(" : ");
946 output.append(String.valueOf(sStart));
947 output.append(" - ");
948 output.append(String.valueOf(sEnd));
949 output.append(" Maps to ");
950 output.append(NEWLINE);
951 output.append(new Format("%" + maxid + "s").form(structId));
952 output.append(" : ");
953 output.append(String.valueOf(pdbStart));
954 output.append(" - ");
955 output.append(String.valueOf(pdbEnd));
956 output.append(NEWLINE).append(NEWLINE);
958 int matchedSeqCount = 0;
959 for (int j = 0; j < nochunks; j++)
961 // Print the first aligned sequence
962 output.append(new Format("%" + (maxid) + "s").form(seqName)).append(
965 for (int i = 0; i < len; i++)
967 if ((i + (j * len)) < seqRes.length())
969 output.append(seqRes.charAt(i + (j * len)));
973 output.append(NEWLINE);
974 output.append(new Format("%" + (maxid) + "s").form(" ")).append(" ");
976 // Print out the matching chars
977 for (int i = 0; i < len; i++)
981 if ((i + (j * len)) < seqRes.length())
983 if (seqRes.charAt(i + (j * len)) == strRes
984 .charAt(i + (j * len))
985 && !jalview.util.Comparison.isGap(seqRes.charAt(i
991 else if (type.equals("pep"))
993 if (ResidueProperties.getPAM250(seqRes.charAt(i + (j * len)),
994 strRes.charAt(i + (j * len))) > 0)
1008 } catch (IndexOutOfBoundsException e)
1013 // Now print the second aligned sequence
1014 output = output.append(NEWLINE);
1015 output = output.append(new Format("%" + (maxid) + "s").form(strName))
1017 for (int i = 0; i < len; i++)
1019 if ((i + (j * len)) < strRes.length())
1021 output.append(strRes.charAt(i + (j * len)));
1024 output.append(NEWLINE).append(NEWLINE);
1026 float pid = (float) matchedSeqCount / seqRes.length() * 100;
1027 if (pid < SiftsSettings.getFailSafePIDThreshold())
1029 throw new SiftsException(">>> Low PID detected for SIFTs mapping...");
1031 output.append("Length of alignment = " + seqRes.length()).append(
1033 output.append(new Format("Percentage ID = %2.2f").form(pid));
1034 output.append(NEWLINE);
1039 public int getEntityCount()
1041 return siftsEntry.getEntity().size();
1045 public String getDbAccessionId()
1047 return siftsEntry.getDbAccessionId();
1051 public String getDbCoordSys()
1053 return siftsEntry.getDbCoordSys();
1057 public String getDbEvidence()
1059 return siftsEntry.getDbEvidence();
1063 public String getDbSource()
1065 return siftsEntry.getDbSource();
1069 public String getDbVersion()
1071 return siftsEntry.getDbVersion();