diff --git a/src/main/java/cz/mendelu/dnaAnalyser/exporter/ExporterService.java b/src/main/java/cz/mendelu/dnaAnalyser/exporter/ExporterService.java index b3b1837c1f39e2c1f54890facb5bef9be2e48d05..191b6fa0809e4ec862a14d434def2f9e16c9547c 100644 --- a/src/main/java/cz/mendelu/dnaAnalyser/exporter/ExporterService.java +++ b/src/main/java/cz/mendelu/dnaAnalyser/exporter/ExporterService.java @@ -181,13 +181,12 @@ public class ExporterService { analysisColumnMapper = new ArrayList<String>();; break; } - try { - // add analysis specific header - result = String.format(result, name, description); + // Add analysis specific header + StringBuilder resultBuilder = new StringBuilder(); + resultBuilder.append(String.format(result, name, description)); while (rs.next()) { - try { chromStart = rs.getInt("POSITION"); if (sequenceStart == null) { @@ -196,47 +195,48 @@ public class ExporterService { chromEnd = rs.getInt("POSITION") + rs.getInt("LENGTH"); String strand = null; - Integer score = 0; - + int score = 0; + if (analysis == Analysis.RLOOP) { strand = rs.getString("STRAND"); - Integer g3 = rs.getInt("G3"); - Integer g4 = rs.getInt("G4"); - Integer gn = rs.getInt("GN"); + int g3 = rs.getInt("G3"); + int g4 = rs.getInt("G4"); + int gn = rs.getInt("GN"); - Double rizG = rs.getDouble("RIZGRICHNESS"); - Double rloopG = rs.getDouble("RLOOPGRICHNESS"); + double rizG = rs.getDouble("RIZGRICHNESS"); + double rloopG = rs.getDouble("RLOOPGRICHNESS"); - Integer scoreCalc = (int) Math.ceil(- (g3 + g4*2 + gn*3) * rizG * rloopG); + int scoreCalc = (int) Math.ceil(-(g3 + g4 * 2 + gn * 3) * rizG * rloopG); score = strand.equals("+") ? Math.abs(scoreCalc) : scoreCalc; - } - else if (analysis == Analysis.QUADRUPLEX || analysis == Analysis.AGGREGATE) { + } else if (analysis == Analysis.QUADRUPLEX || analysis == Analysis.AGGREGATE) { // G4 Hunter score calculation score = (int) Math.ceil(rs.getDouble("SCORE") * 100); - } - else if (analysis == Analysis.ZDNA) { + } else if (analysis == Analysis.ZDNA) { score = (int) Math.ceil(rs.getDouble("SCORE")); } dataValue = String.format(" %d", score); - } catch (SQLException e) { // score is for g4hunter, r + } catch (SQLException e) { log.error("Error fetching analysis data: {}", e); - } + continue; // Skip the rest of this loop iteration and continue with the next + } - result += String.format(format, + resultBuilder.append(String.format(format, chrom, - posInGenomeStart+chromStart, - posInGenomeStart+chromEnd, + posInGenomeStart + chromStart, + posInGenomeStart + chromEnd, dataValue - ); + )); // This is now using StringBuilder dataValue = ""; } - } - catch (NullPointerException | NotFoundException e) { - log.error("Error finding analysis by id: {}\n {}", id, e); + // Convert the StringBuilder to a String + result = resultBuilder.toString(); + + } catch (SQLException e) { + log.error("Error processing result set: {}", e); } // update browser header