Skip to content

Commit

Permalink
ENH: warn if IDs don't meet the "recommendations for identifiers" des…
Browse files Browse the repository at this point in the history
…cribed in the QIIME 2 Metadata file format docs. (#96)

Fixes #93.
  • Loading branch information
jairideout authored Feb 14, 2018
1 parent 83fdfe6 commit b3fa4c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

**Note on versioning:** the version numbers used here match the version numbers displayed to users in the Chrome Web Store. Sometimes there are gaps between release versions (e.g., version 2 jumps to version 5). This happens because each separate upload of Keemei to the web store increments the version number, and sometimes multiple uploads are necessary before a release is finalized (e.g., if the release is reviewed by an add-ons advisor and updates are required before it can go public). Therefore, the version numbering used here in the changelog and tagged GitHub releases will match the public release version displayed in the web store.

## Development version

### Features
* Warn if IDs don't meet the "recommendations for identifiers" described in the [QIIME 2](https://qiime2.org) metadata file format documentation.

## Version 18 (2018-02-14)

This release adds support for validating the new [QIIME 2](https://qiime2.org) metadata file format available in the project's `2018.2` release.
Expand Down
13 changes: 13 additions & 0 deletions src/Qiime2Format.gs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ var Q2COLUMNTYPES_ = {
// Credit: https://stackoverflow.com/a/4703508/3776794
var NUMERICREGEX_ = /^[-+]?(?:(?:\d*\.\d+)|(?:\d+\.?))(?:[Ee][+-]?\d+)?$/;

// Recommended ID regex based on "Recommendations for Identifiers" in QIIME 2 Metadata file format docs.
// Tested at https://regexr.com/
var RECOMMENDEDIDREGEX_ = /^[a-zA-Z0-9.\-]{1,36}$/;

function validateQiime2_() {
var startTime = Date.now();

Expand Down Expand Up @@ -313,6 +317,15 @@ function validateQ2Data_(validationResults, sheetData, dataIdx, header, headerId
ids[id] = true;
}

// Warn if ID doesn't meet the "recommended identifiers" requirements in the QIIME 2 Metadata file format docs.
if (!RECOMMENDEDIDREGEX_.test(id)) {
var position = [i, 0];
var message = ["ID doesn't meet the recommendations for choosing identifiers described in the QIIME 2 metadata documentation. IDs are recommended to have the following attributes:"];
message.push("- IDs should be 36 characters long or less.");
message.push("- IDs should contain only ASCII alphanumeric characters (i.e. in the range of [a-z], [A-Z], or [0-9]), the period (.) character, or the dash (-) character.");
addCellWarning_(validationResults, position, message);
}

// Now that the ID is validated, check that the other values in the row can be converted to numbers
// if they are declared to be numeric. Also check that values don't overflow past the header's length.
for (var j = 1; j < row.length; j++) {
Expand Down

0 comments on commit b3fa4c8

Please sign in to comment.