Skip to content

Commit

Permalink
Add the reader.close() missed by e960094.
Browse files Browse the repository at this point in the history
Other minor refactors and improvements.
  • Loading branch information
fcyu committed Oct 9, 2024
1 parent c73f098 commit 2a09902
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
10 changes: 5 additions & 5 deletions MSFragger-GUI/src/com/dmtavt/fragpipe/tools/skyline/Skyline.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class Skyline {

// convert our names to Skyline names
// names from Skyline cmd documentation (version 24.0-daily, 7/19/2024)
private final static HashMap<String, String> enzymesMap = new HashMap<>();
private final static Map<String, String> enzymesMap = new HashMap<>();
static {
enzymesMap.put("trypsin", "Trypsin");
enzymesMap.put("stricttrypsin", "Trypsin/P");
Expand Down Expand Up @@ -103,8 +103,8 @@ private static void runSkyline(String skylinePath, Path wd, String skylineVersio
PropsFile pf = new PropsFile(workflowPath, "for Skyline");
pf.load();

TreeSet<String> lcmsFiles = new TreeSet<>();
TreeSet<String> ddaAndDIAfiles = new TreeSet<>();
Set<String> lcmsFiles = new TreeSet<>();
Set<String> ddaAndDIAfiles = new TreeSet<>();

String dataType = "DDA";
String line;
Expand Down Expand Up @@ -141,7 +141,7 @@ private static void runSkyline(String skylinePath, Path wd, String skylineVersio
reader.close();

List<Path> speclibFiles = Files.walk(wd).filter(p -> p.getFileName().toString().endsWith(".speclib")).collect(Collectors.toList());
TreeSet<Path> psmTsvFiles = Files.walk(wd).filter(p -> p.getFileName().toString().startsWith("psm.tsv") && p.getFileName().toString().endsWith("psm.tsv")).collect(Collectors.toCollection(TreeSet::new));
Set<Path> psmTsvFiles = Files.walk(wd).filter(p -> p.getFileName().toString().startsWith("psm.tsv") && p.getFileName().toString().endsWith("psm.tsv")).collect(Collectors.toCollection(TreeSet::new));

if (useSpeclib && speclibFiles.isEmpty()) {
System.out.println("No DIA-NN .speclib files found in " + wd + " but Skyline was set to use the spectral library as input and DIA-NN was enabled. Did the DIA-NN run fail? No Skyline document will be generated.");
Expand All @@ -156,7 +156,7 @@ private static void runSkyline(String skylinePath, Path wd, String skylineVersio

Path peptideListPath = skylineOutputDir.resolve("peptide_list.txt").toAbsolutePath();
WritePeptideList pepWriter = new WritePeptideList();
HashMap<String, HashSet<String>> addedMods = pepWriter.writePeptideList(psmTsvFiles, peptideListPath);
Map<String, Set<String>> addedMods = pepWriter.writePeptideList(psmTsvFiles, peptideListPath);

Path modXmlPath = wd.resolve("mod.xml");
WriteSkyMods writeSkyMods = new WriteSkyMods(modXmlPath, pf, modsMode, matchUnimod, !useSpeclib, addedMods);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.regex.Pattern;

public class WritePeptideList {
private static HashMap<String, Integer> columns;
private static Map<String, Integer> columns;
private static final Pattern sitePattern = Pattern.compile("(\\d+)\\w\\(");
private static final Pattern massPattern = Pattern.compile("(\\([\\d.]+\\))");
private static final Pattern AApattern = Pattern.compile("\\d?([\\w-]+)\\(");
Expand All @@ -18,9 +18,9 @@ public class WritePeptideList {
public static final String COL_PROTEIN = "Protein";


public HashMap<String, HashSet<String>> writePeptideList(TreeSet<Path> psmtsvFiles, Path outputPath) throws IOException {
HashMap<String, Set<String>> proteinMap = new HashMap<>();
HashMap<String, HashSet<String>> additiveMods = new HashMap<>();
public Map<String, Set<String>> writePeptideList(Set<Path> psmtsvFiles, Path outputPath) throws IOException {
Map<String, Set<String>> proteinMap = new HashMap<>();
Map<String, Set<String>> additiveMods = new HashMap<>();

for (Path psmtsv: psmtsvFiles) {
BufferedReader reader = new BufferedReader(new FileReader(psmtsv.toFile()));
Expand All @@ -35,11 +35,13 @@ public HashMap<String, HashSet<String>> writePeptideList(TreeSet<Path> psmtsvFil
proteinMap.get(protein).add(modpep);
} else {
// initialize new protein and peptide
HashSet<String> peptides = new HashSet<>();
Set<String> peptides = new HashSet<>();
peptides.add(modpep);
proteinMap.put(protein, peptides);
}
}

reader.close();
}

// write output
Expand All @@ -60,11 +62,11 @@ public HashMap<String, HashSet<String>> writePeptideList(TreeSet<Path> psmtsvFil
* of "+" characters.
* @return
*/
public static String generateModifiedPeptide(String[] psmSplits, HashMap<String, Integer> columns, boolean addCharge, HashMap<String, HashSet<String>> additiveMods) {
public static String generateModifiedPeptide(String[] psmSplits, Map<String, Integer> columns, boolean addCharge, Map<String, Set<String>> additiveMods) {
String peptide = psmSplits[columns.get(COL_PEPTIDE)];

String[] mods = psmSplits[columns.get(COL_ASSIGNED_MODS)].split(",");
HashMap<Integer, String> modMap = new HashMap<>();
Map<Integer, String> modMap = new TreeMap<>();
for (String mod : mods) {
Matcher siteMatch = sitePattern.matcher(mod);
int site;
Expand Down Expand Up @@ -94,15 +96,14 @@ public static String generateModifiedPeptide(String[] psmSplits, HashMap<String,
/**
* Generate a modified peptide String with all Assigned modifications placed within it
*/
private static String insertMods(String peptide, HashMap<Integer, String> modMap) {
TreeMap<Integer, String> sortedMods = new TreeMap<>(modMap);
private static String insertMods(String peptide, Map<Integer, String> modMap) {
StringBuilder modifiedPeptide = new StringBuilder(peptide);

// Offset to account for insertions
int offset = 0;

// Iterate through the sorted entries and insert the mods
for (Map.Entry<Integer, String> entry : sortedMods.entrySet()) {
for (Map.Entry<Integer, String> entry : modMap.entrySet()) {
int position = entry.getKey() + offset;
String mod = entry.getValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class WriteSSL {

private static HashMap<String, Integer> columns;
private static Map<String, Integer> columns;
public static final String COL_SCANID = "Spectrum";
public static final String COL_CHARGE = "Charge";
public static final String COL_SCORE = "Probability";
Expand All @@ -23,13 +23,13 @@ public class WriteSSL {
* file scan charge sequence score-type score RT IM
* Sequence includes all mods. IM is optional. Score-type can be PERCOLATOR QVALUE or PEPTIDE PROPHET SOMETHING
*/
public void writeSSL(TreeSet<Path> psmtsvFiles, Path outputPath, boolean isPercolator, TreeSet<String> lcmsFiles, boolean useIonQuantPeaks) throws IOException {
public void writeSSL(Set<Path> psmtsvFiles, Path outputPath, boolean isPercolator, Set<String> lcmsFiles, boolean useIonQuantPeaks) throws IOException {
ArrayList<String> output = new ArrayList<>();
boolean isIM = false;
boolean checkIM = true;

// map file paths to the file names that will be in the psm.tsv
HashMap<String, String> lcmsFileNames = new HashMap<>();
Map<String, String> lcmsFileNames = new HashMap<>();
for (String lcmsFile : lcmsFiles) {
Path path = Paths.get(lcmsFile);
String fileName = path.getFileName().toString();
Expand Down Expand Up @@ -86,6 +86,8 @@ public void writeSSL(TreeSet<Path> psmtsvFiles, Path outputPath, boolean isPerco
}
output.add(sslLine.toString());
}

reader.close();
}

// write output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public class WriteSkyMods {
}
}

public WriteSkyMods(Path path, PropsFile pf, int modsMode, boolean matchUnimod, boolean isSSL, HashMap<String, HashSet<String>> addedMods) throws Exception {
public WriteSkyMods(Path path, PropsFile pf, int modsMode, boolean matchUnimod, boolean isSSL, Map<String, Set<String>> addedMods) throws Exception {
List<Mod> mods = new ArrayList<>(4);

String fixModStr = pf.getProperty("msfragger.table.fix-mods");
Expand Down Expand Up @@ -113,7 +113,7 @@ public WriteSkyMods(Path path, PropsFile pf, int modsMode, boolean matchUnimod,
}

// add any combined mods (multiple at one site) found during peptide list generation
for (Map.Entry<String, HashSet<String>> entry : addedMods.entrySet()) {
for (Map.Entry<String, Set<String>> entry : addedMods.entrySet()) {
mass = Float.parseFloat(entry.getKey());
mods.addAll(convertMods(String.join("", entry.getValue()), true, mass, mass, new ArrayList<>(), new ArrayList<>(), false));
}
Expand Down

0 comments on commit 2a09902

Please sign in to comment.