Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy over src folder from atlas-web-core (sha: 05c86f0e91f222bde8a29ce56050d9eaf2c1c4d9) #1

Draft
wants to merge 36 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
83d524d
Copy over src folder from atlas-web-core (sha: 05c86f0e91f222bde8a29c…
ke4 Jan 17, 2025
f402285
Fix compilation errors and dependencies for uk.ac.ebi.atlas.util package
ke4 Jan 17, 2025
527b627
Fix compilation errors and dependencies for uk.ac.ebi.atlas.bioentity…
ke4 Jan 17, 2025
a7beb36
Fix compilation errors and dependencies for uk.ac.ebi.atlas.commons p…
ke4 Jan 17, 2025
af9a106
Fix compilation errors and dependencies for uk.ac.ebi.atlas.configura…
ke4 Jan 17, 2025
f71fae8
Fix comp. errors and deps for uk.ac.ebi.atlas.experimentimport package
ke4 Jan 17, 2025
25061c8
Fix comp. errors and deps for uk.ac.ebi.atlas.experimentpage package
ke4 Jan 17, 2025
84d9572
Fix comp. errors and deps for uk.ac.ebi.atlas.filters package
ke4 Jan 17, 2025
4dfbabb
Fix comp. errors and deps for uk.ac.ebi.atlas.model package
ke4 Jan 17, 2025
11b2c34
Fix comp. errors and deps for uk.ac.ebi.atlas.profile package
ke4 Jan 17, 2025
11ec98e
Fix comp. errors and deps for uk.ac.ebi.atlas.search package
ke4 Jan 18, 2025
65bde8e
Fix comp. errors and deps for uk.ac.ebi.atlas.solr package
ke4 Jan 18, 2025
42baa7b
Fix comp. errors and deps for uk.ac.ebi.atlas.species package
ke4 Jan 18, 2025
06e8eae
Fix comp. errors and deps for uk.ac.ebi.atlas.web package
ke4 Jan 18, 2025
3fc84a9
Add junit4 dependency for current tests
ke4 Jan 18, 2025
4e2dab1
Fix comp. errors and deps for tests in uk.ac.ebi.atlas.experimentimpo…
ke4 Jan 18, 2025
f89120c
Fix comp. errors and deps for tests in uk.ac.ebi.atlas.experimentpage…
ke4 Jan 20, 2025
6d7d210
Fix comp. errors and deps for tests in uk.ac.ebi.atlas.experiments pa…
ke4 Jan 20, 2025
73f4fdf
Fix comp. errors and deps for tests in uk.ac.ebi.atlas.home package
ke4 Jan 20, 2025
1627c2f
Fix comp. errors and deps for tests in uk.ac.ebi.atlas.model package
ke4 Jan 20, 2025
9ad916a
Fix comp. errors and deps for tests in uk.ac.ebi.atlas.monitoring pac…
ke4 Jan 20, 2025
eae2ae5
Fix comp. errors and deps for tests in uk.ac.ebi.atlas.search package
ke4 Jan 20, 2025
da4a948
Fix comp. errors and deps for tests in uk.ac.ebi.atlas.solr package
ke4 Jan 20, 2025
28c82c9
Fix comp. errors and deps for tests in uk.ac.ebi.atlas.species package
ke4 Jan 20, 2025
a97ff0a
Fix comp. errors and deps for tests in uk.ac.ebi.atlas.trader package
ke4 Jan 20, 2025
534c7a7
Fix comp. errors and deps for tests in uk.ac.ebi.atlas.utils package
ke4 Jan 20, 2025
7daea12
Fix comp. errors and deps for tests in uk.ac.ebi.atlas.web package
ke4 Jan 20, 2025
60478b6
Add back our artifactory repo for ae-efo-loader lib
ke4 Jan 20, 2025
3ba6efd
Replace remaining javax.servlet imports to files from jakarta.servlet…
ke4 Jan 20, 2025
898edee
Fix remaining @Inject --> @Autowired refactor
ke4 Jan 20, 2025
5022f77
Fix jetty related dependencies (downgrade for now to fix compilation)
ke4 Jan 20, 2025
ef7b7f6
Comment old assertThat code for now to be fixed later
ke4 Jan 20, 2025
513f08d
Add processing instructions for test resources
ke4 Jan 20, 2025
697f54b
Add default config values
ke4 Jan 20, 2025
51ba43b
Use java-conventions plugin for common dependencies
ke4 Jan 21, 2025
976ac5c
Fix comp. errors and deps for tests in uk.ac.ebi.atlas.experimentimpo…
ke4 Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
54 changes: 41 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
plugins {
id 'java'
id 'atlas-web-bulk.java-conventions'
id 'org.springframework.boot' version '3.4.1' apply false
id 'io.spring.dependency-management' version '1.1.7'
}

group = 'uk.ac.ebi.atlas'
version = '1.0-SNAPSHOT'

java {
sourceCompatibility = '17'
}

repositories {
mavenCentral()
}

dependencyManagement {
imports {
mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
Expand All @@ -23,10 +12,49 @@ dependencyManagement {

dependencies {
implementation 'org.springframework.boot:spring-boot'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-webflux'

implementation 'org.slf4j:slf4j-api'
implementation 'org.apache.commons:commons-lang3'
implementation 'org.apache.commons:commons-math:2.2'
implementation 'commons-io:commons-io:2.16.1'
implementation 'commons-beanutils:commons-beanutils:1.9.4'
implementation 'commons-jxpath:commons-jxpath:1.3'
implementation 'io.atlassian.util.concurrent:atlassian-util-concurrent:4.0.1'
implementation 'com.google.guava:guava'
implementation 'com.google.code.gson:gson'
implementation 'com.google.auto.value:auto-value-annotations:1.11.0'
annotationProcessor 'com.google.auto.value:auto-value:1.11.0'
implementation 'com.fasterxml.jackson.core:jackson-databind'

implementation 'org.eclipse.jdt:org.eclipse.jdt.annotation:2.3.0'
implementation 'org.eclipse.jetty:jetty-http:9.4.27.v20200227'
implementation 'org.eclipse.jetty:jetty-io:9.4.27.v20200227'
implementation 'org.eclipse.jetty:jetty-client:9.4.27.v20200227'
implementation 'org.eclipse.jetty:jetty-util:9.4.27.v20200227'

implementation 'joda-time:joda-time:2.10.10'

implementation 'au.com.bytecode:opencsv:2.4'

implementation ('org.apache.solr:solr-core:8.7.0') {
exclude group: 'org.apache.logging.log4j', module: 'log4j-slf4j-impl'
}

implementation 'uk.ac.ebi.fg:ae-efo-loader:1.0.5'

compileOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'io.projectreactor:reactor-test'
testImplementation platform('org.junit:junit-bom:5.10.0')
testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.hamcrest:java-hamcrest:2.0.0.0'
testImplementation 'org.assertj:assertj-guava'
// For JUnit 4 tests
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine'
testImplementation 'junit:junit:4.12'
}

tasks.withType(JavaCompile).configureEach {
Expand All @@ -35,4 +63,4 @@ tasks.withType(JavaCompile).configureEach {

test {
useJUnitPlatform()
}
}
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dataFilesLocation = /atlas-data
experimentFilesLocation = /atlas-data/exp
experimentDesignLocation = /atlas-data/expdesign
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package uk.ac.ebi.atlas.bioentity.geneset;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import uk.ac.ebi.atlas.bioentity.go.GoPoTrader;
import uk.ac.ebi.atlas.bioentity.interpro.InterProTrader;
import uk.ac.ebi.atlas.model.OntologyTerm;
import uk.ac.ebi.atlas.solr.bioentities.BioentityPropertyName;
import uk.ac.ebi.atlas.utils.ReactomeClient;

import java.util.List;
import java.util.Map;
import java.util.Set;

import static uk.ac.ebi.atlas.solr.bioentities.BioentityPropertyName.DESCRIPTION;
import static uk.ac.ebi.atlas.solr.bioentities.BioentityPropertyName.GO;
import static uk.ac.ebi.atlas.solr.bioentities.BioentityPropertyName.INTERPRO;
import static uk.ac.ebi.atlas.solr.bioentities.BioentityPropertyName.PATHWAYID;
import static uk.ac.ebi.atlas.solr.bioentities.BioentityPropertyName.PO;

@Profile("!cli")
@Component
public class GeneSetPropertyService {
private final GoPoTrader goPoTermTrader;
private final InterProTrader interProTermTrader;
private final ReactomeClient reactomeClient;

public GeneSetPropertyService(GoPoTrader goPoTermTrader,
InterProTrader interProTermTrader,
ReactomeClient reactomeClient) {
this.goPoTermTrader = goPoTermTrader;
this.interProTermTrader = interProTermTrader;
this.reactomeClient = reactomeClient;
}

public static final List<BioentityPropertyName> ALL =
ImmutableList.of(PATHWAYID, GO, PO, INTERPRO);

public Map<BioentityPropertyName, Set<String>> propertyValuesByType(String identifier, boolean isPlant) {
identifier = identifier.toUpperCase();

if (GeneSetUtil.matchesReactomeID(identifier)) {
if (isPlant) {
return propertyValuesByType(
PATHWAYID, identifier, reactomeClient.getPlantPathwayName(identifier).orElse(""));
} else {
return propertyValuesByType(
PATHWAYID, identifier, reactomeClient.getPathwayName(identifier).orElse(""));
}
} else if (GeneSetUtil.matchesGeneOntologyAccession(identifier)) {
return propertyValuesByType(
GO, identifier, goPoTermTrader.get(identifier).map(OntologyTerm::name).orElse(""));
} else if (GeneSetUtil.matchesPlantOntologyAccession(identifier)) {
return propertyValuesByType(
PO, identifier, goPoTermTrader.get(identifier).map(OntologyTerm::name).orElse(""));
} else if (GeneSetUtil.matchesInterProAccession(identifier)) {
return propertyValuesByType(
INTERPRO, identifier, interProTermTrader.get(identifier).map(OntologyTerm::name).orElse(""));
} else {
return ImmutableMap.of();
}
}

private Map<BioentityPropertyName, Set<String>> propertyValuesByType(BioentityPropertyName which,
String identifier, String value) {
return ImmutableMap.of(which, ImmutableSet.of(identifier), DESCRIPTION, ImmutableSet.of(value));
}
}
65 changes: 65 additions & 0 deletions src/main/java/uk/ac/ebi/atlas/bioentity/geneset/GeneSetUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package uk.ac.ebi.atlas.bioentity.geneset;

import uk.ac.ebi.atlas.search.SemanticQuery;
import uk.ac.ebi.atlas.search.SemanticQueryTerm;

import java.util.regex.Pattern;

public class GeneSetUtil {
private static final Pattern GO_REGEX = Pattern.compile("GO:\\d+", Pattern.CASE_INSENSITIVE);
private static final Pattern PO_REGEX = Pattern.compile("PO:\\d+", Pattern.CASE_INSENSITIVE);
private static final Pattern REACTOME_REGEX = Pattern.compile("R-[A-Z]{3}-\\d+", Pattern.CASE_INSENSITIVE);
private static final Pattern INTER_PRO_REGEX = Pattern.compile("IPR" + "(\\d)+", Pattern.CASE_INSENSITIVE);
private static final Pattern PLANT_REACTOME_REGEX = Pattern.compile("[\\d]+", Pattern.CASE_INSENSITIVE);

private static final String GO_CATEGORY = "go";
private static final String PO_CATEGORY = "po";
private static final String REACTOME_CATEGORY = "pathwayid";
private static final String INTERPRO_CATEGORY = "interpro";

protected GeneSetUtil() {
throw new UnsupportedOperationException();
}

public static boolean matchesInterProAccession(String identifier) {
return INTER_PRO_REGEX.matcher(identifier).matches();
}

public static boolean matchesGeneOntologyAccession(String identifier) {
return GO_REGEX.matcher(identifier).matches();
}

public static boolean matchesPlantOntologyAccession(String identifier) {
return PO_REGEX.matcher(identifier).matches();
}

public static boolean matchesReactomeID(String identifier) {
return REACTOME_REGEX.matcher(identifier).matches();
}

public static boolean matchesPlantReactomeID(String identifier) {
return PLANT_REACTOME_REGEX.matcher(identifier).matches();
}

public static boolean matchesGeneSetAccession(String identifier) {
return matchesReactomeID(identifier) || matchesInterProAccession(identifier) ||
matchesGeneOntologyAccession(identifier) || matchesPlantOntologyAccession(identifier) ||
matchesPlantReactomeID(identifier);
}

private static boolean hasGeneSetCategory(String category) {
return category.equalsIgnoreCase(GO_CATEGORY) || category.equalsIgnoreCase(PO_CATEGORY) ||
category.equalsIgnoreCase(REACTOME_CATEGORY) || category.equalsIgnoreCase(INTERPRO_CATEGORY);
}

public static boolean matchesGeneSetCategoryOrGeneSetValue(SemanticQuery geneQuery) {
if (geneQuery.isEmpty() || geneQuery.size() > 1) {
return false;
}

SemanticQueryTerm term = geneQuery.iterator().next();
return term.category().isPresent() ?
hasGeneSetCategory(term.category().get()) :
matchesGeneSetAccession(term.value());
}
}
38 changes: 38 additions & 0 deletions src/main/java/uk/ac/ebi/atlas/bioentity/go/GoPoTrader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package uk.ac.ebi.atlas.bioentity.go;

import au.com.bytecode.opencsv.CSVReader;
import com.google.common.collect.ImmutableMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import uk.ac.ebi.atlas.model.OntologyTerm;
import uk.ac.ebi.atlas.utils.CsvReaderFactory;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Path;
import java.util.Optional;

@Profile("!cli")
@Component
public class GoPoTrader {
private static final Logger LOGGER = LoggerFactory.getLogger(GoPoTrader.class);
private final ImmutableMap<String, OntologyTerm> accessionToTerm;

public GoPoTrader(Path goPoFilePath) {
try (CSVReader tsvReader = CsvReaderFactory.createForTsv(goPoFilePath.toString())) {
accessionToTerm = new GoPoTsvParser(tsvReader).parse();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

public Optional<OntologyTerm> get(String accession) {
if (accessionToTerm.get(accession) == null) {
LOGGER.warn("Unable to find GO/PO accession {}", accession);
}

return Optional.ofNullable(accessionToTerm.get(accession));
}
}
76 changes: 76 additions & 0 deletions src/main/java/uk/ac/ebi/atlas/bioentity/go/GoPoTsvParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package uk.ac.ebi.atlas.bioentity.go;

import au.com.bytecode.opencsv.CSVReader;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMultimap;
import uk.ac.ebi.atlas.model.OntologyTerm;

import java.io.IOException;
import java.util.Collection;

public class GoPoTsvParser {

private static final String[] VALID_PREFIXES = {"GO:", "PO:"};

private static final int TERM_ACCESSION_COLUMN_INDEX = 0;
private static final int TERM_NAME_COLUMN_INDEX = 1;
private static final int TERM_DEPTH_COLUMN_INDEX = 2;
public static final int DEFAULT_DEPTH = 1;

private final CSVReader csvReader;

public GoPoTsvParser(CSVReader csvReader) {
this.csvReader = csvReader;
}

ImmutableMap<String, OntologyTerm> parse() throws IOException {

String startsWithGoPoRegex = "^(" + Joiner.on("|").join(VALID_PREFIXES) + ").+";

ImmutableMultimap.Builder<String, OntologyTerm> multimapBuilder = ImmutableMultimap.builder();
String[] line;
while ((line = csvReader.readNext()) != null) {
if (line.length > TERM_ACCESSION_COLUMN_INDEX) {
String accession = line[TERM_ACCESSION_COLUMN_INDEX];
if (accession.matches(startsWithGoPoRegex)) {
String name = line.length > TERM_NAME_COLUMN_INDEX ? line[TERM_NAME_COLUMN_INDEX] : "";
int depth = parseDepth(line);
multimapBuilder.put(accession, OntologyTerm.create(accession, name, "", depth));
}
}
}
ImmutableMultimap<String, OntologyTerm> accessionToGoPoTerms = multimapBuilder.build();


ImmutableMap.Builder<String, OntologyTerm> mapBuilder = ImmutableMap.builder();
for (String accession : accessionToGoPoTerms.keySet()) {

int minDepth = minDepthOfTerms(accessionToGoPoTerms.get(accession));
String name = accessionToGoPoTerms.get(accession).iterator().next().name();

mapBuilder.put(accession, OntologyTerm.create(accession, name, "", minDepth));
}

return mapBuilder.build();
}

private int minDepthOfTerms(Collection<OntologyTerm> terms) {
int minDepth = Integer.MAX_VALUE;
for (OntologyTerm term : terms) {
minDepth = term.depth() < minDepth ? term.depth() : minDepth;
}
return minDepth;
}

private int parseDepth(String[] line) {
try {
return line.length > TERM_DEPTH_COLUMN_INDEX ?
Integer.parseInt(line[TERM_DEPTH_COLUMN_INDEX]) :
DEFAULT_DEPTH;
} catch (NumberFormatException e) {
return DEFAULT_DEPTH;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package uk.ac.ebi.atlas.bioentity.interpro;

import com.google.common.collect.ImmutableMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import uk.ac.ebi.atlas.commons.readers.TsvStreamer;
import uk.ac.ebi.atlas.model.OntologyTerm;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;

@Profile("!cli")
@Component
public class InterProTrader {
private static final Logger LOGGER = LoggerFactory.getLogger(InterProTrader.class);
private final ImmutableMap<String, OntologyTerm> accessionToTerm;

public InterProTrader(Path interProFilePath) {
try (TsvStreamer tsvStreamer =
new TsvStreamer(Files.newBufferedReader(interProFilePath, StandardCharsets.UTF_8))) {
accessionToTerm = InterProTsvParser.parse(tsvStreamer);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

public Optional<OntologyTerm> get(String accession) {
if (accessionToTerm.get(accession) == null) {
LOGGER.warn("Unable to find InterPro accession {}", accession);
}

return Optional.ofNullable(accessionToTerm.get(accession));
}
}
Loading