/* FeatureLocLazyQualifierValue * * created: 2007 * * This file is part of Artemis * * Copyright (C) 2007 Genome Research Limited * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ package uk.ac.sanger.artemis.chado; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Hashtable; import java.util.Iterator; import java.util.List; import java.util.Vector; import org.gmod.schema.analysis.AnalysisFeature; import org.gmod.schema.general.DbXRef; import org.gmod.schema.sequence.FeatureDbXRef; import org.gmod.schema.sequence.FeatureLoc; import org.gmod.schema.sequence.FeatureProp; import org.gmod.schema.sequence.Feature; import uk.ac.sanger.artemis.io.LazyQualifierValue; import uk.ac.sanger.artemis.util.DatabaseDocument; public class FeatureLocLazyQualifierValue implements LazyQualifierValue { /** match feature associated with the similarity */ private Feature matchFeature; /** feature_id of the query feature */ private int featureId; /** force complete loading of the data */ private boolean forceLoad = false; /** data loaded */ private boolean lazyLoaded = false; /** * Qualifier object to handle lazy loading of properties that * are featureloc'ed to the feature being read in. e.g. similarity, * polypeptide_domain, protein predictions (TMHMM, signal_peptide). * @param matchFeature * @param featureId */ public FeatureLocLazyQualifierValue(final Feature matchFeature, final int featureId) { this.matchFeature = matchFeature; this.featureId = featureId; } /** * Bulk retrieval of lazy properties (used to speed up writing to files) * @param similarity a List of Similarity qualifier values * @param doc the Document to which these features belong */ public static void bulkRetrieve(final List similarity, final DatabaseDocument doc) { final Iterator it = similarity.iterator(); final Hashtable featureLocHash = new Hashtable(similarity.size()*2); final Hashtable matchFeatures = new Hashtable(similarity.size()); while(it.hasNext()) { FeatureLocLazyQualifierValue thisSimilarity = (FeatureLocLazyQualifierValue)it.next(); Feature thisMatchFeature = thisSimilarity.getMatchFeature(); Collection featureLocs = thisMatchFeature.getFeatureLocsForFeatureId(); Iterator it2 = featureLocs.iterator(); while(it2.hasNext()) { org.gmod.schema.sequence.FeatureLoc featureLoc = (org.gmod.schema.sequence.FeatureLoc)it2.next(); if(featureLoc.getSrcFeatureId() <= 0) continue; final Integer srcFeatureId = new Integer(featureLoc.getSrcFeatureId()); List locs; if(featureLocHash.containsKey(srcFeatureId)) locs = (Vector)featureLocHash.get(srcFeatureId); else locs = new Vector(); locs.add(featureLoc); featureLocHash.put(srcFeatureId, locs); } matchFeatures.put(new Integer(thisMatchFeature.getFeatureId()), thisMatchFeature); } final List queryAndSubjectFeatureIds = new Vector(featureLocHash.keySet()); // // bulk load the subject and query features // final List sims = doc.getFeaturesByListOfIds(queryAndSubjectFeatureIds); for(int i=0; i 0) { final StringBuffer buffDbXRefs = new StringBuffer(); Iterator it4 = dbXRefs.iterator(); while(it4.hasNext()) { FeatureDbXRef featureDbXRef = (FeatureDbXRef) it4.next(); featureDbXRef.getDbXRef(); try { buffDbXRefs.append(featureDbXRef.getDbXRef().getDb().getName() + ":"); buffDbXRefs.append(featureDbXRef.getDbXRef().getAccession()); if(it4.hasNext()) buffDbXRefs.append(","); } catch(NullPointerException npe){} } if(buffDbXRefs.length() > 0) { buff.append(" ("); buff.append(buffDbXRefs); buff.append(")"); } } buff.append(";"); List featureProps = new Vector(subject.getFeatureProps()); Collections.sort(featureProps, new FeaturePropComparator()); for(int i = 0; i < featureProps.size(); i++) { FeatureProp featureProp = (FeatureProp) featureProps.get(i); if(featureProp.getValue() != null) buff.append(featureProp.getValue().trim()); buff.append(";"); } buff.append("length " + subject.getSeqLen()); } if(matchFeature.getCvTerm().getName().equals("protein_match")) buff.append(" aa; "); else buff.append(";"); if(analysisFeature != null && analysisFeature.getIdentity() != null) buff.append("id="+analysisFeature.getIdentity()+"%;"); if(analysisFeature != null && analysisFeature.getSignificance() != null) buff.append("E()="+analysisFeature.getSignificance()+";"); if(analysisFeature != null && analysisFeature.getRawScore() != null) buff.append("score="+analysisFeature.getRawScore()+";"); if(queryLoc != null && queryLoc.getFmin().intValue() > -1) { final int fmin; if(queryLoc.getFmin().compareTo(queryLoc.getFmax()) == 0) fmin = queryLoc.getFmin().intValue(); else fmin = queryLoc.getFmin().intValue()+1; buff.append("query "+fmin+"-"+queryLoc.getFmax()); if(matchFeature.getCvTerm().getName().equals("protein_match")) buff.append(" aa;"); else buff.append(";"); } if(subjectLoc != null && subjectLoc.getFmin().intValue() > -1) { int fmin = subjectLoc.getFmin().intValue()+1; buff.append("subject "+fmin+"-"+subjectLoc.getFmax()); if(matchFeature.getCvTerm().getName().equals("protein_match")) buff.append(" aa;"); else buff.append(";"); } if(matchFeature.getFeatureProps() != null) { List featureProps = new Vector(matchFeature.getFeatureProps()); Collections.sort(featureProps, new FeaturePropComparator()); for(int i=0; i