001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021package org.biojava.nbio.structure.symmetry.misc;
022
023import org.biojava.nbio.structure.symmetry.utils.BlastClustReader;
024
025import java.util.*;
026import java.util.Map.Entry;
027
028public class ProteinComplexSignature {
029        private BlastClustReader blastClust = null;
030        private String pdbId = "";
031        private List<String> chainIds = null;
032        private List<ChainSignature> chainSignatures = new ArrayList<ChainSignature>();
033
034
035        public ProteinComplexSignature(String pdbId, List<String> chainIds, BlastClustReader blastClust) {
036                this.pdbId = pdbId;
037                this.chainIds = chainIds;
038                this.blastClust = blastClust;
039
040                getChainSignatures();
041        }
042
043        public String getComplexSignature() {
044                StringBuilder builder = new StringBuilder();
045                for (ChainSignature s: chainSignatures) {
046                        builder.append(s.toString());
047                }
048                return builder.toString();
049        }
050
051        public String getCompositionId(String chainId) {
052                for (ChainSignature s: chainSignatures) {
053                        if (s.getChainIds().contains(chainId)) {
054                                return s.getCompositionId();
055                        }
056                }
057                return "";
058        }
059
060        public String getComplexStoichiometry() {
061                StringBuilder s = new StringBuilder();
062                for (ChainSignature c: chainSignatures) {
063                        s.append(c.getCompositionId());
064                        if (c.getChainIds().size() >1) {
065                                s.append(c.getChainIds().size());
066                        }
067                }
068                return s.toString();
069        }
070
071        public int getSubunitTypeCount() {
072                return chainSignatures.size();
073        }
074
075        private List<ChainSignature> getChainSignatures() {
076                String alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
077
078                Map<String,Integer> mapCounts = new TreeMap<String,Integer>();
079                Map<String,List<String>> mapChainIds = new TreeMap<String, List<String>>();
080
081                for (String chainId: chainIds) {
082                        String rep = blastClust.getRepresentativeChain(pdbId, chainId);
083                        Integer value = mapCounts.get(rep);
084                        if (value == null) {
085                                mapCounts.put(rep, 1);
086                                List<String> list = new ArrayList<String>();
087                                list.add(chainId);
088                                mapChainIds.put(rep, list);
089                        } else {
090                                value+=1;
091                                mapCounts.put(rep, value);
092                                List<String> list = mapChainIds.get(rep);
093                                list.add(chainId);
094                        }
095                }
096
097
098                for (Entry<String, Integer> entry: mapCounts.entrySet()) {
099                        List<String> chainIds = mapChainIds.get(entry.getKey());
100                        ChainSignature chainSignature = new ChainSignature(entry.getKey(), entry.getValue(), chainIds);
101                        chainSignatures.add(chainSignature);
102                }
103
104                Collections.sort(chainSignatures);
105                for (int i = 0; i < chainSignatures.size(); i++) {
106                        ChainSignature c = chainSignatures.get(i);
107                        if (i < alpha.length()) {
108                                c.setCompositionId(alpha.substring(i,i+1));
109                        } else {
110                                c.setCompositionId("?");
111                        }
112                }
113
114                return chainSignatures;
115        }
116
117}