Skip to content

Commit

Permalink
Merge pull request #107 from biocodellc/develop
Browse files Browse the repository at this point in the history
merge develop into master
  • Loading branch information
jdeck88 authored Mar 7, 2019
2 parents d8fa229 + 36f8875 commit fa22c0f
Show file tree
Hide file tree
Showing 13 changed files with 290 additions and 99 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
resources/geome_secrets.json
.gradle/
.build/
.idea/
build/
out/
9 changes: 5 additions & 4 deletions PluginVersions.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<PluginVersions>
<LatestVersion>3.0.8</LatestVersion>
<LatestVersionURL>https://github.com/biocodellc/biocode-lims/releases/download/3.0.8/BiocodePlugin_3_0_8.gplugin</LatestVersionURL>
<ReleaseNotes>==Biocode Plugin 3.0.8 - 12 February 2019==
* Fix GeOMe metadata updating
<LatestVersion>3.0.9</LatestVersion>
<LatestVersionURL>https://github.com/biocodellc/biocode-lims/releases/download/3.0.9/BiocodePlugin_3_0_9.gplugin</LatestVersionURL>
<ReleaseNotes>==Biocode Plugin 3.0.9 - 6 March 2019==
* Fix Project search bug
* Add Genbank Metadata data properties to results list for Geome
</ReleaseNotes>
<ExtraInformation/>
</PluginVersions>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ println "Gradle " + GradleVersion.current().getVersion() + ' - ' + GradleVersion
apply plugin: "java"
apply plugin: "idea"

version = '3.0.8'
version = '3.0.9'

defaultTasks 'createPlugin';

Expand Down
8 changes: 6 additions & 2 deletions doc/release_notes.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
==Biocode Plugin 3.0.8 - 12 February 12 2019==
==Biocode Plugin 3.0.9 - 6 March 2019==
* Fixed bug where queries on Geome Project were crashing application
* Added genbankCountry, genbankDate, and genbankLatLng to output data properties

==Biocode Plugin 3.0.8 - 12 February 2019==
* Fixed bug where sample data was not getting fetched, only cached data. This led to unpredictable FIMS data population

==Biocode Plugin 3.0.7 - 10 October 12 2018==
==Biocode Plugin 3.0.7 - 10 October 2018==
* set default geome fims instance to production.
* enable either production or develop geome to be called
* Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion src/com/biomatters/plugins/biocode/BiocodePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class BiocodePlugin extends GeneiousPlugin {
}

private static GeneiousActionOptions superBiocodeAction;
public static final String PLUGIN_VERSION = "3.0.8";
public static final String PLUGIN_VERSION = "3.0.9";
public static final String SUPPORT_EMAIL = "[email protected]";

public static GeneiousActionOptions getSuperBiocodeAction() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ private JsonNode getClientSecrets() throws DatabaseServiceException {
}

