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.structure;
23 import java.util.ArrayList;
24 import java.util.HashSet;
25 import java.util.List;
27 import java.util.regex.Matcher;
28 import java.util.regex.Pattern;
30 import jalview.datamodel.PDBEntry;
31 import jalview.datamodel.SequenceI;
32 import jalview.io.StructureFile;
33 import mc_view.PDBChain;
35 public class PDBEntryUtils
38 public static String inferChainId(SequenceI seq)
41 if (seq.getName().indexOf("|") > -1)
43 targetChainId = seq.getName()
44 .substring(seq.getName().lastIndexOf("|") + 1);
45 if (targetChainId.length() > 1)
47 if (targetChainId.trim().length() == 0)
53 // not a valid chain identifier
64 protected static Pattern id_and_chain=Pattern.compile("(\\d[0-9A-Za-z]{3})[_:|]?([0-9A-Za-z]{1,2})?.*");
66 public static List<PDBEntry> inferPDBEntry(SequenceI seq)
68 Matcher matcher = id_and_chain.matcher(seq.getName());
70 if (matcher.matches())
72 String id = matcher.group(1);
73 PDBEntry pdbe = new PDBEntry();
75 if (matcher.groupCount() > 1)
77 pdbe.setChainCode(matcher.group(2));
87 * generate likely PDB IDs & chain codes from seq and ds that fit pdb
91 * @return empty list or one or more PDBEntry which match pdb.getId()
93 public static List<PDBEntry> selectPutativePDBe(SequenceI seq,
94 SequenceI ds, StructureFile pdb)
96 List<PDBEntry> putativePDBe = new ArrayList<PDBEntry>();
97 Set<PDBEntry> possiblePDBe=PDBEntryUtils.gatherPDBEntries(seq,true);
98 for (PDBEntry infPDBe: possiblePDBe)
100 if (infPDBe.getId().equalsIgnoreCase(pdb.getId()))
102 putativePDBe.add(infPDBe);
109 public static Set<PDBEntry> gatherPDBEntries(SequenceI seq,boolean inferFromName)
111 Set<PDBEntry> possiblePDBe=new HashSet<PDBEntry>();
114 if (seq.getAllPDBEntries()!=null) {
115 possiblePDBe.addAll(seq.getAllPDBEntries());
119 possiblePDBe.addAll(PDBEntryUtils.inferPDBEntry(seq));
121 seq = seq.getDatasetSequence();
127 public static PDBEntry selectPutativePDBEntry(List<PDBEntry> putativePDBe,
130 if (putativePDBe.isEmpty())
135 // check if there's a chaincode
136 PDBEntry putativeEntry = null;
137 boolean hasChainCodes;
138 // check for a chaincode mapping
139 for (PDBEntry pdbe : putativePDBe)
141 if (pdbe.getChainCode() != null)
143 hasChainCodes = true;
144 if (pdbe.getChainCode().equals(chain.id))
146 putativeEntry = pdbe;
147 return putativeEntry;