Skip to content

Commit 675de58

Browse files
committed
Prior to this change,
This change
1 parent 5568ac1 commit 675de58

File tree

6 files changed

+130
-89
lines changed

6 files changed

+130
-89
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Enumerated sequence feature service.
66
[![Build Status](https://travis-ci.org/nmdp-bioinformatics/service-feature.svg?branch=master)](https://travis-ci.org/nmdp-bioinformatics/service-feature)
77

88

9-
###Hacking service-feature
9+
### Hacking service-feature
1010

1111
Install
1212

@@ -16,3 +16,7 @@ Install
1616
To build
1717

1818
$ mvn install
19+
20+
Documentation
21+
22+
[Wiki](https://github.com/nmdp-bioinformatics/service-feature/wiki) has extensive documentation on usage and deployment.

docker/docker-compose-dev.yml

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ featuredb:
1717
environment:
1818
MYSQL_DATABASE: feature
1919
MYSQL_ROOT_PASSWORD: supersecretpwd
20-
# If using Docker Toolbox, ssh into your vm and make a /data directory
21-
# before using this docker-compose file.
2220
volumes:
2321
- data:/var/lib/mysql
2422

2523
phpmyadmin:
26-
image: phpmyadmin/phpmyadmin
24+
image: phpmyadmin/phpmyadmin:5.1
2725
container_name: myadmin
2826
environment:
2927
- PMA_ARBITRARY=1

pom.xml

+77-72
Original file line numberDiff line numberDiff line change
@@ -21,79 +21,84 @@
2121
> http://www.gnu.org/licenses/lgpl.html
2222
2323
-->
24-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
25-
<modelVersion>4.0.0</modelVersion>
26-
<parent>
27-
<groupId>org.nmdp.service</groupId>
28-
<artifactId>service-parent</artifactId>
29-
<version>2</version>
30-
</parent>
31-
<groupId>org.nmdp.service</groupId>
32-
<artifactId>feature-multimodule</artifactId>
33-
<version>1.0.9-SNAPSHOT</version>
34-
<packaging>pom</packaging>
35-
<name>feature-multimodule</name>
36-
<url>https://github.com/nmdp-bioinformatics/service-feature</url>
37-
<description>Enumerated sequence feature service.</description>
38-
<inceptionYear>2014</inceptionYear>
39-
<scm>
40-
<connection>scm:git:[email protected]:nmdp-bioinformatics/service-feature.git</connection>
41-
<developerConnection>scm:git:[email protected]:nmdp-bioinformatics/service-feature.git</developerConnection>
42-
<url>[email protected]:nmdp-bioinformatics/service-feature.git</url>
43-
</scm>
44-
<licenses>
45-
<license>
46-
<name>GNU Lesser General Public License (LGPL)</name>
47-
<url>http://www.gnu.org/licenses/lgpl.html</url>
48-
<distribution>repo</distribution>
49-
</license>
50-
</licenses>
51-
<developers>
52-
<developer>
53-
<id>mheuer-nmdp</id>
54-
<name>Michael Heuer (NMDP)</name>
55-
</developer>
56-
</developers>
57-
<modules>
58-
<module>domain</module>
59-
<module>service</module>
60-
<module>service-impl</module>
61-
<module>service-jdbi</module>
62-
<module>resource</module>
63-
<module>dropwizard</module>
64-
<module>dropwizard-jdbi</module>
65-
<module>client</module>
66-
<module>tools</module>
67-
</modules>
68-
<dependencyManagement>
69-
<dependencies>
70-
<dependency>
71-
<groupId>mysql</groupId>
72-
<artifactId>mysql-connector-java</artifactId>
73-
<version>5.1.35</version>
74-
</dependency>
75-
<dependency>
76-
<groupId>org.dishevelled</groupId>
77-
<artifactId>dsh-compress</artifactId>
78-
<version>1.1</version>
79-
</dependency>
80-
<dependency>
81-
<groupId>org.dishevelled</groupId>
82-
<artifactId>dsh-commandline</artifactId>
83-
<version>1.1</version>
84-
</dependency>
85-
<dependency>
86-
<groupId>org.dishevelled</groupId>
87-
<artifactId>dsh-multi-map</artifactId>
88-
<version>1.0</version>
89-
</dependency>
90-
<dependency>
24+
<project xmlns="http://maven.apache.org/POM/4.0.0"
25+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
26+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
27+
<modelVersion>4.0.0</modelVersion>
28+
<parent>
9129
<groupId>org.nmdp.service</groupId>
92-
<artifactId>common-dropwizard</artifactId>
93-
<version>1.0</version>
94-
</dependency>
95-
</dependencies>
96-
</dependencyManagement>
30+
<artifactId>service-parent</artifactId>
31+
<version>2</version>
32+
</parent>
33+
<artifactId>feature-multimodule</artifactId>
34+
<version>1.0.9-SNAPSHOT</version>
35+
<packaging>pom</packaging>
36+
<name>feature-multimodule</name>
37+
<url>https://github.com/nmdp-bioinformatics/service-feature</url>
38+
<description>Enumerated sequence feature service.</description>
39+
<inceptionYear>2014</inceptionYear>
40+
<scm>
41+
<connection>
42+
scm:git:[email protected]:nmdp-bioinformatics/service-feature.git
43+
</connection>
44+
<developerConnection>
45+
scm:git:[email protected]:nmdp-bioinformatics/service-feature.git
46+
</developerConnection>
47+
<url>[email protected]:nmdp-bioinformatics/service-feature.git</url>
48+
</scm>
49+
<licenses>
50+
<license>
51+
<name>GNU Lesser General Public License (LGPL)</name>
52+
<url>http://www.gnu.org/licenses/lgpl.html</url>
53+
<distribution>repo</distribution>
54+
</license>
55+
</licenses>
56+
<developers>
57+
<developer>
58+
<id>mheuer-nmdp</id>
59+
<name>Michael Heuer (NMDP)</name>
60+
</developer>
61+
</developers>
62+
<modules>
63+
<module>domain</module>
64+
<module>service</module>
65+
<module>service-impl</module>
66+
<module>service-jdbi</module>
67+
<module>resource</module>
68+
<module>dropwizard</module>
69+
<module>dropwizard-jdbi</module>
70+
<module>client</module>
71+
<module>tools</module>
72+
</modules>
73+
<dependencyManagement>
74+
<dependencies>
75+
<dependency>
76+
<groupId>mysql</groupId>
77+
<artifactId>mysql-connector-java</artifactId>
78+
<version>5.1.49</version>
79+
</dependency>
80+
<dependency>
81+
<groupId>org.dishevelled</groupId>
82+
<artifactId>dsh-compress</artifactId>
83+
<version>1.1</version>
84+
</dependency>
85+
<dependency>
86+
<groupId>org.dishevelled</groupId>
87+
<artifactId>dsh-commandline</artifactId>
88+
<version>1.1</version>
89+
</dependency>
90+
<dependency>
91+
<groupId>org.dishevelled</groupId>
92+
<artifactId>dsh-multi-map</artifactId>
93+
<version>1.0</version>
94+
</dependency>
95+
<dependency>
96+
<groupId>org.nmdp.service</groupId>
97+
<artifactId>common-dropwizard</artifactId>
98+
<version>1.0</version>
99+
</dependency>
100+
</dependencies>
101+
</dependencyManagement>
97102
</project>
98103

99104

service-jdbi/src/main/java/org/nmdp/service/feature/service/jdbi/JdbiFeatureService.java

+33-11
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,20 @@
2222
*/
2323
package org.nmdp.service.feature.service.jdbi;
2424

25-
import static com.google.common.base.Preconditions.checkArgument;
26-
import static com.google.common.base.Preconditions.checkNotNull;
27-
28-
import java.util.List;
29-
30-
import javax.annotation.concurrent.Immutable;
31-
3225
import com.google.inject.Inject;
33-
3426
import org.nmdp.service.feature.Feature;
35-
3627
import org.nmdp.service.feature.service.DnaAlphabet;
3728
import org.nmdp.service.feature.service.FeatureService;
38-
3929
import org.slf4j.Logger;
4030
import org.slf4j.LoggerFactory;
4131

32+
import javax.annotation.concurrent.Immutable;
33+
import java.sql.SQLIntegrityConstraintViolationException;
34+
import java.util.List;
35+
36+
import static com.google.common.base.Preconditions.checkArgument;
37+
import static com.google.common.base.Preconditions.checkNotNull;
38+
4239
/**
4340
* JDBI feature service.
4441
*/
@@ -47,6 +44,8 @@ final class JdbiFeatureService implements FeatureService {
4744
private final FeatureDao featureDao;
4845
private static final Logger logger = LoggerFactory.getLogger(JdbiFeatureService.class);
4946

47+
private static final int MAX_INSERT_FEATURE_TRIES = 10;
48+
5049
@Inject
5150
JdbiFeatureService(final FeatureDao featureDao) {
5251
checkNotNull(featureDao);
@@ -111,7 +110,30 @@ public Feature createFeature(final String locus,
111110
if (logger.isTraceEnabled()) {
112111
logger.trace("next accession locusId " + locusId + " termId " + termId + " rank " + rank);
113112
}
114-
long featureId = insertFeature(locusId, termId, rank, accession, sequenceId);
113+
114+
int insertTries = 0;
115+
long featureId = 0;
116+
do {
117+
insertTries++;
118+
try {
119+
featureId = insertFeature(locusId, termId, rank, accession, sequenceId);
120+
} catch (RuntimeException se) {
121+
if (se.getCause() instanceof SQLIntegrityConstraintViolationException) {
122+
logger.warn(se.getCause().getMessage());
123+
// Try next accession number
124+
accession = featureDao.nextAccession(locusId, termId, rank);
125+
logger.info("Retrying with a new accession number");
126+
// Give up after trying for MAX_INSERT_FEATURE_TRIES
127+
if (insertTries == MAX_INSERT_FEATURE_TRIES) {
128+
logger.warn("Giving up after " + MAX_INSERT_FEATURE_TRIES +
129+
" tries to get a new accession number");
130+
throw se;
131+
}
132+
} else {
133+
throw se;
134+
}
135+
}
136+
} while (featureId < 1);
115137

116138
if (logger.isTraceEnabled()) {
117139
logger.trace("finding feature by featureId " + featureId);

service-jdbi/src/main/sql/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Database Setup
2+
3+
See [Data Import](https://github.com/nmdp-bioinformatics/service-feature/wiki/Data-import) page on wiki for full details.
4+
5+
Run the SQL files in the following order to initialize the database.
6+
```
7+
mysql-drop.sql
8+
mysql-create.sql
9+
mysql-load-imgt-hla.sql
10+
mysql-load-hgnc.sql
11+
mysql-load-sequence-ontology.sql
12+
```

service-jdbi/src/main/sql/mysql-create.sql

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ create table if not exists `feature` (
3333
`sequence_id` bigint not null,
3434
`accession` bigint not null,
3535
primary key (`feature_id`),
36-
index (`locus_id`,`term_id`,`rank`,`accession`),
37-
index (`locus_id`,`term_id`,`rank`,`sequence_id`),
36+
unique key `unique_feature` (`locus_id`,`term_id`,`rank`,`accession`),
37+
index feature_sequence (`locus_id`,`term_id`,`rank`,`sequence_id`),
3838
constraint foreign key (`locus_id`) references locus (`locus_id`),
3939
constraint foreign key (`term_id`) references term (`term_id`),
4040
constraint foreign key (`sequence_id`) references sequence (`sequence_id`)

0 commit comments

Comments
 (0)