Changeset 3764
Legend:
- Unmodified
- Added
- Removed
-
trunk/client/servlet/src/org/proteios/action/feature/CreateFeatureHitMatchJob.java
r3445 r3764 28 28 package org.proteios.action.feature; 29 29 30 import org.proteios.Context;31 import org.proteios.ContextEnabled;32 import org.proteios.TableToolbarContext;33 30 import org.proteios.action.ProteiosAction; 34 31 import org.proteios.action.job.ListJobs; 32 import org.proteios.core.BooleanParameterType; 35 33 import org.proteios.core.DbControl; 36 import org.proteios.core.F eature;34 import org.proteios.core.FloatParameterType; 37 35 import org.proteios.core.ItemFactory; 38 36 import org.proteios.core.ItemParameterType; … … 43 41 import se.lu.thep.waf.ActionException; 44 42 import se.lu.thep.waf.constraints.InvalidParameterValue; 45 46 import java.util.ArrayList; 47 import java.util.List; 43 import se.lu.thep.waf.constraints.VBoolean; 44 import se.lu.thep.waf.constraints.VFloat; 48 45 49 46 /** … … 52 49 public class CreateFeatureHitMatchJob 53 50 extends ProteiosAction<CreateFeatureHitMatchJob> 54 implements ContextEnabled55 51 { 52 53 public static final VFloat VTOLERANCE = new VFloat("tol", true); 54 public static final VFloat VSTARTTOL = new VFloat("starttol", true); 55 public static final VFloat VENDTOL = new VFloat("endtol", true); 56 public static final VBoolean VSECONDARY = new VBoolean("isSecondary", false); 57 56 58 /* 57 59 * (non-Javadoc) … … 69 71 Project project = isProjectActive(dc); 70 72 ItemFactory factory = getItemFactory(dc); 73 Float tolerance = getValidFloat(VTOLERANCE); 74 Float startTimeTol = getValidFloat(VSTARTTOL); 75 Float endTimeTol = getValidFloat(VENDTOL); 76 Boolean isSecondary = getValidBoolean(VSECONDARY); 77 if (isSecondary == null) 78 isSecondary = new Boolean(false); 71 79 /*********************************************************************** 72 80 * Create jobs … … 96 104 job.setParameterValue("project", projectParam, project); 97 105 // File parameters 106 job.setParameterValue("tolerance", new FloatParameterType(), tolerance); 107 job.setParameterValue("endTimeTol", new FloatParameterType(), endTimeTol); 108 job.setParameterValue("startTimeTol", new FloatParameterType(), startTimeTol); 109 job.setParameterValue("secondary", new BooleanParameterType(), 110 isSecondary); 98 111 job.setName("Match features and hits"); 99 job.setDescription("Matching in project " + project);112 job.setDescription("Matching in project:" + project+ ", tolerance:"+tolerance + ", secondary:"+isSecondary); 100 113 dc.saveItem(job); 101 114 dc.commit(); … … 107 120 } 108 121 109 private static List<Context> contexts = new ArrayList<Context>(1);110 static111 {112 TableToolbarContext btn = new TableToolbarContext("match",113 "MatchFeaturesHits", CreateFeatureHitMatchJob.class, Feature.class);114 contexts.add(btn);115 }116 122 117 118 public List<Context> listContexts()119 {120 return contexts;121 }122 123 } -
trunk/plugin/src/org/proteios/plugins/FeatureHitMatcher.java
r3694 r3764 115 115 int count = 0; 116 116 DbControl dc = sc.newDbControl(); 117 tolerance = ((Float) job.getValue("tolerance")).doubleValue(); 118 endTimeTol = ((Float) job.getValue("endTimeTol")).doubleValue(); 119 startTimeTol = ((Float) job.getValue("startTimeTol")).doubleValue(); 117 120 Project project = (Project) job.getValue("project"); 121 boolean matchRelated = ((Boolean) job.getValue("secondary")) 122 .booleanValue(); 118 123 /* Check that the feature file hasn't been imported already */ 119 124 QueryFactory qf = new QueryFactory(); … … 130 135 .property("msFile"), Hql.entity(currentMsFile))); 131 136 log.debug("Matching for file:" + currentMsFile); 132 List<Hit> hits = retrieveHits(currentMsFile, project, dc); 137 List<Hit> hits = retrieveHits(currentMsFile, project, dc, 138 matchRelated); 133 139 List<Feature> features = featureQuery.list(dc); 134 for (Feature f : features) 135 { 136 List<Hit> potential = new ArrayList<Hit>(); 137 for (Hit h : hits) 138 { 139 double hitMz = h.getExperimentalMassInDaltons() / h 140 .getCharge() + MONOISOTOPIC_PROTON_MASS; 141 if ((Math.abs(f.getMassToChargeRatio() - hitMz) < tolerance) && h 142 .getCharge().equals(f.getChargeState())) 143 { 144 log.debug("m/z matching:" + f 145 .getMassToChargeRatio() + " hit:" + hitMz); 146 if (h.getRetentionTimeInMinutes() >= f 147 .getStartRetentionTimeInMinutes() && h 148 .getRetentionTimeInMinutes() <= f 149 .getEndRetentionTimeInMinutes()) 150 { 151 /* A match! */ 152 log 153 .debug("Matched hit RT:" + h 154 .getRetentionTimeInMinutes() + " with feature RT:" + f 155 .getApexRetentionTimeInMinutes()); 156 count++; 157 dc.reattachItem(f); 158 dc.reattachItem(h); 159 if (f.getPeptideSequence() == null) 160 { 161 if (h.getFeature() == null || (h 162 .getPrecursorQuantity() < f 163 .getApexIntensity())) 164 { 165 h.setPrecursorQuantity(f 166 .getApexIntensity()); 167 } 168 f 169 .setPeptideSequence(h 170 .getDescription()); 171 f.addHit(h); 172 } 173 else 174 { 175 /* TODO chose the best match instead */ 176 /* 177 * Use the feature with the highest 178 * intensity 179 */ 180 if (h.getPrecursorQuantity() == null || (h 181 .getPrecursorQuantity() < f 182 .getApexIntensity())) 183 { 184 h.setPrecursorQuantity(f 185 .getApexIntensity()); 186 } 187 f.addHit(h); 188 } 189 } 190 // Check for potential matches just outside the 191 // feature 192 else if ((f.getStartRetentionTimeInMinutes() - h 193 .getRetentionTimeInMinutes()) < startTimeTol || (h 194 .getRetentionTimeInMinutes() - f 195 .getEndRetentionTimeInMinutes()) < endTimeTol) 196 { 197 if (h.getFeature() == null || h 198 .getDescription().equals( 199 f.getPeptideSequence())) 200 { 201 potential.add(h); 202 } 203 } 204 205 } 206 } 207 // Match potential matches if they have not been matched 208 // before 209 if (f.getPeptideSequence() == null) 210 { 211 for (Hit h : potential) 212 { 213 if (h.getFeature() == null) 214 { 215 dc.reattachItem(h); 216 dc.reattachItem(f); 217 if (h.getPrecursorQuantity() == null || (h 218 .getPrecursorQuantity() < f 219 .getApexIntensity())) 220 { 221 h.setPrecursorQuantity(f 222 .getApexIntensity()); 223 f.addHit(h); 224 f 225 .setPeptideSequence(h 226 .getDescription()); 227 } 228 } 229 } 230 } 231 } 140 count += matchFeatures(features, hits, dc, tolerance, 141 startTimeTol, endTimeTol); 232 142 featureQuery.reset(); 233 143 } … … 252 162 253 163 254 private List<Hit> retrieveHits(File msFile, Project project, DbControl dc) 164 private int matchFeatures(List<Feature> features, List<Hit> hits, 165 DbControl dc, double tolerance, double startTimeTol, 166 double endTimeTol) 167 { 168 log.debug("Features to match:" + features.size()); 169 log.debug("Hits to match:" + hits.size()); 170 int count = 0; 171 for (Feature f : features) 172 { 173 List<Hit> potential = new ArrayList<Hit>(); 174 for (Hit h : hits) 175 { 176 double hitMz = h.getExperimentalMassInDaltons() / h.getCharge() + MONOISOTOPIC_PROTON_MASS; 177 if ((Math.abs(f.getMassToChargeRatio() - hitMz) < tolerance) && h 178 .getCharge().equals(f.getChargeState())) 179 { 180 log 181 .debug("m/z matching:" + f.getMassToChargeRatio() + " hit:" + hitMz); 182 if (h.getRetentionTimeInMinutes() >= f 183 .getStartRetentionTimeInMinutes() && h 184 .getRetentionTimeInMinutes() <= f 185 .getEndRetentionTimeInMinutes()) 186 { 187 /* A match! */ 188 log 189 .debug("Matched hit RT:" + h 190 .getRetentionTimeInMinutes() + " with feature RT:" + f 191 .getApexRetentionTimeInMinutes()); 192 count++; 193 dc.reattachItem(f); 194 dc.reattachItem(h); 195 if (f.getPeptideSequence() == null) 196 { 197 if (h.getFeature() == null || (h 198 .getPrecursorQuantity() < f.getApexIntensity())) 199 { 200 h.setPrecursorQuantity(f.getApexIntensity()); 201 } 202 f.setPeptideSequence(h.getDescription()); 203 f.addHit(h); 204 } 205 else 206 { 207 /* TODO chose the best match instead */ 208 /* 209 * Use the feature with the highest intensity 210 */ 211 if (h.getPrecursorQuantity() == null || (h 212 .getPrecursorQuantity() < f.getApexIntensity())) 213 { 214 h.setPrecursorQuantity(f.getApexIntensity()); 215 } 216 f.addHit(h); 217 } 218 } 219 // Check for potential matches just outside the 220 // feature 221 else if ((f.getStartRetentionTimeInMinutes() - startTimeTol) <= h 222 .getRetentionTimeInMinutes() && h 223 .getRetentionTimeInMinutes() <= (f 224 .getEndRetentionTimeInMinutes() + endTimeTol)) 225 { 226 if (h.getFeature() == null || h.getDescription() 227 .equals(f.getPeptideSequence())) 228 { 229 potential.add(h); 230 log 231 .debug("Potential hit RT: " + h 232 .getRetentionTimeInMinutes() + " with feature RT:" + f 233 .getApexRetentionTimeInMinutes()); 234 } 235 } 236 237 } 238 } 239 // Match potential matches if they have not been matched 240 // before 241 if (f.getPeptideSequence() == null) 242 { 243 for (Hit h : potential) 244 { 245 if (h.getFeature() == null) 246 { 247 dc.reattachItem(h); 248 dc.reattachItem(f); 249 if (h.getPrecursorQuantity() == null || (h 250 .getPrecursorQuantity() < f.getApexIntensity())) 251 { 252 log 253 .debug("Adding potential:" + h.getDescription() + " , RT:" + h 254 .getRetentionTimeInMinutes()); 255 h.setPrecursorQuantity(f.getApexIntensity()); 256 f.addHit(h); 257 f.setPeptideSequence(h.getDescription()); 258 count++; 259 } 260 } 261 } 262 } 263 } 264 return count; 265 } 266 267 268 private List<Hit> retrieveHits(File msFile, Project project, DbControl dc, 269 boolean matchRelated) 255 270 { 256 271 List<Hit> hits = new ArrayList<Hit>(); 257 272 ItemQuery<Hit> hitQuery = Hit.getQuery(project); 258 // First check if the same msXML file can be found in the hits table273 // First check if the same msXML file can be found in the hits table 259 274 hitQuery.restrict(Restrictions.eq(Hql.property("peakListFile"), Hql 260 275 .entity(msFile))); … … 311 326 } 312 327 log.debug("Query:" + hitQuery.toString()); 328 if (matchRelated) 329 { 330 // Match all hits that are NOT from the particular peak list 331 ItemResultList<Hit> hitlist = hitQuery.list(dc); 332 if (!hitlist.isEmpty()) 333 { 334 Hit h = hitlist.get(0); 335 hitQuery.reset(); 336 hitQuery.restrict(Restrictions.neq( 337 Hql.property("peakListFile"), Hql.entity(h 338 .getPeakListFile()))); 339 hitQuery.restrict(Restrictions.eq( 340 Hql.property("localSampleId"), Expressions 341 .parameter("localSampleId"))); 342 hitQuery.setPermanentParameter("localSampleId", h 343 .getLocalSampleId(), null); 344 hitQuery.restrict(Restrictions.eq(Hql.property("fractionId"), 345 Expressions.parameter("fractionId"))); 346 hitQuery.setPermanentParameter("fractionId", h.getFractionId(), 347 null); 348 } 349 } 313 350 ItemResultList<Hit> hitlist = hitQuery.list(dc); 314 351 for (Hit h : hitlist)
Note: See TracChangeset
for help on using the changeset viewer.