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_OBSERVED = "Not_Observed";
101 private static final String SIFTS_FTP_BASE_URL = "http://ftp.ebi.ac.uk/pub/databases/msd/sifts/xml/";
103 private final static String NEWLINE = System.lineSeparator();
105 private String curSourceDBRef;
107 private HashSet<String> curDBRefAccessionIdsString;
109 public enum CoordinateSys
111 UNIPROT("UniProt"), PDB("PDBresnum"), PDBe("PDBe");
114 private CoordinateSys(String name)
119 public String getName()
125 public enum ResidueDetailType
127 NAME_SEC_STRUCTURE("nameSecondaryStructure"), CODE_SEC_STRUCTURE(
128 "codeSecondaryStructure"), ANNOTATION("Annotation");
131 private ResidueDetailType(String code)
136 public String getCode()
143 * Fetch SIFTs file for the given PDBfile and construct an instance of
147 * @throws SiftsException
149 public SiftsClient(StructureFile pdb) throws SiftsException
152 this.pdbId = pdb.getId();
153 File siftsFile = getSiftsFile(pdbId);
154 siftsEntry = parseSIFTs(siftsFile);
158 * Construct an instance of SiftsClient using the supplied SIFTs file. Note:
159 * The SIFTs file should correspond to the PDB Id in PDBfile instance
163 * @throws SiftsException
166 public SiftsClient(PDBfile pdb, File siftsFile) throws SiftsException
169 this.pdbId = pdb.getId();
170 siftsEntry = parseSIFTs(siftsFile);
174 * Parse the given SIFTs File and return a JAXB POJO of parsed data
177 * - the GZipped SIFTs XML file to parse
180 * if a problem occurs while parsing the SIFTs XML
182 private Entry parseSIFTs(File siftFile) throws SiftsException
184 try (InputStream in = new FileInputStream(siftFile);
185 GZIPInputStream gzis = new GZIPInputStream(in);)
187 // System.out.println("File : " + siftFile.getAbsolutePath());
188 JAXBContext jc = JAXBContext.newInstance("jalview.xml.binding.sifts");
189 XMLStreamReader streamReader = XMLInputFactory.newInstance()
190 .createXMLStreamReader(gzis);
191 Unmarshaller um = jc.createUnmarshaller();
192 return (Entry) um.unmarshal(streamReader);
193 } catch (JAXBException e)
196 throw new SiftsException(e.getMessage());
197 } catch (FileNotFoundException e)
200 throw new SiftsException(e.getMessage());
201 } catch (XMLStreamException e)
204 throw new SiftsException(e.getMessage());
205 } catch (FactoryConfigurationError e)
208 throw new SiftsException(e.getMessage());
209 } catch (IOException e)
212 throw new SiftsException(e.getMessage());
217 * Get a SIFTs XML file for a given PDB Id from Cache or download from FTP
218 * repository if not found in cache
221 * @return SIFTs XML file
222 * @throws SiftsException
224 public static File getSiftsFile(String pdbId) throws SiftsException
226 String siftsFileName = SiftsSettings.getSiftDownloadDirectory()
227 + pdbId.toLowerCase() + ".xml.gz";
228 File siftsFile = new File(siftsFileName);
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 File oldSiftsFile = new File(siftsFileName + "_old");
238 siftsFile.renameTo(oldSiftsFile);
241 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
242 oldSiftsFile.delete();
244 } catch (IOException e)
247 oldSiftsFile.renameTo(siftsFile);
248 return new File(siftsFileName);
254 siftsFile = downloadSiftsFile(pdbId.toLowerCase());
255 } catch (IOException e)
257 throw new SiftsException(e.getMessage());
263 * This method enables checking if a cached file has exceeded a certain
269 * the threshold in days
272 public static boolean isFileOlderThanThreshold(File file, int noOfDays)
274 Path filePath = file.toPath();
275 BasicFileAttributes attr;
279 attr = Files.readAttributes(filePath, BasicFileAttributes.class);
280 diffInDays = (int) ((new Date().getTime() - attr.lastModifiedTime()
281 .toMillis()) / (1000 * 60 * 60 * 24));
282 // System.out.println("Diff in days : " + diffInDays);
283 } catch (IOException e)
287 return noOfDays <= diffInDays;
291 * Download a SIFTs XML file for a given PDB Id from an FTP repository
294 * @return downloaded SIFTs XML file
295 * @throws SiftsException
296 * @throws IOException
298 public static File downloadSiftsFile(String pdbId) throws SiftsException,
301 if (pdbId.contains(".cif"))
303 pdbId = pdbId.replace(".cif", "");
305 String siftFile = pdbId + ".xml.gz";
306 String siftsFileFTPURL = SIFTS_FTP_BASE_URL + siftFile;
307 String downloadedSiftsFile = SiftsSettings.getSiftDownloadDirectory()
309 File siftsDownloadDir = new File(
310 SiftsSettings.getSiftDownloadDirectory());
311 if (!siftsDownloadDir.exists())
313 siftsDownloadDir.mkdirs();
315 // System.out.println(">> Download ftp url : " + siftsFileFTPURL);
316 URL url = new URL(siftsFileFTPURL);
317 URLConnection conn = url.openConnection();
318 InputStream inputStream = conn.getInputStream();
319 FileOutputStream outputStream = new FileOutputStream(
320 downloadedSiftsFile);
321 byte[] buffer = new byte[BUFFER_SIZE];
323 while ((bytesRead = inputStream.read(buffer)) != -1)
325 outputStream.write(buffer, 0, bytesRead);
327 outputStream.close();
329 // System.out.println(">>> File downloaded : " + downloadedSiftsFile);
330 return new File(downloadedSiftsFile);
334 * Delete the SIFTs file for the given PDB Id in the local SIFTs download
338 * @return true if the file was deleted or doesn't exist
340 public static boolean deleteSiftsFileByPDBId(String pdbId)
342 File siftsFile = new File(SiftsSettings.getSiftDownloadDirectory()
343 + pdbId.toLowerCase() + ".xml.gz");
344 if (siftsFile.exists())
346 return siftsFile.delete();
352 * Get a valid SIFTs DBRef for the given sequence current SIFTs entry
355 * - the target sequence for the operation
356 * @return a valid DBRefEntry that is SIFTs compatible
358 * if no valid source DBRefEntry was found for the given sequences
360 public DBRefEntryI getValidSourceDBRef(SequenceI seq)
361 throws SiftsException
363 DBRefEntryI sourceDBRef = null;
364 sourceDBRef = seq.getSourceDBRef();
365 if (sourceDBRef != null && isValidDBRefEntry(sourceDBRef))
371 DBRefEntry[] dbRefs = seq.getDBRefs();
372 if (dbRefs == null || dbRefs.length < 1)
374 throw new SiftsException(
375 "Source DBRef could not be determined. DBRefs might not have been retrieved.");
378 for (DBRefEntryI dbRef : dbRefs)
380 if (dbRef == null || dbRef.getAccessionId() == null
381 || dbRef.getSource() == null)
385 if (isFoundInSiftsEntry(dbRef.getAccessionId())
386 && (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT) || dbRef
387 .getSource().equalsIgnoreCase(DBRefSource.PDB)))
389 seq.setSourceDBRef(dbRef);
394 if (sourceDBRef != null && isValidDBRefEntry(sourceDBRef))
398 throw new SiftsException("Could not get source DB Ref");
402 * Check that the DBRef Entry is properly populated and is available in this
403 * SiftClient instance
406 * - DBRefEntry to validate
407 * @return true validation is successful otherwise false is returned.
409 private boolean isValidDBRefEntry(DBRefEntryI entry)
411 return entry != null && entry.getAccessionId() != null
412 && isFoundInSiftsEntry(entry.getAccessionId());
416 public HashSet<String> getAllMappingAccession()
418 HashSet<String> accessions = new HashSet<String>();
419 List<Entity> entities = siftsEntry.getEntity();
420 for (Entity entity : entities)
422 List<Segment> segments = entity.getSegment();
423 for (Segment segment : segments)
425 List<MapRegion> mapRegions = segment.getListMapRegion()
427 for (MapRegion mapRegion : mapRegions)
430 .add(mapRegion.getDb().getDbAccessionId().toLowerCase());
438 public StructureMapping getSiftsStructureMapping(SequenceI seq,
439 String pdbFile, String chain) throws SiftsException
441 structId = (chain == null) ? pdbId : pdbId + "|" + chain;
442 System.out.println("Getting mapping for: " + pdbId + "|" + chain
443 + " : seq- " + seq.getName());
445 final StringBuilder mappingDetails = new StringBuilder(128);
446 PrintStream ps = new PrintStream(System.out)
449 public void print(String x)
451 mappingDetails.append(x);
455 public void println()
457 mappingDetails.append(NEWLINE);
460 HashMap<Integer, int[]> mapping = getGreedyMapping(chain, seq, ps);
462 String mappingOutput = mappingDetails.toString();
463 StructureMapping siftsMapping = new StructureMapping(seq, pdbFile,
464 pdbId, chain, mapping, mappingOutput);
469 public HashMap<Integer, int[]> getGreedyMapping(String entityId,
470 SequenceI seq, java.io.PrintStream os) throws SiftsException
472 ArrayList<Integer> omitNonObserved = new ArrayList<Integer>();
473 int nonObservedShiftIndex = 0;
474 // System.out.println("Generating mappings for : " + entityId);
475 Entity entity = null;
476 entity = getEntityById(entityId);
477 String originalSeq = AlignSeq.extractGaps(
478 jalview.util.Comparison.GapChars, seq.getSequenceAsString());
479 HashMap<Integer, int[]> mapping = new HashMap<Integer, int[]>();
480 DBRefEntryI sourceDBRef = seq.getSourceDBRef();
481 sourceDBRef = getValidSourceDBRef(seq);
482 // TODO ensure sequence start/end is in the same coordinate system and
483 // consistent with the choosen sourceDBRef
485 // set sequence coordinate system - default value is UniProt
486 if (sourceDBRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
488 seqCoordSys = CoordinateSys.PDB;
491 HashSet<String> dbRefAccessionIdsString = new HashSet<String>();
492 for (DBRefEntry dbref : seq.getDBRefs())
494 dbRefAccessionIdsString.add(dbref.getAccessionId().toLowerCase());
496 dbRefAccessionIdsString.add(sourceDBRef.getAccessionId().toLowerCase());
498 curDBRefAccessionIdsString = dbRefAccessionIdsString;
499 curSourceDBRef = sourceDBRef.getAccessionId();
501 TreeMap<Integer, String> resNumMap = new TreeMap<Integer, String>();
502 List<Segment> segments = entity.getSegment();
503 for (Segment segment : segments)
505 segStartEnd = segment.getStart() + " - " + segment.getEnd();
506 // System.out.println("Mapping segments : " + segment.getSegId() + "\\"
508 List<Residue> residues = segment.getListResidue().getResidue();
509 for (Residue residue : residues)
511 int currSeqIndex = UNASSIGNED;
512 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
513 CrossRefDb pdbRefDb = null;
514 for (CrossRefDb cRefDb : cRefDbs)
516 if (cRefDb.getDbSource().equalsIgnoreCase(DBRefSource.PDB))
520 if (cRefDb.getDbCoordSys()
521 .equalsIgnoreCase(seqCoordSys.getName())
522 && isAccessionMatched(cRefDb.getDbAccessionId()))
524 String resNumIndexString = cRefDb.getDbResNum()
525 .equalsIgnoreCase("None") ? String.valueOf(UNASSIGNED)
526 : cRefDb.getDbResNum();
529 currSeqIndex = Integer.valueOf(resNumIndexString);
530 } catch (NumberFormatException nfe)
532 currSeqIndex = Integer.valueOf(resNumIndexString
533 .split("[a-zA-Z]")[0]);
536 if (pdbRefDb != null)
538 break;// exit loop if pdb and uniprot are already found
542 if (currSeqIndex == UNASSIGNED)
546 if (currSeqIndex >= seq.getStart() && currSeqIndex <= seq.getEnd())
551 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
552 .getDbResNum()) : Integer.valueOf(pdbRefDb
554 } catch (NumberFormatException nfe)
556 resNum = (pdbRefDb == null) ? Integer.valueOf(residue
557 .getDbResNum()) : Integer.valueOf(pdbRefDb
558 .getDbResNum().split("[a-zA-Z]")[0]);
562 if (isResidueObserved(residue)
563 || seqCoordSys == CoordinateSys.UNIPROT)
565 char resCharCode = ResidueProperties
566 .getSingleCharacterCode(ResidueProperties
567 .getCanonicalAminoAcid(residue.getDbResName()));
568 resNumMap.put(currSeqIndex, String.valueOf(resCharCode));
572 omitNonObserved.add(currSeqIndex);
573 ++nonObservedShiftIndex;
575 mapping.put(currSeqIndex - nonObservedShiftIndex, new int[] {
576 Integer.valueOf(resNum), UNASSIGNED });
582 populateAtomPositions(entityId, mapping);
583 } catch (Exception e)
587 if (seqCoordSys == CoordinateSys.UNIPROT)
589 padWithGaps(resNumMap, omitNonObserved);
591 int seqStart = UNASSIGNED;
592 int seqEnd = UNASSIGNED;
593 int pdbStart = UNASSIGNED;
594 int pdbEnd = UNASSIGNED;
596 Integer[] keys = mapping.keySet().toArray(new Integer[0]);
600 throw new SiftsException(">>> Empty SIFTS mapping generated!!");
603 seqEnd = keys[keys.length - 1];
605 String matchedSeq = originalSeq;
606 if (seqStart != UNASSIGNED)
608 pdbStart = mapping.get(seqStart)[PDB_RES_POS];
609 pdbEnd = mapping.get(seqEnd)[PDB_RES_POS];
610 int orignalSeqStart = seq.getStart();
611 if (orignalSeqStart >= 1)
613 int subSeqStart = (seqStart >= orignalSeqStart) ? seqStart
614 - orignalSeqStart : 0;
615 int subSeqEnd = seqEnd - (orignalSeqStart - 1);
616 subSeqEnd = originalSeq.length() < subSeqEnd ? originalSeq.length()
618 matchedSeq = originalSeq.substring(subSeqStart, subSeqEnd);
622 matchedSeq = originalSeq.substring(1, originalSeq.length());
626 StringBuilder targetStrucSeqs = new StringBuilder();
627 for (String res : resNumMap.values())
629 targetStrucSeqs.append(res);
634 MappingOutputPojo mop = new MappingOutputPojo();
635 mop.setSeqStart(pdbStart);
636 mop.setSeqEnd(pdbEnd);
637 mop.setSeqName(seq.getName());
638 mop.setSeqResidue(matchedSeq);
640 mop.setStrStart(seqStart);
641 mop.setStrEnd(seqEnd);
642 mop.setStrName(structId);
643 mop.setStrResidue(targetStrucSeqs.toString());
646 os.print(getMappingOutput(mop).toString());
654 * Target chain to populate mapping of its atom positions.
656 * Two dimension array of residue index versus atom position
657 * @throws IllegalArgumentException
658 * Thrown if chainId or mapping is null
660 void populateAtomPositions(String chainId,
661 HashMap<Integer, int[]> mapping) throws IllegalArgumentException
665 PDBChain chain = pdb.findChain(chainId);
667 if (chain == null || mapping == null)
669 throw new IllegalArgumentException(
670 "Chain id or mapping must not be null.");
672 for (int[] map : mapping.values())
674 if (map[PDB_RES_POS] != UNASSIGNED)
676 map[PDB_ATOM_POS] = getAtomIndex(map[PDB_RES_POS], chain.atoms);
679 } catch (Exception e)
687 * @param residueIndex
688 * The residue index used for the search
690 * A collection of Atom to search
691 * @return atom position for the given residue index
693 int getAtomIndex(int residueIndex, Collection<Atom> atoms)
697 throw new IllegalArgumentException(
698 "atoms collection must not be null!");
700 for (Atom atom : atoms)
702 if (atom.resNumber == residueIndex)
704 return atom.atomIndex;
711 * Checks if the residue instance is marked 'Not_observed' or not
716 private boolean isResidueObserved(Residue residue)
718 HashSet<String> annotations = getResidueAnnotaitons(residue,
719 ResidueDetailType.ANNOTATION);
720 if (annotations == null || annotations.isEmpty())
724 for (String annotation : annotations)
726 if (annotation.equalsIgnoreCase(NOT_OBSERVED))
735 * Get annotation String for a given residue and annotation type
741 private HashSet<String> getResidueAnnotaitons(Residue residue,
742 ResidueDetailType type)
744 HashSet<String> foundAnnotations = new HashSet<String>();
745 List<ResidueDetail> resDetails = residue.getResidueDetail();
746 for (ResidueDetail resDetail : resDetails)
748 if (resDetail.getProperty().equalsIgnoreCase(type.getCode()))
750 foundAnnotations.add(resDetail.getContent());
753 return foundAnnotations;
757 public boolean isAccessionMatched(String accession)
759 boolean isStrictMatch = true;
760 return isStrictMatch ? curSourceDBRef.equalsIgnoreCase(accession)
761 : curDBRefAccessionIdsString.contains(accession.toLowerCase());
764 private boolean isFoundInSiftsEntry(String accessionId)
766 HashSet<String> siftsDBRefs = getAllMappingAccession();
767 return accessionId != null
768 && siftsDBRefs.contains(accessionId.toLowerCase());
772 * Pad omitted residue positions in PDB sequence with gaps
776 void padWithGaps(TreeMap<Integer, String> resNumMap,
777 ArrayList<Integer> omitNonObserved)
779 if (resNumMap == null || resNumMap.isEmpty())
783 Integer[] keys = resNumMap.keySet().toArray(new Integer[0]);
785 int firstIndex = keys[0];
786 int lastIndex = keys[keys.length - 1];
787 // System.out.println("Min value " + firstIndex);
788 // System.out.println("Max value " + lastIndex);
789 for (int x = firstIndex; x <= lastIndex; x++)
791 if (!resNumMap.containsKey(x) && !omitNonObserved.contains(x))
793 resNumMap.put(x, "-");
801 public Entity getEntityById(String id) throws SiftsException
803 // Sometimes SIFTS mappings are wrongly swapped between different chains of
804 // a PDB entry. This results to wrong mappings being generated. The boolean
805 // flag 'isGetEntityIdDirectly, determines whether an entity to process is
806 // determined by a greedy heuristic search or by just matching the Chain Id
807 // directly against the entity Id tag. Setting the default value to 'false'
808 // utilise the heuristic search which always produces correct mappings but
809 // less optimised processing, where as changing the value to 'true'
810 // optimises performance but might result to incorrect mapping in some cases
811 // where SIFTS mappings are wrongly swapped between different chains.
812 boolean isGetEntityIdDirectly = false;
813 if (isGetEntityIdDirectly)
815 List<Entity> entities = siftsEntry.getEntity();
816 for (Entity entity : entities)
818 if (!entity.getEntityId().equalsIgnoreCase(id))
825 Entity entity = getEntityByMostOptimalMatchedId(id);
830 throw new SiftsException("Entity " + id + " not found");
834 * This method was added because EntityId is NOT always equal to ChainId.
835 * Hence, it provides the logic to greedily detect the "true" Entity for a
836 * given chainId where discrepancies exist.
841 public Entity getEntityByMostOptimalMatchedId(String chainId)
843 // System.out.println("---> advanced greedy entityId matching block entered..");
844 List<Entity> entities = siftsEntry.getEntity();
845 SiftsEntitySortPojo[] sPojo = new SiftsEntitySortPojo[entities.size()];
847 for (Entity entity : entities)
849 sPojo[count] = new SiftsEntitySortPojo();
850 sPojo[count].entityId = entity.getEntityId();
852 List<Segment> segments = entity.getSegment();
853 for (Segment segment : segments)
855 List<Residue> residues = segment.getListResidue().getResidue();
856 for (Residue residue : residues)
858 List<CrossRefDb> cRefDbs = residue.getCrossRefDb();
859 for (CrossRefDb cRefDb : cRefDbs)
861 if (!cRefDb.getDbSource().equalsIgnoreCase("PDB"))
865 ++sPojo[count].resCount;
866 if (cRefDb.getDbChainId().equalsIgnoreCase(chainId))
868 ++sPojo[count].chainIdFreq;
873 sPojo[count].pid = 100 * (sPojo[count].chainIdFreq / sPojo[count].resCount);
876 Arrays.sort(sPojo, Collections.reverseOrder());
877 // System.out.println("highest matched entity : " + sPojo[0].entityId);
878 // System.out.println("highest matched pid : " + sPojo[0].pid);
880 if (sPojo[0].entityId != null)
882 for (Entity entity : entities)
884 if (!entity.getEntityId().equalsIgnoreCase(sPojo[0].entityId))
894 public class SiftsEntitySortPojo implements
895 Comparable<SiftsEntitySortPojo>
897 public String entityId;
899 public int chainIdFreq;
906 public int compareTo(SiftsEntitySortPojo o)
908 return this.pid - o.pid;
913 public String[] getEntryDBs()
915 System.out.println("\nListing DB entries...");
916 List<String> availDbs = new ArrayList<String>();
917 List<Db> dbs = siftsEntry.getListDB().getDb();
920 availDbs.add(db.getDbSource());
921 System.out.println(db.getDbSource() + " | " + db.getDbCoordSys());
923 return availDbs.toArray(new String[0]);
927 public StringBuffer getMappingOutput(MappingOutputPojo mp)
928 throws SiftsException
930 String seqRes = mp.getSeqResidue();
931 String seqName = mp.getSeqName();
932 int sStart = mp.getSeqStart();
933 int sEnd = mp.getSeqEnd();
935 String strRes = mp.getStrResidue();
936 String strName = mp.getStrName();
937 int pdbStart = mp.getStrStart();
938 int pdbEnd = mp.getStrEnd();
940 String type = mp.getType();
942 int maxid = (seqName.length() >= strName.length()) ? seqName.length()
944 int len = 72 - maxid - 1;
946 int nochunks = ((seqRes.length()) / len)
947 + ((seqRes.length()) % len > 0 ? 1 : 0);
949 StringBuffer output = new StringBuffer();
950 output.append(NEWLINE);
951 output.append("Sequence \u27f7 Structure mapping details").append(
953 output.append("Method: SIFTS");
954 output.append(NEWLINE).append(NEWLINE);
956 output.append(new Format("%" + maxid + "s").form(seqName));
957 output.append(" : ");
958 output.append(String.valueOf(sStart));
959 output.append(" - ");
960 output.append(String.valueOf(sEnd));
961 output.append(" Maps to ");
962 output.append(NEWLINE);
963 output.append(new Format("%" + maxid + "s").form(structId));
964 output.append(" : ");
965 output.append(String.valueOf(pdbStart));
966 output.append(" - ");
967 output.append(String.valueOf(pdbEnd));
968 output.append(NEWLINE).append(NEWLINE);
970 int matchedSeqCount = 0;
971 for (int j = 0; j < nochunks; j++)
973 // Print the first aligned sequence
974 output.append(new Format("%" + (maxid) + "s").form(seqName)).append(
977 for (int i = 0; i < len; i++)
979 if ((i + (j * len)) < seqRes.length())
981 output.append(seqRes.charAt(i + (j * len)));
985 output.append(NEWLINE);
986 output.append(new Format("%" + (maxid) + "s").form(" ")).append(" ");
988 // Print out the matching chars
989 for (int i = 0; i < len; i++)
993 if ((i + (j * len)) < seqRes.length())
995 if (seqRes.charAt(i + (j * len)) == strRes
996 .charAt(i + (j * len))
997 && !jalview.util.Comparison.isGap(seqRes.charAt(i
1003 else if (type.equals("pep"))
1005 if (ResidueProperties.getPAM250(seqRes.charAt(i + (j * len)),
1006 strRes.charAt(i + (j * len))) > 0)
1020 } catch (IndexOutOfBoundsException e)
1025 // Now print the second aligned sequence
1026 output = output.append(NEWLINE);
1027 output = output.append(new Format("%" + (maxid) + "s").form(strName))
1029 for (int i = 0; i < len; i++)
1031 if ((i + (j * len)) < strRes.length())
1033 output.append(strRes.charAt(i + (j * len)));
1036 output.append(NEWLINE).append(NEWLINE);
1038 float pid = (float) matchedSeqCount / seqRes.length() * 100;
1039 if (pid < SiftsSettings.getFailSafePIDThreshold())
1041 throw new SiftsException(">>> Low PID detected for SIFTs mapping...");
1043 output.append("Length of alignment = " + seqRes.length()).append(
1045 output.append(new Format("Percentage ID = %2.2f").form(pid));
1046 output.append(NEWLINE);
1051 public int getEntityCount()
1053 return siftsEntry.getEntity().size();
1057 public String getDbAccessionId()
1059 return siftsEntry.getDbAccessionId();
1063 public String getDbCoordSys()
1065 return siftsEntry.getDbCoordSys();
1069 public String getDbEvidence()
1071 return siftsEntry.getDbEvidence();
1075 public String getDbSource()
1077 return siftsEntry.getDbSource();
1081 public String getDbVersion()
1083 return siftsEntry.getDbVersion();