Changeset 3766


Ignore:
Timestamp:
Aug 16, 2010, 2:14:37 PM (13 years ago)
Author:
Fredrik Levander
Message:

Refs #614. Added log file for matching features to hits.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugin/src/org/proteios/plugins/FeatureHitMatcher.java

    r3764 r3766  
    3434import org.proteios.core.Hit;
    3535import org.proteios.core.Include;
     36import org.proteios.core.ItemFactory;
    3637import org.proteios.core.ItemQuery;
    3738import org.proteios.core.ItemResultList;
     
    5152import org.proteios.core.query.Restrictions;
    5253
     54import java.io.OutputStream;
     55import java.io.PrintWriter;
    5356import java.util.ArrayList;
    5457import java.util.Arrays;
     
    121124      boolean matchRelated = ((Boolean) job.getValue("secondary"))
    122125        .booleanValue();
    123       /* Check that the feature file hasn't been imported already */
    124126      QueryFactory qf = new QueryFactory();
    125127      try
    126128      {
     129        ItemFactory factory = new ItemFactory(dc);
     130        File outCoreFile = factory.create(File.class);
     131        dc.reattachItem(project);
     132        outCoreFile.setDirectory(project.getProjectDirectory());
     133        outCoreFile.setName("MatchLog-" + job.getId() + ".txt");
     134        dc.saveItem(outCoreFile);
     135        OutputStream outstream = outCoreFile.getUploadStream(false);
     136        PrintWriter writer = new PrintWriter(outstream);
     137        writer.println("Matching report for project:" + project
     138          .getName());
     139        writer.println("m/z tolerance:" + tolerance);
     140        writer
     141          .println("RT (minutes) tolerance - start:" + startTimeTol + " end:" + endTimeTol);
     142        writer.println("Matching with related files" + matchRelated);
    127143        List<File> uniqueMsFiles = Feature
    128144          .getUniqueMsFiles(project, dc);
     145        writer
     146          .println("Number of files with MS features:" + uniqueMsFiles
     147            .size() + "\n");
    129148        ItemQuery<Feature> featureQuery = qf.select(Feature.class);
    130149        featureQuery.restrictPermanent(Restrictions.eq(Hql
     
    135154            .property("msFile"), Hql.entity(currentMsFile)));
    136155          log.debug("Matching for file:" + currentMsFile);
     156          writer.println("File:" + currentMsFile);
    137157          List<Hit> hits = retrieveHits(currentMsFile, project, dc,
    138158            matchRelated);
    139159          List<Feature> features = featureQuery.list(dc);
    140160          count += matchFeatures(features, hits, dc, tolerance,
    141             startTimeTol, endTimeTol);
     161            startTimeTol, endTimeTol, writer);
    142162          featureQuery.reset();
    143163        }
     164        writer.close();
    144165        dc.commit();
    145166        response
     
    164185  private int matchFeatures(List<Feature> features, List<Hit> hits,
    165186      DbControl dc, double tolerance, double startTimeTol,
    166       double endTimeTol)
     187      double endTimeTol, PrintWriter writer)
    167188  {
    168189    log.debug("Features to match:" + features.size());
    169190    log.debug("Hits to match:" + hits.size());
     191    writer.println("Features to match:" + features.size());
     192    writer.println("MS/MS identifications to match:" + hits.size());
    170193    int count = 0;
     194    int newmatches = 0;
     195    int replaced = 0;
     196    int ambiguities = 0;
    171197    for (Feature f : features)
    172198    {
     
    199225              {
    200226                h.setPrecursorQuantity(f.getApexIntensity());
     227                replaced++;
    201228              }
    202229              f.setPeptideSequence(h.getDescription());
    203230              f.addHit(h);
     231              newmatches++;
    204232            }
    205233            else
     
    209237               * Use the feature with the highest intensity
    210238               */
    211               if (h.getPrecursorQuantity() == null || (h
     239              if (h.getPrecursorQuantity() == null && (h
    212240                .getPrecursorQuantity() < f.getApexIntensity()))
    213241              {
    214242                h.setPrecursorQuantity(f.getApexIntensity());
     243                if (!h.getDescription().equals(
     244                  f.getPeptideSequence()))
     245                {
     246                  f.setPeptideSequence(h.getDescription());
     247                  ambiguities++;
     248                }
     249                replaced++;
    215250              }
    216251              f.addHit(h);
     
    257292              f.setPeptideSequence(h.getDescription());
    258293              count++;
     294              newmatches++;
    259295            }
    260296          }
     
    262298      }
    263299    }
     300    writer.println("New features matched:" + newmatches);
     301    writer.println("Multiply matched features:" + replaced);
     302    writer.println("Matched hits:" + count);
     303    writer
     304      .println("Ambiguous matches (different sequences from MS/MS identifications):" + ambiguities);
     305    writer.println("===============================");
    264306    return count;
    265307  }
Note: See TracChangeset for help on using the changeset viewer.