Skip to content

Commit

Permalink
feat: release 1.8.0 (bugfixes, new relaxed mode) (#26)
Browse files Browse the repository at this point in the history
* chore: set version to 1.8-SNAPSHOT

* build: bump sortpom-maven-plugin from 2.11.0 to 3.2.0 (#14)

* build: bump spring-boot-maven-plugin from 2.4.5 to 2.7.3 (#15)

* build: bump spring-boot-starter-data-jpa from 2.4.5 to 2.7.3 (#13)

* build: bump spring-boot-starter-web from 2.3.10.RELEASE to 2.7.3 (#12)

* build: bump spring-core from 5.3.6 to 5.3.22 (#11)

* build: bump spring-boot-starter-validation from 2.4.5 to 2.7.3 (#20)

* build: bump versions-maven-plugin from 2.7 to 2.11.0 (#18)

* build: bump spring-boot-starter-test from 2.3.10.RELEASE to 2.7.3 (#17)

* build: bump maven-assembly-plugin from 3.2.0 to 3.4.2 (#16)

* build: bump value from 2.9.1 to 2.9.2 (#25)

* build: bump progressbar from 0.9.3 to 0.9.4 (#24)

* build: bump mockito-core from 4.7.0 to 4.8.0 (#23)

* build: bump versions-maven-plugin from 2.11.0 to 2.12.0 (#22)

* build: bump maven-compiler-plugin from 3.8.1 to 3.10.1 (#21)

* feat: improve relaxed mode

* fix: apply relaxed rules for both MEDIUM and FULL settings

* feat: add spotless config

* ref: auto refactor using spotless

* fix: use a pre-sorted list instead of a tree set

The objects held in the tree set were pairs. Usually the first value in
the pair was unique, but not always. The second value in the pair is
incomparable, so in the rare events the whole pair sorting failed.

* fix: do not report bond length violations between separate fragments

* fix: merge separated chains in relaxed mode

* chore: set version to 1.8.0

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
  • Loading branch information
tzok and dependabot[bot] authored Sep 14, 2022
1 parent ebd879b commit 1d12914
Show file tree
Hide file tree
Showing 106 changed files with 1,246 additions and 1,209 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
# Mean of Circular Quantities (MCQ)

Mean of Circular Quantities (MCQ) is a dissimilarity measure useful in comparison of 3D protein and/or RNA structures. It calculates an average difference between corresponding torsion angle values (rotations around bonds). More information can be found in:

> Zok, T., Popenda, M., & Szachniuk, M. (2014). MCQ4Structures to compute similarity of molecule structures. Central European Journal of Operations Research, 22(3), 457–473. https://doi.org/10.1007/s10100-013-0296-5
## Installation

```sh
git clone https://github.com/RNA-Puzzles/mcq-parent
cd mcq-parent
git submodule update --init
git clone https://github.com/tzok/mcq4structures.git
cd mcq4structures
mvn install
```

## Contents

This project consists of a few subprojets:

- `mcq-common`: base functionality
- `mcq-clustering`: partitional and hierarchical clustering
- `mcq-cli`: command-line interface
Expand Down
7 changes: 6 additions & 1 deletion mcq-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>pl.poznan.put</groupId>
<artifactId>mcq-parent</artifactId>
<version>1.7.0</version>
<version>1.8.0</version>
</parent>

<artifactId>mcq-cli</artifactId>
Expand Down Expand Up @@ -78,6 +78,11 @@

<build>
<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>com.github.ekryd.sortpom</groupId>
<artifactId>sortpom-maven-plugin</artifactId>
Expand Down
19 changes: 9 additions & 10 deletions mcq-cli/src/main/java/pl/poznan/put/mcq/cli/Global.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package pl.poznan.put.mcq.cli;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import me.tongfei.progressbar.ProgressBar;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
Expand Down Expand Up @@ -27,16 +36,6 @@
import pl.poznan.put.utility.svg.Format;
import pl.poznan.put.utility.svg.SVGHelper;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;

@SuppressWarnings("UseOfSystemOutOrSystemErr")
@Value.Immutable
public abstract class Global {
Expand Down
98 changes: 65 additions & 33 deletions mcq-cli/src/main/java/pl/poznan/put/mcq/cli/Helper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
package pl.poznan.put.mcq.cli;

import java.io.File;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
Expand All @@ -14,27 +28,18 @@
import pl.poznan.put.matching.SelectionQuery;
import pl.poznan.put.matching.StructureSelection;
import pl.poznan.put.pdb.PdbParsingException;
import pl.poznan.put.pdb.analysis.ImmutableDefaultResidueCollection;
import pl.poznan.put.pdb.analysis.ImmutablePdbCompactFragment;
import pl.poznan.put.pdb.analysis.MoleculeType;
import pl.poznan.put.pdb.analysis.PdbChain;
import pl.poznan.put.pdb.analysis.PdbCompactFragment;
import pl.poznan.put.pdb.analysis.PdbModel;
import pl.poznan.put.pdb.analysis.PdbResidue;
import pl.poznan.put.pdb.analysis.ResidueCollection;
import pl.poznan.put.rna.NucleotideTorsionAngle;
import pl.poznan.put.structure.StructureManager;
import pl.poznan.put.torsion.MasterTorsionAngleType;

import java.io.File;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

@Slf4j
final class Helper {
static final Option OPTION_TARGET =
Expand Down Expand Up @@ -72,7 +77,8 @@ final class Helper {
.numberOfArgs(1)
.desc(
String.format(
"Torsion angle types (separated by comma without space), select from: %s. Default is: %s",
"Torsion angle types (separated by comma without space), select from: %s. Default"
+ " is: %s",
Helper.arrayToString(NucleotideTorsionAngle.values()),
Helper.arrayToString(
MoleculeType.RNA.mainAngleTypes().toArray(new MasterTorsionAngleType[0]))))
Expand All @@ -94,9 +100,12 @@ final class Helper {
.build();
static final Option OPTION_RELAXED =
Option.builder("r")
.longOpt("relaxed")
.longOpt("relaxed-mode")
.numberOfArgs(1)
.desc(
"Turn on relaxed mode (process 3D models even in presence of bond lengths' violations and treat each chain as a compact fragment even with gaps)")
"Relaxed mode. 0 = (default) does not compare if any violation is found. 1 = only"
+ " compare models without violations. 2 = compare everything regardless of any"
+ " violations")
.build();
static final Option OPTION_MULTI_MODEL =
Option.builder("m")
Expand All @@ -120,8 +129,7 @@ static StructureSelection selectModel(final CommandLine commandLine) throws Pars
final String selectionQuery =
(String) commandLine.getParsedOptionValue(Helper.OPTION_SELECTION_MODEL.getOpt());
final String name = Helper.modelName(modelFile, model);
return Helper.select(
model, name, selectionQuery, commandLine.hasOption(Helper.OPTION_RELAXED.getOpt()));
return Helper.select(model, name, selectionQuery, Helper.parseRelaxedMode(commandLine));
}

static List<StructureSelection> selectModels(final CommandLine commandLine)
Expand All @@ -139,10 +147,7 @@ static List<StructureSelection> selectModels(final CommandLine commandLine)
final String name =
pathToName.getOrDefault(path, Helper.modelName(new File(path), model));
return Helper.select(
model,
name,
selectionQuery,
commandLine.hasOption(Helper.OPTION_RELAXED.getOpt()));
model, name, selectionQuery, Helper.parseRelaxedMode(commandLine));
})
.collect(Collectors.toList());
}
Expand All @@ -153,8 +158,7 @@ static StructureSelection selectTarget(final CommandLine commandLine) throws Par
final String selectionQuery =
(String) commandLine.getParsedOptionValue(Helper.OPTION_SELECTION_TARGET.getOpt());
final String name = Helper.modelName(targetFile, target);
return Helper.select(
target, name, selectionQuery, commandLine.hasOption(Helper.OPTION_RELAXED.getOpt()));
return Helper.select(target, name, selectionQuery, Helper.parseRelaxedMode(commandLine));
}

public static List<StructureSelection> loadMultiModelFile(final CommandLine commandLine)
Expand All @@ -166,7 +170,6 @@ public static List<StructureSelection> loadMultiModelFile(final CommandLine comm
Helper.OPTION_MULTI_MODEL.getOpt(), MultiModelMode.FIRST.name()));
final String query =
(String) commandLine.getParsedOptionValue(Helper.OPTION_SELECTION_TARGET.getOpt());
final boolean relaxedMode = commandLine.hasOption(Helper.OPTION_RELAXED.getOpt());

return Helper.loadStructures(modelFile, multiModelMode).stream()
.map(
Expand All @@ -179,7 +182,7 @@ public static List<StructureSelection> loadMultiModelFile(final CommandLine comm
Helper.modelName(modelFile, model),
model.modelNumber()),
query,
relaxedMode))
Helper.parseRelaxedMode(commandLine)))
.collect(Collectors.toList());
}

Expand Down Expand Up @@ -275,18 +278,33 @@ private static List<? extends PdbModel> loadStructures(
* @param structure A PDB structure.
* @param name Name of the structure to be displayed in final results.
* @param query An asterisk, empty string or selection query.
* @param relaxedMode If true, then each chain is treated as a single compact fragment (gaps are
* not taken into account).
* @param relaxedMode If relaxed mode is MEDIUM or FULL, then each chain is treated as a single
* compact fragment (gaps are not taken into account).
* @return A {@link StructureSelection} made on the given structure.
*/
private static StructureSelection select(
final PdbModel structure, final String name, final String query, final boolean relaxedMode) {
if (relaxedMode) {
return new StructureSelection(
name,
final PdbModel structure,
final String name,
final String query,
final Local.RelaxedMode relaxedMode) {
if (relaxedMode == Local.RelaxedMode.MEDIUM || relaxedMode == Local.RelaxedMode.FULL) {
final LinkedHashSet<String> uniqueChains =
structure.chains().stream()
.map(chain -> Helper.residueCollectionToCompactFragment(chain, name))
.collect(Collectors.toList()));
.map(PdbChain::identifier)
.collect(Collectors.toCollection(LinkedHashSet::new));
final List<PdbCompactFragment> compactFragments = new ArrayList<>();

for (final String uniqueChain : uniqueChains) {
final List<PdbResidue> chainResidues =
structure.residues().stream()
.filter(pdbResidue -> Objects.equals(uniqueChain, pdbResidue.chainIdentifier()))
.collect(Collectors.toList());
compactFragments.add(
Helper.residueCollectionToCompactFragment(
ImmutableDefaultResidueCollection.of(chainResidues), name));
}

return new StructureSelection(name, compactFragments);
}

if ("*".equals(query)) {
Expand Down Expand Up @@ -346,4 +364,18 @@ private static String getMessage(final String s) {
private static String formatMessage(final String s, final Object... objects) {
return MessageFormat.format(Helper.getMessage(s), objects);
}

public static Local.RelaxedMode parseRelaxedMode(final CommandLine commandLine) {
if (commandLine.hasOption(Helper.OPTION_RELAXED.getOpt())) {
final String optionValue = commandLine.getOptionValue(Helper.OPTION_RELAXED.getOpt());
if ("0".equals(optionValue)) {
return Local.RelaxedMode.NONE;
} else if ("1".equals(optionValue)) {
return Local.RelaxedMode.MEDIUM;
} else if ("2".equals(optionValue)) {
return Local.RelaxedMode.FULL;
}
}
return Local.RelaxedMode.NONE;
}
}
Loading

0 comments on commit 1d12914

Please sign in to comment.