/**
* Retrieves the result of a REST method call to either the BiSciCol or Biocode-FIMS services.
* Retrieves the result of a REST method call to the GeOME server
*
* @param resultType The class of the entity that should be returned from the method
* @param response The response from the method call
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.biomatters.plugins.biocode.labbench.fims.FIMSConnection;
import com.biomatters.plugins.biocode.labbench.fims.FimsProject;
import com.biomatters.plugins.biocode.labbench.fims.TableFimsSample;
import com.google.api.client.repackaged.org.apache.commons.codec.binary.StringUtils;


import javax.ws.rs.client.Entity;
Expand All @@ -27,7 +28,7 @@

public class geomeFIMSConnection extends FIMSConnection {
private static final String HOST = "api.geome-db.org";
static final String GEOME_URL = "https://" + HOST;
public static final String GEOME_URL = "https://" + HOST;
private geomeFIMSClient client;

@Override
Expand Down Expand Up @@ -89,8 +90,11 @@ public void _connect(Options options) throws ConnectionException {
collectionAttributes.put(attribute.uri, attribute.asDocumentField());
}
}

}

} catch (Exception e) {

e.printStackTrace();
throw new ConnectionException("Unable to connect to GeOMe: " + e.getMessage());
}
Expand Down Expand Up @@ -130,9 +134,26 @@ public List<FimsProject> getProjects() throws DatabaseServiceException {
}

private static final DocumentField PROJECT_FIELD = new DocumentField("Project", "", "geomeProject", String.class, false, false);
private static final DocumentField GENBANK_COUNTRY_FIELD = new DocumentField("genbankCountry", "", "urn:genbankCountry", String.class, false, false);
private static final DocumentField GENBANK_DATE_FIELD = new DocumentField("genbankDate", "", "urn:genbankDate", String.class, false, false);
private static final DocumentField GENBANK_LATLNG_FIELD = new DocumentField("genbankLatLng", "", "urn:genbankLatLng", String.class, false, false);
// NOTE: the Genbank submission docs indicate empty attributes should be titled "misssing", however, geome commonlyl
// encodes this as "Unknown". To maintain consistency with Geome, we set the BLANK_ATTRIBUTE to "Unknown"
private static final String BLANK_ATTRIBUTE = "Unknown";


@Override
protected List<DocumentField> _getCollectionAttributes() {
List<DocumentField> result = new ArrayList<>(collectionAttributes.values());
result.removeAll(_getTaxonomyAttributes());
result.add(PROJECT_FIELD);
result.add(GENBANK_COUNTRY_FIELD);
result.add(GENBANK_DATE_FIELD);
result.add(GENBANK_LATLNG_FIELD);
return result;
}

protected List<DocumentField> _getLimitedCollectionAttributesForSearch() {
List<DocumentField> result = new ArrayList<>(collectionAttributes.values());
result.removeAll(_getTaxonomyAttributes());
result.add(PROJECT_FIELD);
Expand All @@ -148,7 +169,7 @@ protected List<DocumentField> _getTaxonomyAttributes() {
protected List<DocumentField> _getSearchAttributes() {
List<DocumentField> result = new ArrayList<>();
result.addAll(_getTaxonomyAttributes());
result.addAll(_getCollectionAttributes());
result.addAll(_getLimitedCollectionAttributesForSearch());
return result;
}

Expand Down Expand Up @@ -241,9 +262,8 @@ private Project getProjectFromSearchTerm(AdvancedSearchQueryTerm term) throws Co
throw new ConnectionException("Only Project queries with Contains are supported");
}
for (Project project : projects) {
// query either the project title or the project code
if (project.title.equals(term.getValues()[0]) ||
project.code.equals(term.getValues()[0])) {
// query the project title
if (project.title.equals(term.getValues()[0])) {
return project;
}

Expand Down Expand Up @@ -439,22 +459,27 @@ protected List<FimsSample> _retrieveSamplesForTissueIds(List<String> tissueIds,
private List<FimsSample> transformQueryResults(List<String> tissueIds, SearchResult result) throws ConnectionException {
List<FimsSample> samples = new ArrayList<>();

allAttributes.put("genbankCountry", GENBANK_COUNTRY_FIELD);
allAttributes.put("genbankDate", GENBANK_DATE_FIELD);
allAttributes.put("genbankLatLng", GENBANK_LATLNG_FIELD);

Map<String, DocumentField> attributesByName = new HashMap<>();
allAttributes.values().forEach(f -> attributesByName.put(f.getName(), f));

Map<String, Map<String, Object>> mappedTissues = mapResults(getTissueSampleDocumentField().getName(), result.content.Tissue);
Map<String, Map<String, Object>> mappedSamples = mapResults("materialSampleID", result.content.Sample);
Map<String, Map<String, Object>> mappedEvents = mapResults(EVENT_ID, result.content.Event);


for (String tissueId : tissueIds) {
Map<String, Object> valuesForTissue = mappedTissues.get(tissueId);

if (valuesForTissue != null) {
// Need to convert map from name -> value to uri -> value because that's what Geneious expects
Map<String, Object> valuesByCode = new HashMap<>();


BiConsumer<String, Object> storeByCode = (key, value) -> {

if (value == null || value instanceof String && value.toString().trim().length() == 0) {
return;
}
Expand All @@ -473,7 +498,9 @@ private List<FimsSample> transformQueryResults(List<String> tissueIds, SearchRes
} else {
valueToStore = value.toString();
}

valuesByCode.put(documentField.getCode(), valueToStore);

} catch (NumberFormatException e) {
System.out.println("Invalid value for " + documentField.getValueType() + " was " + value);
}
Expand All @@ -482,6 +509,8 @@ private List<FimsSample> transformQueryResults(List<String> tissueIds, SearchRes
// System.out.println("missing DocumentField for " + key);
}
};


valuesForTissue.forEach(storeByCode);
Object sampleId = valuesForTissue.get(allAttributes.get(SAMPLE_URN).getName());
String eventId = null;
Expand All @@ -498,6 +527,23 @@ private List<FimsSample> transformQueryResults(List<String> tissueIds, SearchRes
}

Map<String, Object> eventValues = mappedEvents.get(eventId);

eventValues.put("genbankCountry", getGenbankCountryValue(
(String) eventValues.get(allAttributes.get("urn:country").getName()),
(String) eventValues.get(allAttributes.get("urn:locality").getName())
));

eventValues.put("genbankLatLng", getGenbankLatLong(
(String) eventValues.get(allAttributes.get("urn:decimalLatitude").getName()),
(String) eventValues.get(allAttributes.get("urn:decimalLongitude").getName())
));

eventValues.put("genbankDate", getGenbankCollectionDate(
(String) eventValues.get(allAttributes.get("urn:yearCollected").getName()),
(String) eventValues.get(allAttributes.get("urn:monthCollected").getName()),
(String) eventValues.get(allAttributes.get("urn:dayCollected").getName())
));

if (eventValues != null) {
eventValues.forEach(storeByCode);
} else {
Expand Down Expand Up @@ -543,4 +589,125 @@ public boolean storesPlateAndWellInformation() {
public boolean hasPhotos() {
return false;
}

/**
* if both lat and long are present, return a string containing the abs(decimalDegree) + Compass Direction
* <p>
* ex.
* <p>
* lat = -8, long = 140 would return "8 S 140 W"
*/
private String getGenbankLatLong(String latText, String lngText) {
StringBuilder latLongSb = new StringBuilder();

if (!latText.equals("") &&
!lngText.equals("")) {

try {
Double lat = Double.parseDouble(latText);

if (lat < 0) {
latLongSb.append(Math.abs(lat)).append(" S");
} else {
latLongSb.append(lat).append(" N");
}

latLongSb.append(" ");

Double lng = Double.parseDouble(lngText);

if (lng < 0) {
latLongSb.append(Math.abs(lng)).append(" W");
} else {
latLongSb.append(lng).append(" E");
}
} catch (NumberFormatException e) {
latLongSb = new StringBuilder()
.append(latText)
.append(" ")
.append(lngText);
}
}

if (latLongSb.toString().equals("")) {
return BLANK_ATTRIBUTE;
} else {
return latLongSb.toString();
}
}

