Skip to content

Commit

Permalink
Merge branch 'p2rank-2-4' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rdk committed Sep 9, 2024
2 parents d1cade7 + 1101acc commit e39ffe5
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 16 deletions.
18 changes: 13 additions & 5 deletions src/main/groovy/cz/siret/prank/domain/Dataset.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class Dataset implements Parametrized, Writable, Failable {
static final String COLUMN_CONSERVATION_FILES_PATTERN = "conservation_files_pattern"
static final String COLUMN_APO_PROTEIN = "apo_protein"
static final String COLUMN_APO_CHAINS = "apo_chains"
static final String COLUMN_POSITIVE_RESIDUES = "positive_residues"

static final List<String> DEFAULT_HEADER = [ COLUMN_PROTEIN ]

Expand Down Expand Up @@ -423,7 +424,7 @@ class Dataset implements Parametrized, Writable, Failable {
* @return true if explicit residue labeling is defined a as a part of th dataset
*/
boolean hasExplicitResidueLabeling() {
return attributes.containsKey(PARAM_RESIDUE_LABELING_FORMAT)
return attributes.containsKey(PARAM_RESIDUE_LABELING_FORMAT) || header.contains(COLUMN_POSITIVE_RESIDUES)
}

/**
Expand All @@ -438,9 +439,16 @@ class Dataset implements Parametrized, Writable, Failable {
*/
@Nullable
ResidueLabeler getResidueLabeler() {

if (residueLabeler == null && hasExplicitResidueLabeling()) {
String labelingFile = dir + "/" + attributes.get(PARAM_RESIDUE_LABELING_FILE)
residueLabeler = ResidueLabeler.loadFromFile(attributes.get(PARAM_RESIDUE_LABELING_FORMAT), labelingFile)

if (header.contains(COLUMN_POSITIVE_RESIDUES)) {

} else {
String labelingFile = dir + "/" + attributes.get(PARAM_RESIDUE_LABELING_FILE)
residueLabeler = ResidueLabeler.loadFromFile(attributes.get(PARAM_RESIDUE_LABELING_FORMAT), labelingFile)
}

}
return residueLabeler
}
Expand Down Expand Up @@ -883,7 +891,7 @@ class Dataset implements Parametrized, Writable, Failable {
@Nullable
BinaryLabeling getExplicitBinaryLabeling() {
if (originDataset.hasExplicitResidueLabeling()) {
return originDataset.explicitBinaryResidueLabeler.getBinaryLabeling(protein.residues, protein)
return originDataset.explicitBinaryResidueLabeler.getBinaryLabeling(protein.residues, protein, this)
}
return null
}
Expand All @@ -893,7 +901,7 @@ class Dataset implements Parametrized, Writable, Failable {
*/
@Nullable
BinaryLabeling getBinaryLabeling() {
return originDataset.binaryResidueLabeler.getBinaryLabeling(protein.residues, protein)
return originDataset.binaryResidueLabeler.getBinaryLabeling(protein.residues, protein, this)
}

ProcessedItemContext getContext() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package cz.siret.prank.domain.labeling

import cz.siret.prank.domain.Dataset
import cz.siret.prank.domain.Protein
import cz.siret.prank.domain.Residue
import cz.siret.prank.domain.Residues
import cz.siret.prank.utils.Sutils
import cz.siret.prank.utils.Writable
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j

/**
*
*/
@Slf4j
@CompileStatic
class ColumnBasedResidueLabeler extends ResidueLabeler<Boolean> implements Writable {

@Override
ResidueLabeling<Boolean> labelResidues(Residues residues, Protein protein, Dataset.Item item) {

Set<String> positives = Sutils.split(item.columnValues.get(Dataset.COLUMN_POSITIVE_RESIDUES), ',').toSet()

return createLabelingFromPositiveResidueCodes(residues, positives)
}

@Override
boolean isBinary() {
return true
}

@Override
ResidueLabeling<Double> getDoubleLabeling() {
return null
}

//===========================================================================================================//

static ResidueLabeling<Boolean> createLabelingFromPositiveResidueCodes(Residues residues, Set<String> positives) {
ResidueLabeling<Boolean> labeling = new ResidueLabeling<Boolean>()

for (Residue residue : residues) {
boolean label = positives.contains(residue.toString())
labeling.add(residue, label)
}

return labeling
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cz.siret.prank.domain.labeling


import cz.siret.prank.domain.Dataset
import cz.siret.prank.domain.Protein
import cz.siret.prank.domain.Residue
import cz.siret.prank.domain.Residues
Expand All @@ -22,7 +22,7 @@ class LigandBasedResidueLabeler extends ResidueLabeler<Boolean> implements Param
ResidueLabeling<Double> lastLigandDistanceLabeling

@Override
ResidueLabeling<Boolean> labelResidues(Residues residues, Protein protein) {
ResidueLabeling<Boolean> labelResidues(Residues residues, Protein protein, Dataset.Item item) {

ResidueLabeling<Double> ligandDistanceLabeling = new ResidueLabeling<>(residues.count)
for (Residue res : residues) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cz.siret.prank.domain.labeling

import cz.siret.prank.domain.Dataset
import cz.siret.prank.domain.Protein
import cz.siret.prank.domain.Residue
import cz.siret.prank.domain.Residues
Expand Down Expand Up @@ -83,7 +84,7 @@ class ModelBasedResidueLabeler extends ResidueLabeler<Boolean> implements Parame
}

@Override
ResidueLabeling<Boolean> labelResidues(Residues residues, Protein protein) {
ResidueLabeling<Boolean> labelResidues(Residues residues, Protein protein, Dataset.Item item) {

ModelBasedPointLabeler predictor = new ModelBasedPointLabeler(model, context).withObserved(observedPoints)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cz.siret.prank.domain.labeling


import cz.siret.prank.domain.Dataset
import cz.siret.prank.domain.Protein
import cz.siret.prank.domain.Residues
import cz.siret.prank.program.PrankException
Expand All @@ -14,23 +14,27 @@ import javax.annotation.Nullable
@CompileStatic
abstract class ResidueLabeler<L> {

abstract ResidueLabeling<L> labelResidues(Residues residues, Protein protein)
abstract ResidueLabeling<L> labelResidues(Residues residues, Protein protein, Dataset.Item item)

abstract boolean isBinary()

@Nullable
abstract ResidueLabeling<Double> getDoubleLabeling()

BinaryLabeling getBinaryLabeling(Residues residues, Protein protein) {
BinaryLabeling getBinaryLabeling(Residues residues, Protein protein, @Nullable Dataset.Item item) {
if (isBinary()) {
(BinaryLabeling) labelResidues(residues, protein)
(BinaryLabeling) labelResidues(residues, protein, item)
} else {
throw new PrankException("Residue labeler not binary!")
}
}

BinaryLabeling getBinaryLabeling(Residues residues, Protein protein) {
return getBinaryLabeling(residues, protein, null)
}

BinaryLabeling getBinaryLabeling(Protein protein) {
getBinaryLabeling(protein.residues, protein)
getBinaryLabeling(protein.residues, protein, null)
}

static ResidueLabeler loadFromFile(String format, String fname) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ class SprintLabelingLoader extends ResidueLabeler<Boolean> implements Writable {
}

@Override
ResidueLabeling<Boolean> labelResidues(Residues residues, Protein protein) {
ResidueLabeling<Boolean> labelResidues(Residues residues, Protein protein, Dataset.Item item) {

Map<Residue.Key, Boolean> labelMap = new HashMap<>()



boolean foundOneChain = false
for (ResidueChain chain : protein.residueChains) {
String chainCode = toElementCode(protein, chain)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ abstract class StaticResidueLabeler extends ResidueLabeler<Boolean> implements W
}

@Override
ResidueLabeling<Boolean> labelResidues(Residues residues, Protein protein) {
ResidueLabeling<Boolean> labelResidues(Residues residues, Protein protein, Dataset.Item item) {

Map<String, Double> scores = new HashMap<>()
for (String line : Futils.readLines(path).tail()) {
Expand Down

0 comments on commit e39ffe5

Please sign in to comment.