6 package uk.ac.ebi.msd.vamsas.vamav.documentmanagement.grouping;
8 import uk.ac.ebi.msd.vamsas.vamav.documentmanagement.PDBUtil;
9 import uk.ac.ebi.msd.vamsas.vamav.documentmanagement.grouping.exceptions.UnableToGroupSequencesException;
10 import uk.ac.ebi.msd.vamsas.vamav.exceptions.IncorrectVamavModuleInitialisation;
11 import uk.ac.ebi.msd.vamsas.vamav.session.VAMAVSession;
12 import uk.ac.ebi.msd.vamsas.vamav.util.data.PDBEntry;
13 import uk.ac.ebi.msd.vamsas.vamav.util.mapping.MappingManager;
14 import uk.ac.ebi.msd.vamsas.vamav.util.pool.StringBufferPool;
18 import java.util.ArrayList;
19 import java.util.Hashtable;
20 import java.util.Properties;
23 *Group sequences per structure
25 * First, add sequences, with DB ref is provided ( addSequence methods)
27 *storeGroup Method (To create atribute file and alignment files)
29 *Each time a sequence is added, it is added to the determined grou.
31 *@author <a href="mailto:pierre@ebi.ac.uk">Pierre MARGUERITE</a>
33 public class SequenceGrouping_structure extends SequenceGrouping //implements uk.ac.ebi.msd.vamsas.vamav.VamaVModule{
37 //private final VAMAVLogger logger = new VAMAVLoggerImpl(this.getClass());
38 protected VAMAVSession vamavSession = null;
43 * Constructor of the SequenceGrouping class, given a mapping manager
45 * @param _mappingManager the mapping manager to use for mapping
47 public SequenceGrouping_structure( MappingManager _mappingManager)
49 super(_mappingManager);
54 * Constructor of the SequenceGrouping class, given a mapping manager
56 * @param _mappingManager the mapping manager to use for mapping
57 * @param sessionID current session for which will be used the current sequence grouping.
59 public SequenceGrouping_structure(MappingManager _mappingManager, VAMAVSession session )
61 super(_mappingManager);
62 this.logger.setSession(session.getSessionID());
63 this.vamavSession = session;
67 * Inits the Sequence Grouping sub module, with a list of configuration properties.
69 public void init (Properties moduleProperties) throws IncorrectVamavModuleInitialisation
71 super.init(moduleProperties);
75 * Add a sequence for grouping.
77 * @param sequence chain sequence to add
78 * @param name name of the sequence to add
79 * @return a list of parameters to call the AstexViewer
80 * @throws UnableToGroupSequencesException if an error occurs during the adding.
82 public Hashtable<String, Object> addSequence(String sequence, String name) throws UnableToGroupSequencesException
84 if( sequence == null || sequence.length()<1)
86 this.logger.sessionWarn("SequenceGrouping addSequence - no Sequence Provided. Can not add.");
89 if( name == null || name.length()<1)
91 this.logger.sessionWarn("SequenceGrouping addSequence - no name Provided. Can not add.");
94 ArrayList<PDBEntry> entries = null;
97 entries = this.getMapping().retrievePDBIDFromSequence(sequence);
99 catch (IncorrectVamavModuleInitialisation inE)
101 this.logger.sessionError("Sequence Grouping addSequence - error during mapping execution. Can not proceed.", inE);
102 throw new UnableToGroupSequencesException();
104 Hashtable<String, Object> parameters = null;
105 if (entries == null ) return null;
106 StringBuffer pdbIDs = StringBufferPool.getString();
107 for (int entryNumber = entries.size() -1; entryNumber>=0; entryNumber--)
109 PDBEntry entry = entries.get(entryNumber);
110 if (entry == null) continue;
112 parameters = new Hashtable<String, Object>();
114 if( !parameters.containsValue(entry))
116 parameters.put("moleculeG"+molNumber,entry);
117 parameters.put("nameG"+molNumber, entry.getPdbID());
118 this.logger.sessionDebug("New molecule added "+entry);
122 PDBUtil util = new PDBUtil(this.vamavSession);
124 ArrayList<PDBUtil.Chain> chains = util.GetChain(entry);
128 /*System.out.println(" chains found ");*/
129 for (int chainN = chains.size()-1; chainN>=0; chainN --)
131 PDBUtil.Chain chain =chains.get(chainN);
132 if (chain == null)continue;
133 /*System.out.println("chain "+chain.getName()+ " "+chain.getSequence());*/
134 String groupName = chain.getName();
135 int pos = groupName.indexOf("_");
136 if( pos>0) groupName = groupName.substring(0,pos);
137 this.addSequenceToGroup(groupName,chain.getSequence(),chain.getName());
138 this.addStructureToGroup(groupName, entry.getPdbID());
142 this.logger.sessionWarn("no chains found ");
143 String id = entry.getPdbID();
144 this.addSequenceToGroup(id, sequence, name);
145 if(pdbIDs.length()<1) pdbIDs.append(id);
146 else pdbIDs.append(", "+id);
148 parameters.put(this.pdbidsproperty,pdbIDs.toString());
149 StringBufferPool.returnString(pdbIDs);
154 * Add a sequence for grouping, with an associated accessionID and its source.
156 * @param sequence chain sequence to add for grouping
157 * @param name name of the sequence to add
158 * @param accessionID accessionId associated to the sequence
159 * @param source source of the accessionID
160 * @return list of parameters to call the AstexViewer, if needed. Null, otherwise.
161 * @throws UnableToGroupSequencesException if an error occurs during the adding.
163 public Hashtable<String, Object> addSequence(String sequence, String name, String accessionID, String source) throws UnableToGroupSequencesException
166 if( sequence == null || sequence.length()<1)
168 this.logger.sessionError("SequenceGrouping - addSequence: Can not add sequence / The sequence is unknown.");
171 if( name == null || name.length()<1)
173 this.logger.sessionError("SequenceGrouping - addSequence: Can not add sequence / The name is unknown.");
176 if( source == null || source.length()<1)
178 this.logger.sessionWarn("SequenceGrouping - addSequence: the accession ID source is not provided / try to determine PDBID from the sequence.");
179 return this.addSequence(sequence, name);
181 if( accessionID == null || accessionID.length()<1)
183 this.logger.sessionWarn("SequenceGrouping - addSequence: the accession ID is not provided / try to determine PDBID from the sequence.");
184 return this.addSequence(sequence, name);
186 Hashtable<String, Object> parameters = null;
189 ArrayList <PDBEntry> entries = null;
191 if("PDB".equals(source))
193 PDBEntry entry = this.getMapping().getPDBEntryFromPDBID(accessionID);
196 entries = new ArrayList<PDBEntry>(1);
200 if ("UNIPROT".equalsIgnoreCase(source))
202 entries = this.getMapping().retrievePDBIDFromUniprotAC(accessionID);
204 if( entries == null || entries.size()<1)
206 this.logger.sessionError("No associated PDB ID to the accessionAC "+ accessionID + " from "+source);
207 return this.addSequence(sequence, name);
209 //boolean notFound = false;
210 //hasAlignmentSequences = true;
211 parameters = new Hashtable<String, Object>();
213 //currenty only use the first entry
214 //for ( int entryNumber = entries.size()-1; entryNumber>=0; entryNumber --)
217 StringBuffer pdbIDs = null;
218 if (entries != null || entries.size()<1)
220 PDBUtil util = new PDBUtil(this.vamavSession);
221 for (int entryNumber = entries.size() -1; entryNumber >=0; entryNumber --)
223 PDBEntry entry = entries.get(entryNumber);
224 parameters.put("moleculeG"+molNumber,entry);
225 parameters.put("nameG"+molNumber, entry.getPdbID());
227 ArrayList<PDBUtil.Chain> chains = util.GetChain(entry);
231 this.logger.sessionDebug(" chains found ");
232 // StringBuffer buff = StringBufferPool.getString();
233 for (int chainN = chains.size()-1; chainN>=0; chainN --)
235 PDBUtil.Chain chain = chains.get(chainN);
236 if (chain == null)continue;
237 String groupName = chain.getName();
238 int pos = groupName.indexOf("_");
239 if( pos>0) groupName = groupName.substring(0,pos);
240 this.addSequenceToGroup(groupName, chain.getSequence(),chain.getName());
241 this.addStructureToGroup(groupName, entry.getPdbID());
246 this.logger.sessionDebug("no chains found ");
248 this.addSequenceToGroup(entry.getPdbID(), sequence, name);
249 if( pdbIDs == null) pdbIDs = StringBufferPool.getString();
250 if(pdbIDs.length()>0)pdbIDs.append(", "+entry.getPdbID());
251 else pdbIDs.append(entry.getPdbID());
252 entries.remove(entry);
255 if(!"PDB".equals(source))parameters.put(this.pdbidsproperty,pdbIDs.toString());
256 StringBufferPool.returnString(pdbIDs);
260 /*catch (IncorrectVamavModuleInitialisation inE)
262 logger.AppliError("Sequence Grouping addSequence - error during mapping execution. Can not proceed.", inE);
263 throw new UnableToGroupSequencesException();
266 catch (Exception inE)
268 this.logger.sessionError("Sequence Grouping addSequence - error during mapping execution. Can not proceed.", inE);
269 throw new UnableToGroupSequencesException();
275 * Retrieves the directory to store files in.
276 * @return the output directory for created file by the sequence grouping processing.
278 public String getOutputDirectory()
280 File sessionDir = this.vamavSession.getSessionDirectory();
281 if( sessionDir != null)
282 return sessionDir.getAbsolutePath();
283 return null; //should not happen, has directory file is attached during object creation.
287 * Retrieves current sessionID
288 * @see uk.ac.ebi.msd.vamsas.vamav.documentmanagement.grouping.SequenceGrouping#getSessionID()
291 public String getSessionID()
294 return this.vamavSession.getSessionID();