Skip to content

Commit

Permalink
Fix some issues with protein prophet
Browse files Browse the repository at this point in the history
  • Loading branch information
chhh committed Jan 6, 2019
1 parent 54fab72 commit c968e2d
Show file tree
Hide file tree
Showing 10 changed files with 312 additions and 118 deletions.
40 changes: 25 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = 'com.dmtavt'
version = '1.0'
version = '1.1'

description = """DeltaMass - detection and visualization of common mass shifts in proteomic searches."""

Expand All @@ -29,7 +29,12 @@ jar {

shadowJar {
classifier = null
minimize()
minimize {
exclude(dependency('javax.xml.bind:jaxb-api:.*'))
exclude(dependency('org.glassfish.jaxb:jaxb-runtime:.*'))
exclude(dependency('javax.activation:javax.activation-api:.*'))
exclude(dependency('com.sun.istack:istack-commons-runtime:.*'))
}
}

launch4j {
Expand All @@ -46,19 +51,19 @@ repositories {
}
dependencies {
// our projects
implementation("com.github.chhh:dmtavt-utils:0.4.4")
implementation("com.github.chhh:msftbx:1.8.6")
implementation("com.github.chhh:ptm-factory:1.0")
implementation("edu.umich.andykong:mscalibrator:1.1")
compile("com.github.chhh:dmtavt-utils:0.4.4")
compile("com.github.chhh:msftbx:1.8.6")
compile("com.github.chhh:ptm-factory:1.0")
compile("edu.umich.andykong:mscalibrator:1.1")

// basic
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
implementation group: 'com.beust', name: 'jcommander', version: '1.72'
compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
compile group: 'com.beust', name: 'jcommander', version: '1.72'

// commons
implementation group: 'org.apache.commons', name: 'commons-math3', version: '3.6.1'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
compile group: 'org.apache.commons', name: 'commons-math3', version: '3.6.1'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.8.1'
compile 'commons-io:commons-io:2.6'

// other
Expand All @@ -67,17 +72,22 @@ dependencies {
compile 'com.miglayout:miglayout-swing:5.2'
compile 'org.jfree:jfreechart:1.5.0'

implementation group: 'com.edwardraff', name: 'JSAT', version: '0.0.9'
implementation(group: 'com.github.haifengl', name: 'smile-core', version: '1.5.2') {
compile(group: 'com.edwardraff', name: 'JSAT', version: '0.0.9')
compile(group: 'com.github.haifengl', name: 'smile-core', version: '1.5.2') {
exclude(module: 'smile-data')
exclude(module: 'smile-graph')
}

// JAXB stuff for parsing mods from databases
compile 'javax.xml.bind:jaxb-api:2.3.1'
compile 'org.glassfish.jaxb:jaxb-runtime:2.3.1'
compile 'javax.activation:javax.activation-api:1.2.0'

// downloaded / precompiled jars
compile fileTree(dir: 'libs', include: '*.jar')

// test
testImplementation(group: 'org.apache.maven', name: 'maven-model', version: '3.6.0')
testImplementation group: 'junit', name: 'junit', version: '4.12'
testCompile(group: 'org.apache.maven', name: 'maven-model', version: '3.6.0')
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile("org.assertj:assertj-core:3.11.1")
}
101 changes: 101 additions & 0 deletions build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project basedir="." default="default" name="DeltaMass">
<description>Builds, tests, and runs the project DeltaMass.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="DeltaMass-impl.jar">
<executorDefSize dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</executorDefSize>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->

<target depends="jar" name="package-for-store">
<property name="store.jar.name" value="DeltaMass"/>
<property name="store.dir" value="dist"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
<delete dir="${store.dir}"/>
<mkdir dir="${store.dir}"/>
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<zip destfile="${store.jar}">
<zipfileset excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"
src="${store.dir}/temp_final.jar"/>
</zip>
<delete file="${store.dir}/temp_final.jar"/>
</target>

<!-- Creating manifest for NetBeans Ant builds -->
<target name="-pre-init">
<!-- Not needed, turns out you can just put stuff in manifest.mf file in
the project root directory -->
</target>

</project>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
deltamass.version.current=0.1-SNAPSHOT
deltamass.version.current=1.1
2 changes: 1 addition & 1 deletion src/main/java/com/dmtavt/deltamass/Bundle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
deltamass.version.current=1.0
deltamass.version.current=1.1
7 changes: 3 additions & 4 deletions src/main/java/com/dmtavt/deltamass/DeltaMassInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ public final class DeltaMassInfo {
private static final EventBus bus = EventBus.getDefault();

public static final String Name = "DeltaMass";
public static final String Ver = "1.0";
public static final String Ver = "1.1";

private static final String PROP_VER = "deltamass.version.current";
private static final String PROP_DOWNLOAD_URL = "deltamass.download.url";
private static final String DEFAULT_DOWNLOAD_URL = "https://github.com/chhh/deltamass/releases";
private static final String BUNDLE_PATH = "com/dmtavt/deltamass/Bundle";
private static final String BUNDLE_PATH = "com/dmtavt/deltamass/Bundle.properties";
private static final String BUNDLE_URL =
"https://raw.githubusercontent.com/chhh/deltamass/master/src/main/java/" + BUNDLE_PATH
+ ".properties";
"https://raw.githubusercontent.com/chhh/deltamass/master/src/main/java/" + BUNDLE_PATH;
private static final URI BUNDLE_URI = URI.create(BUNDLE_URL);

private DeltaMassInfo() {
Expand Down
119 changes: 44 additions & 75 deletions src/main/java/com/dmtavt/deltamass/logic/LogicClean.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,45 @@ public LogicClean(CommandClean cmd) {

public void run() {
log.info("Running cleanup");
if (cmd.dryRun) log.info("Dry-run, won't take any action.");
int stepsPerformed = 0;
final List<Path> scheduledForDeletion = getScheduledForDeletion();

if (!cmd.noPep) {
stepsPerformed++;
log.info("Cleaning up peptide identification files.");
DeletionStats stats = deleteMatchingFilesInSubtrees(cmd.inputFiles,
CacheLocator::isPepCacheFile, cmd.dryRun);
log.info("Pep ID cleanup summary: scheduled: {}, deleted: {}, skipped: {}, error: {}",
stats.scheduled, stats.deleted, stats.skipped.size(), stats.error.size());
}
final String list = scheduledForDeletion.stream().map(Path::toString)
.collect(Collectors.joining("\n"));
log.info("Files to delete:\n" + list);

if (!cmd.noLcms) {
stepsPerformed++;
log.info("Cleaning up LC-MS calibration files.");
DeletionStats stats = deleteMatchingFilesInSubtrees(cmd.inputFiles,
CacheLocator::isCalCacheFile, cmd.dryRun);
log.info("Calibration cleanup summary: scheduled: {}, deleted: {}, skipped: {}, error: {}",
stats.scheduled, stats.deleted, stats.skipped.size(), stats.error.size());
if (cmd.dryRun) {
log.info("Dry-run, won't take any action.");
return;
}

if (stepsPerformed == 0) log.info("You made it clear that nothing should be cleaned up. Doing nothing.");
DeletionStats stats = delete(scheduledForDeletion);
log.info("Cleanup: deleted {}/{}, errors: {}", stats.deleted.size(), stats.scheduled.size(), stats.error.size());
}

private static List<Path> modifyInputPathsForCacheDeletion(List<Path> paths) {
List<Path> possibleCachePaths = new ArrayList<>();
for (Path inputFile : paths) {
if (Files.isDirectory(inputFile)) {
possibleCachePaths.add(inputFile);
} else {
Path parent = inputFile.getParent();
Path fn = inputFile.getFileName();
possibleCachePaths.add(parent.resolve(fn.toString() + CacheLocator.CACHE_EXT_PEP));
possibleCachePaths.add(parent.resolve(fn.toString() + CacheLocator.CACHE_EXT_CAL));
}
}
return possibleCachePaths;
}

public List<Path> getScheduledForDeletion() {
List<Path> delete = new ArrayList<>();
final List<Path> putativeCachePaths = modifyInputPathsForCacheDeletion(cmd.inputFiles);

if (!cmd.noPep) {
delete.addAll(getScheduledForDeletion(cmd.inputFiles, CacheLocator::isPepCacheFile));
delete.addAll(getScheduledForDeletion(putativeCachePaths, CacheLocator::isPepCacheFile));
}
if (!cmd.noLcms) {
delete.addAll(getScheduledForDeletion(cmd.inputFiles, CacheLocator::isCalCacheFile));
delete.addAll(getScheduledForDeletion(putativeCachePaths, CacheLocator::isCalCacheFile));
}
return delete;
}
Expand Down Expand Up @@ -89,73 +97,34 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
log.warn("Error collecting files for deletion in subtree: {}" + path, e);
}
} else {
if (condition.test(path)) {
if (Files.exists(path) && condition.test(path)) {
delete.add(path);
}
}
}
return new ArrayList<>(delete);
}

private class DeletionStats {
int scheduled = 0;
int deleted = 0;
ConcurrentLinkedQueue<Path> skipped = new ConcurrentLinkedQueue<>();
private static class DeletionStats {
ConcurrentLinkedQueue<Path> scheduled = new ConcurrentLinkedQueue<>();
ConcurrentLinkedQueue<Path> deleted = new ConcurrentLinkedQueue<>();
ConcurrentLinkedQueue<Path> error = new ConcurrentLinkedQueue<>();
}

private DeletionStats deleteMatchingFilesInSubtrees(Iterable<? extends Path> paths, Predicate<? super Path> condition, boolean dryRun) {
final ConcurrentLinkedQueue<Path> delete = new ConcurrentLinkedQueue<>();
final DeletionStats stats = new DeletionStats();

for (Path path : paths) {
if (Files.isDirectory(path)) {
try {
Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
if (!Files.isReadable(dir)) return FileVisitResult.SKIP_SUBTREE;
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
if (!Files.isWritable(file)) {
log.warn("File not writeable, skipping: {}", file);
stats.skipped.add(file);
return FileVisitResult.CONTINUE;
}
if (condition.test(file)) delete.add(file);
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
log.error("Error collecting files for deletion in subtree: {}" + path, e);
}
} else {
if (CacheLocator.isPepCacheFile(path))
delete.add(path);
}
}

if (!delete.isEmpty()) {
log.info("Files scheduled for deletion:\n {}",
delete.stream().map(Path::toString).collect(Collectors.joining("\n ")));
} else {
log.info("Found no files to delete.");
}
stats.scheduled = delete.size();

if (!dryRun) delete.forEach(path -> {
public static DeletionStats delete(List<Path> pathsToDelete) {
DeletionStats ds = new DeletionStats();
ds.scheduled.addAll(pathsToDelete);
for (Path path : pathsToDelete) {
try {
Files.deleteIfExists(path);
stats.deleted++;
if (Files.deleteIfExists(path)) {
ds.deleted.add(path);
}
} catch (IOException e) {
log.error("Could not delete file: " + path, e);
stats.error.add(path);
log.error("Error deleting file: " + path.toString() + "\nDetails:\n" + e.getMessage());
ds.error.add(path);
}
});

return stats;
}
return ds;
}

}
12 changes: 9 additions & 3 deletions src/main/java/com/dmtavt/deltamass/logic/LogicInputFiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,11 @@ private List<Path> inputFiles(List<Path> inputPaths, final Pattern regex, boolea
return matched;
}

private boolean isPepFileSupported(Path pepFilePath) {
IParserFactory<IPepidParser> parser = PepidParserRegistry.find(pepFilePath);
return parser != null;
}

private List<Path> collectSupportedFiles(Iterable<? extends Path> paths, boolean recursive) {
final ConcurrentLinkedQueue<Path> supported = new ConcurrentLinkedQueue<>();

Expand All @@ -280,8 +285,7 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
IParserFactory<IPepidParser> parser = PepidParserRegistry.find(file);
if (parser != null) {
if (isPepFileSupported(file)) {
supported.add(file);
}
return FileVisitResult.CONTINUE;
Expand All @@ -292,8 +296,10 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
log.warn("Error collecting files for deletion in subtree: {}" + path, e);
}
} else {
if (CacheLocator.isPepCacheFile(path))
// given a regular file, not a directory
if (isPepFileSupported(path)) {
supported.add(path);
}
}
}
return new ArrayList<>(supported);
Expand Down
Loading

0 comments on commit c968e2d

Please sign in to comment.