-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0061fe4
commit 118dbf4
Showing
6 changed files
with
253 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Description | ||
|
||
Each of us inherits from our biological parents a set of chemical instructions known as DNA that influence how our bodies are constructed. | ||
All known life depends on DNA! | ||
|
||
> Note: You do not need to understand anything about nucleotides or DNA to complete this exercise. | ||
DNA is a long chain of other chemicals and the most important are the four nucleotides, adenine, cytosine, guanine and thymine. | ||
A single DNA chain can contain billions of these four nucleotides and the order in which they occur is important! | ||
We call the order of these nucleotides in a bit of DNA a "DNA sequence". | ||
|
||
We represent a DNA sequence as an ordered collection of these four nucleotides and a common way to do that is with a string of characters such as "ATTACG" for a DNA sequence of 6 nucleotides. | ||
'A' for adenine, 'C' for cytosine, 'G' for guanine, and 'T' for thymine. | ||
|
||
Given a string representing a DNA sequence, count how many of each nucleotide is present. | ||
If the string contains characters that aren't A, C, G, or T then it is invalid and you should signal an error. | ||
|
||
For example: | ||
|
||
```text | ||
"GATTACA" -> 'A': 3, 'C': 1, 'G': 1, 'T': 2 | ||
"INVALID" -> error | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
@echo off | ||
SETLOCAL EnableDelayedExpansion | ||
|
||
call :macro | ||
|
||
REM TODO: Need to cleanup the code | ||
|
||
set "string=%~1" | ||
|
||
REM set "string=G" | ||
REM set "string=GGGGGGG" | ||
REM set "string=AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC" | ||
|
||
echo -%string%- | ||
|
||
%getlen% %string% | ||
set /a "len[0]=length" | ||
|
||
for %%i in (A C G T) do ( | ||
set "string=!string:%%i=!" | ||
%getlen% !string! | ||
set /a "c+=1", "d=c - 1" | ||
set /a "len[!c!]=length" | ||
set /a "%%i_difference=len[!d!] - len[!c!]" | ||
) | ||
|
||
if !T_difference! equ 0 ( | ||
set /a "T_difference=len[4]" | ||
set "len[4]=0" | ||
) | ||
|
||
echo !A_difference!,!C_difference!,!G_difference!,!T_difference! | ||
|
||
goto end | ||
|
||
:macro | ||
(set \n=^^^ | ||
%= This creates an escaped Line Feed - DO NOT ALTER =% | ||
) | ||
|
||
set getlen=for %%# in (1 2) do if %%#==2 ( for %%1 in (^^!args^^!) do (%\n% | ||
set "str=X%%~1" ^& set "length=0" ^& for /l %%b in (10,-1,0) do set /a "length|=1<<%%b" ^& for %%c in (^^!length^^!) do if "^!str:~%%c,1^!" equ "" set /a "length&=~1<<%%b"%\n% | ||
)) else set args= | ||
goto :eof | ||
|
||
:end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"authors": ["IcarusLivesHF", "GroophyLifefor"], | ||
"files": { | ||
"solution": [ | ||
"NucleotideCount.bat" | ||
], | ||
"test": [ | ||
"NucleotideCountTest.bat" | ||
], | ||
"example": [ | ||
".meta/Example.bat" | ||
] | ||
}, | ||
"blurb": "Given a DNA string, compute how many times each nucleotide occurs in the string.", | ||
"source": "The Calculating DNA Nucleotides_problem at Rosalind", | ||
"source_url": "https://rosalind.info/problems/dna/" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# This is an auto-generated file. | ||
# | ||
# Regenerating this file via `configlet sync` will: | ||
# - Recreate every `description` key/value pair | ||
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications | ||
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) | ||
# - Preserve any other key/value pair | ||
# | ||
# As user-added comments (using the # character) will be removed when this file | ||
# is regenerated, comments can be added via a `comment` key. | ||
|
||
[af9ffe10-dc13-42d8-a742-e7bdafac449d] | ||
description = "Say Hi!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
@echo off | ||
SETLOCAL EnableDelayedExpansion | ||
|
||
call :macro | ||
|
||
REM TODO: Need to cleanup the code | ||
|
||
set "string=%~1" | ||
|
||
REM set "string=G" | ||
REM set "string=GGGGGGG" | ||
REM set "string=AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC" | ||
|
||
%getlen% %string% | ||
set /a "len[0]=length" | ||
|
||
for %%i in (A C G T) do ( | ||
set "string=!string:%%i=!" | ||
%getlen% !string! | ||
set /a "c+=1", "d=c - 1" | ||
set /a "len[!c!]=length" | ||
set /a "%%i_difference=len[!d!] - len[!c!]" | ||
) | ||
|
||
if !T_difference! equ 0 ( | ||
set /a "T_difference=len[4]" | ||
set "len[4]=0" | ||
) | ||
|
||
echo !A_difference!,!C_difference!,!G_difference!,!T_difference! | ||
echo Invalid nucleotide in strand = !len[4]! = !string! | ||
|
||
goto end | ||
|
||
:macro | ||
(set \n=^^^ | ||
%= This creates an escaped Line Feed - DO NOT ALTER =% | ||
) | ||
|
||
set getlen=for %%# in (1 2) do if %%#==2 ( for %%1 in (^^!args^^!) do (%\n% | ||
set "str=X%%~1" ^& set "length=0" ^& for /l %%b in (10,-1,0) do set /a "length|=1<<%%b" ^& for %%c in (^^!length^^!) do if "^!str:~%%c,1^!" equ "" set /a "length&=~1<<%%b"%\n% | ||
)) else set args= | ||
goto :eof | ||
|
||
:end |
109 changes: 109 additions & 0 deletions
109
exercises/practice/nucleotide-count/NucleotideCountTest.bat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
@echo off | ||
REM --------------------------------------------------- | ||
REM NucleotideCount Unit Testing | ||
REM --------------------------------------------------- | ||
|
||
:Main | ||
REM Initalize result variable | ||
set "slug=NucleotideCount" | ||
|
||
CALL :Initialize | ||
|
||
REM -------------------- | ||
REM Test Case Start \/\/ | ||
REM Resource: https://github.com/exercism/problem-specifications/blob/ce02684e726a1b78a1c1e591188e4e268fd27b15/exercises/nucleotide-count/canonical-data.json | ||
REM -------------------- | ||
set "expected=0,0,0,0" | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: empty strand. (expected: %expected%, actually: %stdout%^)" | ||
CALL :Assert "" | ||
|
||
set "expected=0,0,1,0" | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: can count one nucleotide in single-character input. (expected: %expected%, actually: %stdout%^)" | ||
CALL :Assert "G" | ||
|
||
set "expected=0,0,7,0" | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: strand with repeated nucleotide. (expected: %expected%, actually: %stdout%^)" | ||
CALL :Assert "GGGGGGG" | ||
|
||
set "expected=20,12,17,21" | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: strand with multiple nucleotides. (expected: %expected%, actually: %stdout%^)" | ||
CALL :Assert "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC" | ||
|
||
set "expected=Invalid nucleotide in strand" | ||
set "if_success=Test passed" | ||
set "if_failed=Test failed: strand with invalid nucleotides - Print just 'Invalid nucleotide in strand'. (expected: %expected%, actually: %stdout%^)" | ||
CALL :Assert "AGXXACT" | ||
|
||
REM -------------------- | ||
REM Test Case End /\/\/\ | ||
REM -------------------- | ||
|
||
CALL :ResolveStatus | ||
exit /b %errorlevel% | ||
REM End of Main | ||
|
||
REM --------------------------------------------------- | ||
REM Assert [..Parameters(up to 9)] | ||
REM --------------------------------------------------- | ||
GOTO :End REM Prevents the code below from being executed | ||
:Assert | ||
set "stdout=" | ||
|
||
REM Run the program and capture the output then delete the file | ||
CALL %slug%.bat %~1 %~2 %~3 %~4 %~5 %~6 %~7 %~8 %~9 > stdout.bin 2>&1 | ||
set /p stdout=<stdout.bin | ||
del stdout.bin | ||
|
||
REM Check if the result is correct | ||
if "%stdout%" == "%expected%" ( | ||
if defined if_success ( | ||
echo %if_success% | ||
|
||
REM Reset the variable to avoid duplicating the message. | ||
set "if_success=" | ||
set "if_failed=" | ||
) | ||
|
||
REM If the result is correct, exit with code 0 | ||
set /a successCount+=1 | ||
exit /b 0 | ||
) else ( | ||
if defined if_failed ( | ||
echo %if_failed% | ||
|
||
REM Reset the variable to avoid duplicating the message. | ||
set "if_success=" | ||
set "if_failed=" | ||
) | ||
|
||
REM If the result is incorrect, exit with code 1 | ||
set /a failCount+=1 | ||
exit /b 1 | ||
) | ||
GOTO :EOF REM Go back to the line after the call to :Assert | ||
|
||
:Initialize | ||
REM It's for initialize, not about checking empty file | ||
set "successCount=0" | ||
set "failCount=0" | ||
GOTO :EOF REM Go back to the line after the call to :CheckEmptyFile | ||
|
||
:ResolveStatus | ||
set "status=" | ||
if %failCount% gtr 0 ( | ||
REM status: Fail | ||
REM message: The test failed. | ||
exit /b 1 | ||
|
||
) else ( | ||
REM status: Pass | ||
exit /b 0 | ||
|
||
) | ||
GOTO :EOF REM Go back to the line after the call to :ExportResultAsJson | ||
|
||
:End |