@Override public void run() { float lowrt = peakA.ApexRT - parameter.ApexDelta; float highrt = peakA.ApexRT + parameter.ApexDelta; float lowmz = InstrumentParameter.GetMzByPPM(peakA.TargetMz, 1, parameter.MS1PPM); float highmz = InstrumentParameter.GetMzByPPM( (peakA.TargetMz + ((float) this.MaxNoOfClusters / this.StartCharge)), 1, -parameter.MS1PPM); Object[] found = null; try { found = PeakCurveSearchTree.range(new double[] {lowrt, lowmz}, new double[] {highrt, highmz}); } catch (KeySizeException ex) { Logger.getRootLogger().error(ExceptionUtil.printStackTrace(ex)); } if (found == null || found.length == 0) { return; } SortedCurveCollectionMZ PeakCurveListMZ = new SortedCurveCollectionMZ(); for (Object peakCurve : found) { PeakCurveListMZ.add((PeakCurve) peakCurve); } float Arange = peakA.EndRT() - peakA.StartRT(); for (int charge = EndCharge; charge >= StartCharge; charge--) { float mass = charge * (peakA.TargetMz - (float) ElementaryIon.proton.getTheoreticMass()); if (mass < parameter.MinPrecursorMass || mass > parameter.MaxPrecursorMass || (parameter.MassDefectFilter && !MD.InMassDefectRange(mass, parameter.MassDefectOffset))) { continue; } PeakCluster peakCluster = new PeakCluster(MaxNoOfClusters, charge); peakCluster.IsoPeaksCurves[0] = peakA; peakCluster.MonoIsotopePeak = peakA; XYData[] Ranges = new XYData[MaxNoOfClusters - 1]; for (int i = 0; i < MaxNoOfClusters - 1; i++) { Entry range = IsotopePatternMap[i].ceilingEntry(peakCluster.NeutralMass()); if (range == null) { range = IsotopePatternMap[i].lastEntry(); } Ranges[i] = (XYData) range.getValue(); } for (int pkidx = 1; pkidx < MaxNoOfClusters; pkidx++) { float ppmthreshold = parameter.MS1PPM + (parameter.MS1PPM * pkidx * 0.5f); float lowtheomz = InstrumentParameter.GetMzByPPM( peakA.TargetMz + (pkidx * ((float) ElementaryIon.proton.getTheoreticMass() / charge)), charge, ppmthreshold); float uptheomz = InstrumentParameter.GetMzByPPM( peakA.TargetMz + (pkidx * ((float) ElementaryIon.proton.getTheoreticMass() / charge)), charge, -ppmthreshold); int startmzidx = PeakCurveListMZ.BinarySearchLower(lowtheomz); float theomz = peakA.TargetMz + (pkidx * ((float) ElementaryIon.proton.getTheoreticMass() / charge)); float maxscore = 0f; float maxcorr = 0f; float maxoverlap = 0f; PeakCurve closestPeak = null; for (int mzidx = startmzidx; mzidx < PeakCurveListMZ.size(); mzidx++) { PeakCurve peakB = PeakCurveListMZ.get(mzidx); if (peakB.TargetMz <= peakA.TargetMz) { continue; } if (peakB.TargetMz > uptheomz) { break; } float Brange = peakB.EndRT() - peakB.StartRT(); float OverlapP = 0f; if (peakA.StartRT() >= peakB.StartRT() && peakA.StartRT() <= peakB.EndRT() && peakA.EndRT() >= peakB.EndRT()) { OverlapP = (peakB.EndRT() - peakA.StartRT()) / Brange; } else if (peakA.EndRT() >= peakB.StartRT() && peakA.EndRT() <= peakB.EndRT() && peakA.StartRT() <= peakB.StartRT()) { OverlapP = (peakA.EndRT() - peakB.StartRT()) / Brange; } else if (peakA.StartRT() <= peakB.StartRT() && peakA.EndRT() >= peakB.EndRT()) { OverlapP = 1; } else if (peakA.StartRT() >= peakB.StartRT() && peakA.EndRT() <= peakB.EndRT()) { OverlapP = Arange / Brange; } if (parameter.TargetIDOnly || (OverlapP > parameter.MiniOverlapP && (!parameter.CheckMonoIsotopicApex || (peakA.ApexRT >= peakB.StartRT() && peakA.ApexRT <= peakB.EndRT() && peakB.ApexRT >= peakA.StartRT() && peakB.ApexRT <= peakA.EndRT())))) { float ppm = InstrumentParameter.CalcPPM(theomz, peakB.TargetMz); if (ppm < ppmthreshold) { float corr = 0f; try { corr = PeakCurveCorrCalc.CalPeakCorr(peakA, peakB, parameter.NoPeakPerMin); } catch (IOException ex) { Logger.getRootLogger().error(ExceptionUtil.printStackTrace(ex)); } if (Float.isNaN(corr)) { corr = 0f; // System.out.print("Corr=NAN\n"); } float PeakIntA = peakA.ApexInt; float PeakIntB = peakB.GetMaxIntensityByRegionRange( Math.max(peakA.StartRT(), peakB.StartRT()), Math.min(peakB.EndRT(), peakA.EndRT())); if ((parameter.TargetIDOnly && corr > 0.2f) || corr > parameter.IsoCorrThreshold) { // if (corr > parameter.IsoCorrThreshold || (PeakIntA > PeakIntB*1.5f && // PeakIntB>0.1f * PeakIntA && (peakA.EndScan-peakA.StartScan)>4 && // (peakB.EndScan-peakB.StartScan)>4)) { float intscore = 0f; float IntRatio = PeakIntB / PeakIntA; if (IntRatio > Ranges[pkidx - 1].getY() && IntRatio <= Ranges[pkidx - 1].getX()) { intscore = 1f; } else { if (Math.abs(IntRatio - Ranges[pkidx - 1].getY()) > Math.abs(IntRatio - Ranges[pkidx - 1].getX())) { intscore = 1 - Math.abs(IntRatio - Ranges[pkidx - 1].getX()); } else { intscore = 1 - Math.abs(IntRatio - Ranges[pkidx - 1].getY()); } } if (intscore < 0f) { intscore = 0f; } float score = ((ppmthreshold - ppm) / ppmthreshold) + corr + intscore; if (maxscore < score) { maxscore = score; closestPeak = peakB; maxcorr = corr; maxoverlap = OverlapP; } } } } } if (closestPeak != null) { peakCluster.Corrs[pkidx - 1] = maxcorr; peakCluster.IsoPeaksCurves[pkidx] = closestPeak; peakCluster.OverlapRT[pkidx - 1] = maxoverlap; peakCluster.GetSNR(pkidx - 1); if (pkidx == 1) { peakCluster.OverlapP = maxoverlap; } } if (closestPeak == null) { break; } } if (peakCluster.IsotopeComplete(MinNoOfClusters)) { peakCluster.CalcPeakArea_V2(); peakCluster.UpdateIsoMapProb(IsotopePatternMap); peakCluster.AssignConfilictCorr(); peakCluster.LeftInt = peakA.GetSmoothedList().Data.get(0).getY(); peakCluster.RightInt = peakA.GetSmoothedList().Data.get(peakA.GetSmoothedList().PointCount() - 1).getY(); if (parameter.TargetIDOnly || peakCluster.IsoMapProb > parameter.IsoPattern) { ResultClusters.add(peakCluster); if (!parameter.TargetIDOnly || (parameter.RemoveGroupedPeaks && peakCluster.Corrs[0] > parameter.RemoveGroupedPeaksCorr && peakCluster.OverlapP > parameter.RemoveGroupedPeaksRTOverlap)) { for (int i = 1; i < peakCluster.IsoPeaksCurves.length; i++) { PeakCurve peak = peakCluster.IsoPeaksCurves[i]; if (peak != null && peakCluster.Corrs[i - 1] > parameter.RemoveGroupedPeaksCorr && peakCluster.OverlapRT[i - 1] > parameter.RemoveGroupedPeaksRTOverlap) { peak.ChargeGrouped.add(charge); } } } } } } PeakCurveListMZ = null; // System.out.print("....done\n"); }
/** Dumps the results as a series of KML's..one per trip */ public void writeKMLandCSV() { String csv_header = "INDEX,DATE,TIME,SECONDS_SINCE_MIDNIGHT,TRIP_ID,DIR,SPEED,LAT,LONG,ALT,EXITS,ENTRANCES"; try { CSVWriter writer = new CSVWriter(new FileWriter("bus_data.csv"), ','); // Write the header String[] entries = csv_header.split(","); writer.writeNext(entries); // Setup some style LineStyle lineStyle = new LineStyle(); lineStyle.setColor("ff005555"); lineStyle.setWidth(5.0); IconStyle peopleIconStyle = new IconStyle(); // Icon peopleIcon = new Icon(); // peopleIcon.setHref("http://maps.google.com/mapfiles/kml/man.png"); peopleIconStyle.setIconHref("http://maps.google.com/mapfiles/kml/shapes/man.png"); peopleIconStyle.setScale(1.50); IconStyle wpIconStyleNorth = new IconStyle(); // wpIcon.setHref("http://maps.google.com/mapfiles/kml/paddle/red-stars.png"); // wpIconStyleNorth.setIconHref("http://maps.google.com/mapfiles/kml/shapes/placemark_circle.png"); wpIconStyleNorth.setIconHref("http://maps.google.com/mapfiles/ms/micons/green-dot.png"); wpIconStyleNorth.setScale(0.50); IconStyle wpIconStyleSouth = new IconStyle(); // wpIcon.setHref("http://maps.google.com/mapfiles/kml/paddle/red-stars.png"); wpIconStyleSouth.setIconHref("http://maps.google.com/mapfiles/ms/micons/yellow-dot.png"); wpIconStyleSouth.setScale(0.50); Style style_lineStyle = new Style(); style_lineStyle.setLineStyle(lineStyle); Style style_peopleIconStyle = new Style(); style_peopleIconStyle.setId("peopleIcon"); style_peopleIconStyle.setIconStyle(peopleIconStyle); Style style_wpIconStyleNorth = new Style(); style_wpIconStyleNorth.setId("wpIconNorth"); style_wpIconStyleNorth.setIconStyle(wpIconStyleNorth); Style style_wpIconStyleSouth = new Style(); style_wpIconStyleSouth.setId("wpIconSouth"); style_wpIconStyleSouth.setIconStyle(wpIconStyleSouth); Kml[] kml = new Kml[tripCounter]; Document[] document = new Document[tripCounter]; Folder[] northFolders = new Folder[tripCounter]; Folder[] southFolders = new Folder[tripCounter]; Folder[] peopleFolders = new Folder[tripCounter]; // Folder[] tracksFolders = new Folder[tripCounter]; for (int i = 0; i < tripCounter; i++) { kml[i] = new Kml(); kml[i].setXmlIndent(true); document[i] = new Document(); document[i].addStyleSelector(style_lineStyle); document[i].addStyleSelector(style_peopleIconStyle); document[i].addStyleSelector(style_wpIconStyleNorth); document[i].addStyleSelector(style_wpIconStyleSouth); kml[i].setFeature(document[i]); northFolders[i] = new Folder(); northFolders[i].setName("North Route"); southFolders[i] = new Folder(); southFolders[i].setName("South Route"); peopleFolders[i] = new Folder(); peopleFolders[i].setName("People"); // tracksFolders[i] = new Folder(); // tracksFolders[i].setName("Tracks"); document[i].addFeature(northFolders[i]); document[i].addFeature(southFolders[i]); document[i].addFeature(peopleFolders[i]); // document[i].addFeature(tracksFolders[i]); } double[] lowerKey = new double[1]; double[] upperKey = new double[1]; lowerKey[0] = firstTime; upperKey[0] = lastTime; Object[] foo = geoRecords.range(lowerKey, upperKey); for (int i = 0; i < foo.length; i++) { GeoRecord nextRecord = (GeoRecord) foo[i]; int tripNumber = nextRecord.getTripId(); // System.out.println(foo[i]); if (nextRecord.getDirection().equals("N")) { northFolders[tripNumber - 1].addFeature(nextRecord.toKML()); } else { southFolders[tripNumber - 1].addFeature(nextRecord.toKML()); } if (nextRecord.getAssociatedPeople().size() > 0) { peopleFolders[tripNumber - 1].addFeature(nextRecord.toKMLWithPeople()); } // Write CSV entry String csvLine = nextRecord.toCSV(); String[] entries2 = csvLine.split(","); writer.writeNext(entries2); } // Write the KML files for (int i = 0; i < tripCounter; i++) { kml[i].createKml("bus_route" + i + ".kml"); } // Close the csv writer writer.close(); } catch (Exception e) { System.err.println(e); } }