deepakkumar96 / biovalidator

a library to validate biological data formats

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BioValidator master build status

BioValidator is a schema validator that validates biological file format like Fasta, GFF, etc. Currently, it only supports Fasta file format

Usage

The most simple way to validate supported file types is to use ValidatorHelper provided by library.
Example: Arguments in the below validate method

  1. filename: absolute file path
  2. validator-type: type of validator
  3. isStrict: whether to validate in strict mode or permissive
ValidationResult validationResult = ValidatorHelper.validate("filepath", ValidatorType.FASTA, true);
OR
ValidationResult validationResult = ValidatorHelper.validate("filepath", "fasta-dna", true);
OR
ValidationResult validationResult = ValidatorHelper.validateFasta("filepath");

Check whether file is valid or not:

assertTrue(validationResult.isValid());

If file contain errors or warnings:

if (!validationResult.isValid()) {
    validationResult.getErrorMessages().forEach(System.out::println);
    validationResult.getWarningMessages().forEach(System.out::println);
}

Validation Result Customization

Validator's behaviour and result and can be easily customize, ValidatorBuilder can be used to customize behaviour and result of the validator.
Example: To validate a file by disabling warnings and continue validation even if error occurred

Validator validator = ValidatorBuilder.withFile("path", "fasta-protein")
        .disableWarnings()
        .enableErrors()
        .disableStopAtFirstError()
        .build();

assertTrue(validator.validate().isValid());
OR
validator.validate(result -> {
    assertTrue(result.isValid());
})

Construct a raw validator:

String dnaSequence = "> seqId | header name\nACTGACTGACTG";

InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(dnaSequence.getBytes()));
Validator validator = new FastaValidator(isr, SequenceType.DNA);
ValidationResult result = validator.validate();

assertTrue(result.isValid());

Using biovalidator in your application

Maven dependency

<dependency>
  <groupId>org.intermine</groupId>
  <artifactId>biovalidator</artifactId>
  <version>0.1.2</version>
  <type>pom</type>
</dependency>

Gradle dependency

compile 'org.intermine:biovalidator:0.1.2'

Using biovalidator as a command line utility

Step 1: Get biovalidator Fat-Jar(either build from source or dirctly download from bintray

  • Build from source : $ ./gradlew createFatJar

    • this will generate a jar named 'biovalidator-fat-x.x.x.jar' in 'build/libs' directory
  • Or Download fat-jar version of biovalidator from bintray

Setp 2: run as an executable jar file

java -jar biovalidator-fat-0.1.2.jar --help

BioValidator Documentation

Documentation about BioValidator uses and validation rules: https://github.com/intermine/biovalidator/wiki

About

a library to validate biological data formats

License:MIT License


Languages

Language:Java 100.0%