Package: fastapy
fastapyA lightweight Python package to read and write sequence records inFASTA format.The design was inspired by the utility of BioPython’s SeqIO, which supports many sequence formats. This repo focuses only on FASTA records. It is faster than BioPython, can handle compressed FASTA files (gzip, bzip2, zip), and has no Python package dependencies.RequirementsPython >= 3.8InstallationYou can installfastapyfromPyPI:pipinstallfastapyor directly from GitHub:pipinstall"git+https://github.com/aziele/fastapy.git"You can also usefastapywithout installation since it doesn't have any dependencies. Simply clone or download this repository and you're ready to use it.gitclonehttps://github.com/aziele/fastapy.gitcdfastapy
python
>>>importfastapy
>>>fastapy.__doc__'A lightweight Python module to read and write FASTA sequence records'Quick StartTypical usage is to read a FASTA file and loop over the sequences record(s).importfastapyforrecordinfastapy.parse('test/test.fasta'):print(record.id,len(record),record.seq[:10],record.desc)Output:NP_002433.1  362   METDAPQPGL   RNA-binding protein Musashi homolog 1 [Homo sapiens]
ENO94161.1    79   MKLLISGLGP   RRM domain-containing RNA-binding protein
sequence     292   MKLSKIALMMUsageThis module contains theRecordclass representing a FASTA sequence record and theparse()function to read FASTA records from a file.Record objectRecord is an object that contains information on a FASTA sequence record, including id, description, and the sequence itself.importfastapyrecord=fastapy.Record(id='NP_950171.2',seq='MEEEAETEEQQRFSYQQRLKAAVHYTVGCLCEEVALDKEMQFSKQTIAAISELTFRQCENFAKDLEMFASICRKRQE',desc='APITD1-CORT protein isoform 2 [Homo sapiens]')print(record.id)# NP_950171.2print(record.desc)# APITD1-CORT protein isoform 2 [Homo sapiens]print(record.seq)# MEEEAE..print(record.description)# >NP_950171.2 G APITD1-CORT protein isoform 2 [Homo sapiens]print(len(record))# 77print('EEEA'inrecord)# TrueBy default, the sequence line is wrapped to 70 characters. You can provide the line length. Use zero (or None) for no wrapping.print(record)# >NP_950171.2 APITD1-CORT protein isoform 2 [Homo sapiens]# MEEEAETEEQQRFSYQQRLKAAVHYTVGCLCEEVALDKEMQFSKQTIAAISELTFRQCENFAKDLEMFAS# ICRKRQEprint(record.format(wrap=30))# >NP_001382951.1 G protein subunit gamma 5 [Homo sapiens]# MEEEAETEEQQRFSYQQRLKAAVHYTVGCL# CEEVALDKEMQFSKQTIAAISELTFRQCEN# FAKDLEMFASICRKRQEprint(record.format(wrap=None))# >NP_950171.2 APITD1-CORT protein isoform 2 [Homo sapiens]# MEEEAETEEQQRFSYQQRLKAAVHYTVGCLCEEVALDKEMQFSKQTIAAISELTFRQCENFAKDLEMFASICRKRQEparseTheparse()function is a generator to read FASTA records asRecordobjects one by one from a file (plain FASTA or compressed using gzip or bzip2). Because only one record is created at a time, very little memory is required.importfastapyforrecordinfastapy.parse('test/test.fasta.gz'):print(record.id)For some tasks you may need to have a reusable access to the records. For this purpose, you can use the built-in Pythonlist()function to turn the iterator into a list:importfastapyrecords=list(fastapy.parse('test/test.fasta.gz'))print(records[0].id)# First recordprint(records[-1].id)# Last recordAnother common task is to index your records by sequence identifier. Useto_dict()to turn a Record iterator (or list) into a dictionary.importfastapyrecords=fastapy.to_dict(fasta.parse('test/test.fasta.gz'))print(records['NP_002433.1'])# Use any record idreadTheread()function reads only the first FASTA record from a file. It does not read any subsequent records in the file.importfastapyseq_record=fastapy.read('test/test.fasta')print(seq_record.id)# NP_002433.1TestYou can run tests to ensure that the module works as expected../test/test.pyLicenseGNU General Public License, version 3