Skip to content

Commit

Permalink
Change some LinkedList to ArrayList for a higher speed.
Browse files Browse the repository at this point in the history
  • Loading branch information
fcyu committed Feb 4, 2018
1 parent 63deabe commit 06ad992
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
11 changes: 6 additions & 5 deletions src/main/java/proteomics/ECL2.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ private ECL2(String parameter_path, String spectra_path, String dbName) throws I
}
ExecutorService thread_pool = Executors.newFixedThreadPool(thread_num);
Search search_obj = new Search(build_index_obj, parameter_map, ms1Tolerance, leftInverseMs1Tolerance, rightInverseMs1Tolerance, ms1ToleranceUnit);
List<Future<Boolean>> taskList = new LinkedList<>();
ArrayList<Future<SearchWrap.Entry>> taskList = new ArrayList<>(preSpectra.getUsefulSpectraNum() + 10);
Connection sqlConnection = DriverManager.getConnection(sqlPath);
Statement sqlStatement = sqlConnection.createStatement();
ResultSet sqlResultSet = sqlStatement.executeQuery("SELECT scanId, precursorCharge, massWithoutLinker, precursorMass FROM spectraTable");
Expand All @@ -188,8 +188,8 @@ private ECL2(String parameter_path, String spectra_path, String dbName) throws I
int count = 0;
while (count < totalCount) {
// record search results and delete finished ones.
List<Future<Boolean>> toBeDeleteTaskList = new LinkedList<>();
for (Future<Boolean> task : taskList) {
List<Future<SearchWrap.Entry>> toBeDeleteTaskList = new ArrayList<>(totalCount - count);
if (task.isDone()) {
if (task.get()) {
++resultCount;
Expand All @@ -201,6 +201,7 @@ private ECL2(String parameter_path, String spectra_path, String dbName) throws I
}
count += toBeDeleteTaskList.size();
taskList.removeAll(toBeDeleteTaskList);
taskList.trimToSize();

int progress = count * 20 / totalCount;
if (progress != lastProgress) {
Expand Down Expand Up @@ -270,20 +271,20 @@ private static void saveTargetResult(Map<String, CalFDR.Entry> result, Map<Strin
interTargetWriter.write("scan_num,spectrum_id,spectrum_mz,spectrum_mass,peptide_mass,rt,C13_correction,charge,score,delta_C,ppm,peptide,protein,protein_annotation_1,protein_annotation_2,e_value,q_value,mgf_title,\n");
interDecoyWriter.write("scan_num,spectrum_id,spectrum_mz,spectrum_mass,peptide_mass,rt,C13_correction,charge,score,delta_C,ppm,peptide,protein,protein_annotation_1,protein_annotation_2,e_value,q_value,mgf_title,\n");
}
List<CalFDR.Entry> entryList = new LinkedList<>(result.values());
List<CalFDR.Entry> entryList = new ArrayList<>(result.values());
entryList.sort(Comparator.reverseOrder());
for (CalFDR.Entry entry : entryList) {
sqlResultSet = sqlStatement.executeQuery(String.format(Locale.US, "SELECT scanNum, precursorMz, precursorMass, rt, isotopeCorrectionNum, ms1PearsonCorrelationCoefficient, precursorCharge, theoMass, score, deltaC, ppm, seq1, linkSite1, seq2, linkSite2, proId1, proId2, eValue, mgfTitle, candidateNum, pointCount, rSquare, slope, intercept, startIdx, endIdx, chainScore1, chainRank1, chainScore2, chainRank2, hitType, clType FROM spectraTable WHERE scanId='%s'", entry.scanId));
if (sqlResultSet.next()) {
List<String> proAnnotationList1 = new LinkedList<>();
List<String> proAnnotationList1 = new ArrayList<>();
for (String s : sqlResultSet.getString("proId1").split(";")) {
if (s.startsWith("DECOY_")) {
proAnnotationList1.add("DECOY");
} else {
proAnnotationList1.add(pro_annotate_map.get(s));
}
}
List<String> proAnnotationList2 = new LinkedList<>();
List<String> proAnnotationList2 = new ArrayList<>();
for (String s : sqlResultSet.getString("proId2").split(";")) {
if (s.startsWith("DECOY_")) {
proAnnotationList2.add("DECOY");
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/proteomics/Spectrum/PreSpectra.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class PreSpectra {
private static final Pattern scanNumPattern3 = Pattern.compile("^[^.]+\\.([0-9]+)\\.[0-9]+\\.[0-9]");

private Map<Integer, TreeMap<Integer, TreeSet<DevEntry>>> scanDevEntryMap = new HashMap<>();
private int usefulSpectraNum = 0;

public PreSpectra(JMzReader spectra_parser, double ms1Tolerance, double leftInverseMs1Tolerance, double rightInverseMs1Tolerance, int ms1ToleranceUnit, BuildIndex build_index_obj, Map<String, String> parameter_map, String ext, String sqlPath) throws MzXMLParsingException, IOException, SQLException, JMzReaderException {
Set<Integer> debug_scan_num_set = new HashSet<>();
Expand All @@ -52,7 +53,6 @@ public PreSpectra(JMzReader spectra_parser, double ms1Tolerance, double leftInve

PreparedStatement sqlPrepareStatement = sqlConnection.prepareStatement("INSERT INTO spectraTable (scanNum, scanId, precursorCharge, precursorMz, precursorMass, rt, massWithoutLinker, mgfTitle, isotopeCorrectionNum, ms1PearsonCorrelationCoefficient) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
sqlConnection.setAutoCommit(false);
int usefulSpectraNum = 0;

Iterator<Spectrum> spectrumIterator = spectra_parser.getSpectrumIterator();
String parentId = null;
Expand Down Expand Up @@ -154,6 +154,10 @@ public Map<Integer, TreeMap<Integer, TreeSet<DevEntry>>> getScanDevEntryMap() {
return scanDevEntryMap;
}

public int getUsefulSpectraNum() {
return usefulSpectraNum;
}

private Entry getIsotopeCorrectionNum(double precursorMz, int charge, double inverseCharge, TreeMap<Double, Double> parentPeakList, double ms1Tolerance, double leftInverseMs1Tolerance, double rightInverseMs1Tolerance, int ms1ToleranceUnit, IsotopeDistribution isotopeDistribution, TreeMap<Integer, TreeSet<DevEntry>> chargeDevEntryMap) {
Entry entry = new Entry(0, 0);
double leftTol = ms1Tolerance * 2;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/proteomics/Types/SparseVector.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ public Set<Integer> getIdxSet() {
}

double getMaxValue() {
List<Double> intensity_list = new LinkedList<>(sparse_vector.values());
List<Double> intensity_list = new ArrayList<>(sparse_vector.values());
intensity_list.sort(Collections.reverseOrder());
return intensity_list.get(0);
}

double getMinValue() {
List<Double> intensity_list = new LinkedList<>(sparse_vector.values());
List<Double> intensity_list = new ArrayList<>(sparse_vector.values());
Collections.sort(intensity_list);
return intensity_list.get(0);
}
Expand Down

0 comments on commit 06ad992

Please sign in to comment.