Package: py-fasta-validator
py_fasta_validatorA Python extension of thefasta validatorThis is a Python C-extension to validate a fasta file. It only checks a few things, and by default only sets its response via the return code, so you will need to check that in your Python code. See the examples provided.The simple rules that we adhere to are:Each header line starts with a>. The header preceedes the sequence.Every other line is considered a sequence lineSequence lines may not contain whitespace, numbers, or non-sequence characters. In other words, they must only contain the characters [A-Z] and [a-z]Sequence lines can end with a new line or return depending on whether you have edited this file on a mac, pc, or linux machine.Sequence lines can be empty.The sequence identifier is the string of characters in the header line following the>and upto the first whitespace. Everything after the first whitespace is descriptive, and can be as long as you likeEach sequence identifier must be unique within the fasta file.We will exit with the following return codes:0this is a valid fasta file1the first line does not start with a > (rule 1 violated).2there are duplicate sequence identifiers in the file (rule 7 violated)4there are characters in a sequence line other than [A-Za-z]Other exit codes (e.g. 255, 254, etc) indicate internal errors in the program.Running py_fasta_validatorThe installation now also includes a command line application,py_fasta_validatorthat you can run. See the Testing section below!You can also import FastaValidator directly:importFastaValidatorreturn_code=FastaValidator.fasta_validator(file_name)InstallationEveryoneRecommended:Install with conda. This is the easiest way to installpy_fasta_validatorand the recommended method:conda install -c bioconda py_fasta_validatorAlternate method:Install with pip:pip install py-fasta-validatorAdvancedPrerequisitesIf you install using one the methods above you don't need to worry about the prerequistes, they are already included!fasta validatoris written in ANSI C but you will also need the Python developers toolkit (e.g. python-3.x-dev installed on your machine to provide Python.h)To clone the code from GitHub use:gitclonehttps://github.com/linsalrob/fasta_validator.gitcdfasta_validatorTo build the code, use:makeThis should compile the source into an executable in the current working directory.Please note, if you get an error like this:gcc  -Wall -o fasta_validate ./fasta_validate.c -I/usr/include/python3.8 -I/usr/include/x86_64-linux-gnu/python3.8
/usr/bin/ld: /tmp/ccgvrFaq.o: in function `python_input':
fasta_validate.c:(.text+0x481): undefined reference to `PyArg_ParseTuple'
/usr/bin/ld: fasta_validate.c:(.text+0x48c): undefined reference to `PyExc_RuntimeError'
/usr/bin/ld: fasta_validate.c:(.text+0x49b): undefined reference to `PyErr_SetString'
/usr/bin/ld: fasta_validate.c:(.text+0x4c3): undefined reference to `PyLong_FromLong'
/usr/bin/ld: /tmp/ccgvrFaq.o: in function `PyInit_fastaValidator':
fasta_validate.c:(.text+0x4f2): undefined reference to `PyModule_Create2'
collect2: error: ld returned 1 exit status
make: *** [Makefile:9: all] Error 1Then we need to append the version of python to themakecommand. I am (currently) runningpython3.8and the command to compile without error is:make CFLAGS=-lpython3.8I don't know the exact cause of this error, butpkg-config --libs python3is not reporting anything when it should report-lpython3.8To install this code as root (sudo) you can use:makeinstalland this will copy the executable to/usr/local/bin.to install it as a user, just copy the compiled binaryfasta_validateto somewhere on your path.TestingTo test the code you can use the example data provided. Download thetest data set[zip file, 16.4 kb] and uncompress it.$ for FASTA in test/*fasta; do echo $FASTA; py_fasta_validator -f $FASTA; echo "Exit code: $?"; doneThis will output the name of the fasta file, the output, and the exit code from the process:test/code.fasta
test/code.fasta has non-sequence characters in it
Exit code: 4
test/duplicates_no_spaces.fasta
test/duplicates_no_spaces.fasta has multiple sequences with the same identifier
Exit code: 2
test/duplicates_with_spaces.fasta
test/duplicates_with_spaces.fasta has multiple sequences with the same identifier
Exit code: 2
test/good.fasta
Exit code: 0
test/good_mixed.fasta
Exit code: 0
test/good_multiline.fasta
Exit code: 0
test/no_first_line.fasta
test/no_first_line.fasta does not start with a >
Exit code: 1
test/space.fasta
test/space.fasta has non-sequence characters in it
Exit code: 4Developing/TestingNote, if you are developing and testing in a conda environment, you might run into an error like:./fasta_validate: error while loading shared libraries: libpython3.11.so.1.0: cannot open shared object file: No such file or directoryYou need to make sure thatLD_LIBRARY_PATHis set to your/lib/in your conda environment.For example:$./fasta_validate
./fasta_validate:errorwhileloadingsharedlibraries:libpython3.11.so.1.0:cannotopensharedobjectfile:Nosuchfileordirectory
$mambainstall-ypython-devtools
$whichpython
~/miniconda3/envs/py_fasta/bin/python
$exportLD_LIBRARY_PATH_OLD=$LD_LIBRARY_PATH# make a back up of the original LD_LIBRARY_PATH, just in case!$exportLD_LIBRARY_PATH=$HOME/miniconda3/envs/py_fasta/lib/:$LD_LIBRARY_PATH# set the new library path$./fasta_validate./fasta_validate[-v][fastafile]Note: to make this change permanent you should set the$LD_LIBRARY_PATHvariable (and the copy) inetc/conda/activate.d/env_vars.shandetc/conda/deactivate.d/env_vars.shasdescribed in the docsCitationPlease cite this asEdwards, R.A. 2019. fasta_validate: a fast and efficient fasta validator written in pure C. DOI: 10.5281/zenodo.2532044What is the difference between this andfasta_validator?Not very much!The original C code was written for theSearch SRAproject as we wanted to validate fasta files uploaded by users. That code is written in C, and does not require any additional libraries to install.This version adds the Python hooks, and so it requires the Python development library to be installed. Therefore, we kept them as two separate projects, although you'll notice the C code is essentially the same!LicenseThis software is released using theMIT License