Skip to content

dimebemer/dna-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

DNA API

Services for DNA operations.

Requirements

  • Java 8
  • Maven
  • Python 3.7 (for AWS Lambda function)

Notes

API

  • This API is hosted by AWS Elastic Beanstalk. Host URI can be found in the next section.

  • A few extra, non-specified endpoints (POST /humans and GET /dnas/{id}) were added.

DNA Stats with AWS Lambda

  • Aggregate DNA stats are provided by an AWS Lambda function, with Python script code. This Lambda is triggered by any update to the Dna DynamoDB table, and will shift count stats on INSERT and REMOVE events. (There's no endpoint for removal, but it was kept this way in order to make testing easier.)

  • Since aggregate data is generated by a Lambda, eventual consistency should be expected for DNA stats. In my tests, however, data seemed to have always been updated almost in real time.

  • The Python function can be found at src/main/resources/dna-stats-aggregator.py

  • Ratio will be null when there are 0 humans registered (no division by zero allowed).

Simian Algorithm

  • The Simian Algorithm is inside the DnaCategorizer class, as a private method.

  • The method takes a List<String> rather than a String[] as a parameter for consistency - specially since converting this List to an Array and then to a Char Matrix (as the algorithm does) could slightly impact performance.

  • The algorithm will search for at least 2 sequences of 4 equal letters for it to be considered a Simian. Since it wasn't stated that those sequences should be distinct, repeated sequences will also be considered (e.g. 2 sequences of AAAA).

Tests

  • SpringBoot's default integration test is annotated with @Ignore due to AWS access keys not being hardcoded in properties. These are input as environment variables. Still, test coverage will be above 80% lines of code as required.

Endpoints

GET /dnas/{id}

Returns any DNA by ID.

Example

GET /dnas/2dfbc2b5-163e-36e4-a0fc-30bd5b534426

Response:

{
    "dna_id": "2dfbc2b5-163e-36e4-a0fc-30bd5b534426",
    "category": "HUMAN",
    "dna": [
        "TTGCGA",
        "CAGTGC",
        "TTATGT",
        "AGAGGA",
        "CCCTTA",
        "TCACTG"
    ]
}

POST /dnas/simians

Creates DNA for a Simian. Returns the new resource.

Example

POST /dnas/simians

Body:

{
	"dna": ["ATGCGA", "CAGTGC", "TTATGT", "AAAAGG", "CCCCTA", "TCCCTG"]
}

Response:

{
    "dna_id": "asdfs878-163e-36e4-a0fc-asdf7s8df8",
    "category": "SIMIAN",
    "dna": [
        "ATGCGA", 
        "CAGTGC", 
        "TTATGT", 
        "AAAAGG", 
        "CCCCTA", 
        "TCCCTG"
    ]
}

POST /dnas/humans

Creates DNA for a Human. Returns the new resource.

Example

POST /dnas/humans

Body:

{
	"dna": ["TTGCGA", "CAGTGC", "TTATGT", "AGAGGA", "CCCTTA", "TCACTG"]
}

Response:

{
    "dna_id": "2dfbc2b5-163e-36e4-a0fc-30bd5b534426",
    "category": "HUMAN",
    "dna": [
        "TTGCGA",
        "CAGTGC",
        "TTATGT",
        "AGAGGA",
        "CCCTTA",
        "TCACTG"
    ]
}

GET /dnas/stats

Returns DNA Stats to count simians, humans and ratio of simians per humans. Ratio should be presented with a scale of 4.

Note: Eventual consistency should be expected.

Example

GET /dnas/stats

Response:

{
    "count_mutant_dna": 2,
    "count_human_dna": 3,
    "ratio": 0.6667
}

About

DNA API by Rafael Bemerguy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published