/**
* Format the genbank Country field
*
* @param country
* @param locality
*
* @return
*/
private String getGenbankCountryValue(String country, String locality) {
String genbankCountryValue = "";
// Assign the country portion of the Genbank country field
if (country != null) {
genbankCountryValue = country.trim();
}
// Assign the locality portion of the Genbank country field
if (locality != null &&
country != null &&
!locality.trim().equalsIgnoreCase(country.trim()) &&
!locality.trim().equals("")) {
// In some cases, the country name has already been mapped into the locality
// causing an unusual cascade of country names in the genbankCountry Field.
// This conditional statement attempts to catch and fix this situation.
if (locality.trim().startsWith(country.trim()) &&
!locality.trim().equalsIgnoreCase(country.trim())) {
// remove the country name
String tempLocalityField = locality.trim().replaceFirst(country.trim(), "");
// remove colons since they will be confusing in this context
tempLocalityField = tempLocalityField.replace(":","");
genbankCountryValue += ":" + tempLocalityField;
} else {
genbankCountryValue += ":" + locality.trim();
}
}
// Return the blank attribute if we do not have any content
if (genbankCountryValue.equals("")) {
return BLANK_ATTRIBUTE;
} else {
return genbankCountryValue;
}
}

/**
* Format the genbank collection date field
*
* @param yearCollected
* @param monthCollected
* @param dayCollected
*
* @return
*/
private String getGenbankCollectionDate(String yearCollected, String monthCollected, String dayCollected) {
StringBuilder collectionDate = new StringBuilder();

collectionDate.append(yearCollected);


if (monthCollected != null && !monthCollected.equals("")) {

collectionDate.append("-");
collectionDate.append(monthCollected);

if (dayCollected != null && !dayCollected.equals("")) {
collectionDate.append("-");
collectionDate.append(dayCollected);
}
}

if (collectionDate.toString().equals("")) {
return BLANK_ATTRIBUTE;
} else {
return collectionDate.toString();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ public void setPassword(String password) {
public boolean includePublicProjects() {
return includePublicProjectsOption.getValue();
}

public void setIncludePublicProjectsOption(Boolean publicOption) { includePublicProjectsOption.setValue(publicOption); }

public void setHostOption(String host) { this.hostOption.setValue(host); }
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public class NewPlateDocumentOperationTest extends LimsTestCase {
private static final String NINETY_SIX_WELL_PLATE_TYPE_VALUE = "96Plate";
private static final String THREE_HUNDRED_EIGHTY_FOUR_WELL_PLATE_TYPE_VALUE = "384Plate";

//TODO: Fix these tests which are failing due to Caused by: java.lang.IllegalArgumentException: Key too long: buttonVisibleView/Add Thermocycles:Create new Thermocycles, or view existing ones

/*
@Test
public void testCreateStripExtractionPlateFromStripExtractionPlate() throws DocumentOperationException, DatabaseServiceException, BadDataException {
for (int numberOfStrips = 1; numberOfStrips <= 6; numberOfStrips++) {
Expand Down Expand Up @@ -273,4 +277,5 @@ private static NewPlateOptions createNewPlateOptions(String reactionType, String
return newPlateOptions;
}
*/
}
Loading

0 comments on commit fa22c0f

Please sign in to comment.