Package: pyfastx
Citation:Lianming Du, Qin Liu, Zhenxin Fan, Jie Tang, Xiuyue Zhang, Megan Price, Bisong Yue, Kelei Zhao. Pyfastx: a robust Python package for fast random access to sequences from plain and gzipped FASTA/Q files. Briefings in Bioinformatics, 2021, 22(4):bbaa368.Table of ContentsIntroductionFeaturesInstallationFASTXFASTA sequences iterationFASTQ reads iterationFASTARead FASTA fileFASTA records iterationGet FASTA informationGet longest and shortest sequenceCalculate N50 and L50Get sequence mean and median lengthGet sequence countsGet subsequencesKey functionSequenceGet a sequence from FASTAGet sequence informationSequence sliceReverse and complement sequenceRead sequence line by lineSearch for subsequenceFastaKeysGet keysSort keysFilter keysFASTQRead FASTQ fileFASTQ records iterationGet FASTQ informationReadGet read from FASTQGet read informationFastqKeysGet fastq keysCommand line interfaceBuild indexShow statistics informationSplit FASTA/Q fileConvert FASTQ to FASTA fileGet subsequence with regionSample sequencesExtract sequencesDrawbacksTestingAcknowledgementsIntroductionThepyfastxis a lightweight Python C extension that enables users to randomly access to sequences from plain andgzippedFASTA/Q files. This module aims to provide simple APIs for users to extract seqeunce from FASTA and reads from FASTQ by identifier and index number. Thepyfastxwill build indexes stored in a sqlite3 database file for random access to avoid consuming excessive amount of memory. In addition, thepyfastxcan parse standard (sequence is spread into multiple lines with same length) and nonstandard (sequence is spread into one or more lines with different length) FASTA format. This module usedkseq.hwritten by@attractivechaosinklibproject to parse plain FASTA/Q file and zran.c written by@pauldmccarthyin projectindexed_gzipto index gzipped file for random access.This project was heavily inspired by@mdshw5’s projectpyfaidxand@brentp’s projectpyfasta.FeaturesSingle file for the Python extensionLightweight, memory efficient for parsing FASTA/Q fileFast random access to sequences fromgzippedFASTA/Q fileRead sequences from FASTA file line by lineCalculate N50 and L50 of sequences in FASTA fileCalculate GC content and nucleotides compositionExtract reverse, complement and antisense sequencesExcellent compatibility, support for parsing nonstandard FASTA fileSupport for FASTQ quality score conversionProvide command line interface for splitting FASTA/Q fileInstallationCurrently,pyfastxsupports Python 3.6, 3.7, 3.8, 3.9, 3.10, 3.11. Make sure you have installed bothpipand Python before starting.You can installpyfastxvia the Python Package Index (PyPI)pip install pyfastxUpdatepyfastxmodulepip install -U pyfastxFASTXNew inpyfastx0.8.0.Pyfastx provide a simple and fast python binding for kseq.h to iterate over sequences or reads in fasta/q file. The FASTX object will automatically detect the input sequence format (fasta or fastq) to return different tuple.FASTA sequences iterationWhen iterating over sequences on FASTX object, a tuple(name, seq)will be returned.>>>fa=pyfastx.Fastx('tests/data/test.fa.gz')>>>forname,seqinfa:>>>print(name)>>>print(seq)>>>#always output uppercase sequence>>>foriteminpyfastx.Fastx('tests/data/test.fa',uppercase=True):>>>print(item)>>>#Manually specify sequence format>>>foriteminpyfastx.Fastx('tests/data/test.fa',format="fasta"):>>>print(item)If you want the sequence comment, you can set comment to True, New inpyfastx0.9.0.>>>fa=pyfastx.Fastx('tests/data/test.fa.gz',comment=True)>>>forname,seq,commentinfa:>>>print(name)>>>print(seq)>>>print(comment)The comment is the content of header line after the first white space or tab character.FASTQ reads iterationWhen iterating over reads on FASTX object, a tuple(name, seq, qual)will be returned.>>>fq=pyfastx.Fastx('tests/data/test.fq.gz')>>>forname,seq,qualinfq:>>>print(name)>>>print(seq)>>>print(qual)If you want the read comment, you can set comment to True, New inpyfastx0.9.0.>>>fq=pyfastx.Fastx('tests/data/test.fq.gz',comment=True)>>>forname,seq,qual,commentinfq:>>>print(name)>>>print(seq)>>>print(qual)>>>print(comment)The comment is the content of header line after the first white space or tab character.FASTARead FASTA fileRead plain or gzipped FASTA file and build index, support for random access to FASTA.>>>importpyfastx>>>fa=pyfastx.Fasta('test/data/test.fa.gz')>>>fa<Fasta>test/data/test.fa.gzcontains211seqsNoteBuilding index may take some times. The time required to build index depends on the size of FASTA file. If index built, you can randomly access to any sequences in FASTA file. The index file can be reused to save time when you read seqeunces from FASTA file next time.FASTA records iterationThe fastest way to iterate plain or gzipped FASTA file without building index, the iteration will return a tuple contains name and sequence.>>>importpyfastx>>>forname,seqinpyfastx.Fasta('test/data/test.fa.gz',build_index=False):>>>print(name,seq)You can also iterate sequence object from FASTA object like this:>>>importpyfastx>>>forseqinpyfastx.Fasta('test/data/test.fa.gz'):>>>print(seq.name)>>>print(seq.seq)>>>print(seq.description)Iteration withbuild_index=True(default) return sequence object which allows you to access attributions of sequence. New in pyfastx 0.6.3.Get FASTA information>>># get sequence counts in FASTA>>>len(fa)211>>># get total sequence length of FASTA>>>fa.size86262>>># get GC content of DNA sequence of FASTA>>>fa.gc_content43.529014587402344>>># get GC skew of DNA sequences in FASTA>>># New in pyfastx 0.3.8>>>fa.gc_skews0.004287730902433395>>># get composition of nucleotides in FASTA>>>fa.composition{'A':24534,'C':18694,'G':18855,'T':24179}>>># get fasta type (DNA, RNA, or protein)>>>fa.type'DNA'>>># check fasta file is gzip compressed>>>fa.is_gzipTrueGet longest and shortest sequenceNew inpyfastx0.3.0>>># get longest sequence>>>s=fa.longest>>>s<Sequence>JZ822609.1withlengthof821>>>s.name'JZ822609.1'>>>len(s)821>>># get shortest sequence>>>s=fa.shortest>>>s<Sequence>JZ822617.1withlengthof118>>>s.name'JZ822617.1'>>>len(s)118Calculate N50 and L50New inpyfastx0.3.0Calculate assembly N50 and L50, return (N50, L50), learn more aboutN50,L50>>># get FASTA N50 and L50>>>fa.nl(50)(516,66)>>># get FASTA N90 and L90>>>fa.nl(90)(231,161)>>># get FASTA N75 and L75>>>fa.nl(75)(365,117)Get sequence mean and median lengthNew inpyfastx0.3.0>>># get sequence average length>>>fa.mean408>>># get seqeunce median length>>>fa.median430Get sequence countsNew inpyfastx0.3.0Get counts of sequences whose length >= specified length>>># get counts of sequences with length >= 200 bp>>>fa.count(200)173>>># get counts of sequences with length >= 500 bp>>>fa.count(500)70Get subsequencesSubsequences can be retrieved from FASTA file by using a list of [start, end] coordinates>>># get subsequence with start and end position>>>interval=(1,10)>>>fa.fetch('JZ822577.1',interval)'CTCTAGAGAT'>>># get subsequences with a list of start and end position>>>intervals=[(1,10),(50,60)]>>>fa.fetch('JZ822577.1',intervals)'CTCTAGAGATTTTAGTTTGAC'>>># get subsequences with reverse strand>>>fa.fetch('JZ822577.1',(1,10),strand='-')'ATCTCTAGAG'Key functionNew inpyfastx0.5.1Sometimes your fasta will have a long header which contains multiple identifiers and description, for example, “>JZ822577.1 contig1 cDNA library of flower petals in tree peony by suppression subtractive hybridization Paeonia suffruticosa cDNA, mRNA sequence”. In this case, both “JZ822577.1” and “contig1” can be used as identifer. you can specify the key function to select one as identifier.>>>#default use JZ822577.1 as identifier>>>#specify key_func to select contig1 as identifer>>>fa=pyfastx.Fasta('tests/data/test.fa.gz',key_func=lambdax:x.split()[1])>>>fa<Fasta>tests/data/test.fa.gzcontains211seqsSequenceGet a sequence from FASTA>>># get sequence like a dictionary by identifier>>>s1=fa['JZ822577.1']>>>s1<Sequence>JZ822577.1withlengthof333>>># get sequence like a list by index>>>s2=fa[2]>>>s2<Sequence>JZ822579.1withlengthof176>>># get last sequence>>>s3=fa[-1]>>>s3<Sequence>JZ840318.1withlengthof134>>># check a sequence name weather in FASTA file>>>'JZ822577.1'infaTrueGet sequence information>>>s=fa[-1]>>>s<Sequence>JZ840318.1withlengthof134>>># get sequence order number in FASTA file>>># New in pyfastx 0.3.7>>>s.id211>>># get sequence name>>>s.name'JZ840318.1'>>># get sequence description>>># New in pyfastx 0.3.1>>>s.description'R283 cDNA library of flower petals in tree peony by suppression subtractive hybridization Paeonia suffruticosa cDNA, mRNA sequence'>>># get sequence string>>>s.seq'ACTGGAGGTTCTTCTTCCTGTGGAAAGTAACTTGTTTTGCCTTCACCTGCCTGTTCTTCACATCAACCTTGTTCCCACACAAAACAATGGGAATGTTCTCACACACCCTGCAGAGATCACGATGCCATGTTGGT'>>># get sequence raw string, New in pyfastx 0.6.3>>>print(s.raw)>JZ840318.1R283cDNAlibraryofflowerpetalsintreepeonybysuppressionsubtractivehybridizationPaeoniasuffruticosacDNA,mRNAsequenceACTGGAGGTTCTTCTTCCTGTGGAAAGTAACTTGTTTTGCCTTCACCTGCCTGTTCTTCACATCAACCTTGTTCCCACACAAAACAATGGGAATGTTCTCACACACCCTGCAGAGATCACGATGCCATGTTGGT>>># get sequence length>>>len(s)134>>># get GC content if dna sequence>>>s.gc_content46.26865768432617>>># get nucleotide composition if dna sequence>>>s.composition{'A':31,'C':37,'G':25,'T':41,'N':0}Sequence sliceSequence object can be sliced like a python string>>># get a sub seq from sequence>>>s=fa[-1]>>>ss=s[10:30]>>>ss<Sequence>JZ840318.1from11to30>>>ss.name'JZ840318.1:11-30'>>>ss.seq'CTTCTTCCTGTGGAAAGTAA'>>>ss=s[-10:]>>>ss<Sequence>JZ840318.1from125to134>>>ss.name'JZ840318.1:125-134'>>>ss.seq'CCATGTTGGT'NoteSlicing start and end coordinates are 0-based. Currently, pyfastx does not support an optional thirdsteporstrideargument. For exampless[::-1]Reverse and complement sequence>>># get sliced sequence>>>fa[0][10:20].seq'GTCAATTTCC'>>># get reverse of sliced sequence>>>fa[0][10:20].reverse'CCTTTAACTG'>>># get complement of sliced sequence>>>fa[0][10:20].complement'CAGTTAAAGG'>>># get reversed complement sequence, corresponding to sequence in antisense strand>>>fa[0][10:20].antisense'GGAAATTGAC'Read sequence line by lineNew inpyfastx0.3.0The sequence object can be iterated line by line as they appear in FASTA file.>>>forlineinfa[0]:...print(line)...CTCTAGAGATTACTTCTTCACATTCCAGATCACTCAGGCTCTTTGTCATTTTAGTTTGACTAGGATATCGAGTATTCAAGCTCATCGCTTTTGGTAATCTTTGCGGTGCATGCCTTTGCATGCTGTATTGCTGCTTCATCATCCCCTTTGACTTGTGTGGCGGTGGCAAGACATCCGAAGAGTTAAGCGATGCTTGTCTAGTCAATTTCCCCATGTACAGAATCATTGTTGTCAATTGGTTGTTTCCTTGATGGTGAAGGGGCTTCAATACATGAGTTCCAAACTAACATTTCTTGACTAACACTTGAGGAAGAAGGACAAGGGTCCCCATGTNoteSliced sequence (e.g. fa[0][10:50]) cannot be read line by lineSearch for subsequenceNew inpyfastx0.3.6Search for subsequence from given sequence and get one-based start position of the first occurrence>>># search subsequence in sense strand>>>fa[0].search('GCTTCAATACA')262>>># check subsequence weather in sequence>>>'GCTTCAATACA'infa[0]True>>># search subsequence in antisense strand>>>fa[0].search('CCTCAAGT','-')301FastaKeysNew inpyfastx0.8.0. We have changedIdentifierobject toFastaKeysobject.Get keysGet all names of sequence as a list-like object.>>>ids=fa.keys()>>>ids<FastaKeys>contains211keys>>># get count of sequence>>>len(ids)211>>># get key by index>>>ids[0]'JZ822577.1'>>># check key whether in fasta>>>'JZ822577.1'inidsTrue>>># iterate over keys>>>fornameinids:>>>print(name)>>># convert to a list>>>list(ids)Sort keysSort keys by sequence id, name, or length for iterationNew inpyfastx0.5.0>>># sort keys by length with descending order>>>fornameinids.sort(by='length',reverse=True):>>>print(name)>>># sort keys by name with ascending order>>>fornameinids.sort(by='name'):>>>print(name)>>># sort keys by id with descending order>>>fornameinids.sort(by='id',reverse=True)>>>print(name)Filter keysFilter keys by sequence length and nameNew inpyfastx0.5.10>>># get keys with length > 600>>>ids.filter(ids>600)<FastaKeys>contains48keys>>># get keys with length >= 500 and <= 700>>>ids.filter(ids>=500,ids<=700)<FastaKeys>contains48keys>>># get keys with length > 500 and < 600>>>ids.filter(500<ids<600)<FastaKeys>contains22keys>>># get keys contain JZ8226>>>ids.filter(ids%'JZ8226')<FastaKeys>contains90keys>>># get keys contain JZ8226 with length > 550>>>ids.filter(ids%'JZ8226',ids>550)<FastaKeys>contains17keys>>># clear sort order and filters>>>ids.reset()<FastaKeys>contains211keys>>># list a filtered result>>>ids.filter(ids%'JZ8226',ids>730)>>>list(ids)['JZ822609.1','JZ822650.1','JZ822664.1','JZ822699.1']>>># list a filtered result with sort order>>>ids.filter(ids%'JZ8226',ids>730).sort('length',reverse=True)>>>list(ids)['JZ822609.1','JZ822699.1','JZ822664.1','JZ822650.1']>>>ids.filter(ids%'JZ8226',ids>730).sort('name',reverse=True)>>>list(ids)['JZ822699.1','JZ822664.1','JZ822650.1','JZ822609.1']FASTQNew inpyfastx0.4.0Read FASTQ fileRead plain or gzipped file and build index, support for random access to reads from FASTQ.>>>importpyfastx>>>fq=pyfastx.Fastq('tests/data/test.fq.gz')>>>fq<Fastq>tests/data/test.fq.gzcontains100readsFASTQ records iterationThe fastest way to parse plain or gzipped FASTQ file without building index, the iteration will return a tuple contains read name, seq and quality.>>>importpyfastx>>>forname,seq,qualinpyfastx.Fastq('tests/data/test.fq.gz',build_index=False):>>>print(name)>>>print(seq)>>>print(qual)You can also iterate read object from FASTQ object like this:>>>importpyfastx>>>forreadinpyfastx.Fastq('test/data/test.fq.gz'):>>>print(read.name)>>>print(read.seq)>>>print(read.qual)>>>print(read.quali)Iteration withbuild_index=True(default) return read object which allows you to access attribution of read. New in pyfastx 0.6.3.Get FASTQ information>>># get read counts in FASTQ>>>len(fq)800>>># get total bases>>>fq.size120000>>># get GC content of FASTQ file>>>fq.gc_content66.17471313476562>>># get composition of bases in FASTQ>>>fq.composition{'A':20501,'C':39705,'G':39704,'T':20089,'N':1}>>># New in pyfastx 0.6.10>>># get average length of reads>>>fq.avglen150.0>>># get maximum lenth of reads>>>fq.maxlen150>>># get minimum length of reas>>>fq.minlen150>>># get maximum quality score>>>fq.maxqual70>>># get minimum quality score>>>fq.minqual35>>># get phred which affects the quality score conversion>>>fq.phred33>>># Guess fastq quality encoding system>>># New in pyfastx 0.4.1>>>fq.encoding_type['Sanger Phred+33','Illumina 1.8+ Phred+33']ReadGet read from FASTQ>>>#get read like a dict by read name>>>r1=fq['A00129:183:H77K2DMXX:1:1101:4752:1047']>>>r1<Read>A00129:183:H77K2DMXX:1:1101:4752:1047withlengthof150>>># get read like a list by index>>>r2=fq[10]>>>r2<Read>A00129:183:H77K2DMXX:1:1101:18041:1078withlengthof150>>># get the last read>>>r3=fq[-1]>>>r3<Read>A00129:183:H77K2DMXX:1:1101:31575:4726withlengthof150>>># check a read weather in FASTQ file>>>'A00129:183:H77K2DMXX:1:1101:4752:1047'infqTrueGet read information>>>r=fq[-10]>>>r<Read>A00129:183:H77K2DMXX:1:1101:1750:4711withlengthof150>>># get read order number in FASTQ file>>>r.id791>>># get read name>>>r.name'A00129:183:H77K2DMXX:1:1101:1750:4711'>>># get read full header line, New in pyfastx 0.6.3>>>r.description'@A00129:183:H77K2DMXX:1:1101:1750:4711 1:N:0:CAATGGAA+CGAGGCTG'>>># get read length>>>len(r)150>>># get read sequence>>>r.seq'CGAGGAAATCGACGTCACCGATCTGGAAGCCCTGCGCGCCCATCTCAACCAGAAATGGGGTGGCCAGCGCGGCAAGCTGACCCTGCTGCCGTTCCTGGTCCGCGCCATGGTCGTGGCGCTGCGCGACTTCCCGCAGTTGAACGCGCGCTA'>>># get raw string of read, New in pyfastx 0.6.3>>>print(r.raw)@A00129:183:H77K2DMXX:1:1101:1750:47111:N:0:CAATGGAA+CGAGGCTGCGAGGAAATCGACGTCACCGATCTGGAAGCCCTGCGCGCCCATCTCAACCAGAAATGGGGTGGCCAGCGCGGCAAGCTGACCCTGCTGCCGTTCCTGGTCCGCGCCATGGTCGTGGCGCTGCGCGACTTCCCGCAGTTGAACGCGCGCTA+FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF:FF,FFFFFFFFFFFFFFFFFFFFFFFFFF,F:FFFFFFFFF:>>># get read quality ascii string>>>r.qual'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF:FF,FFFFFFFFFFFFFFFFFFFFFFFFFF,F:FFFFFFFFF:'>>># get read quality integer value, ascii - 33 or 64>>>r.quali[37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,25,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,25,37,37,11,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,37,11,37,25,37,37,37,37,37,37,37,37,37,25]>>># get read length>>>len(r)150FastqKeysNew inpyfastx0.8.0.Get fastq keysGet all names of read as a list-like object.>>>ids=fq.keys()>>>ids<FastqKeys>contains800keys>>># get count of read>>>len(ids)800>>># get key by index>>>ids[0]'A00129:183:H77K2DMXX:1:1101:6804:1031'>>># check key whether in fasta>>>'A00129:183:H77K2DMXX:1:1101:14416:1031'inidsTrueCommand line interfaceNew inpyfastx0.5.0$pyfastx-husage:pyfastxCOMMAND[OPTIONS]AcommandlinetoolforFASTA/Qfilemanipulationoptionalarguments:-h,--helpshowthishelpmessageandexit-v,--versionshowprogram'sversionnumberandexitCommands:indexbuildindexforfasta/qfilestatshowdetailedstatisticsinformationoffasta/qfilesplitsplitfasta/qfileintomultiplefilesfq2faconvertfastqfiletofastafilesubseqgetsubsequencesfromfastafilebyregionsamplerandomlysamplesequencesfromfastaorfastqfileextractextractfullsequencesorreadsfromfasta/qfileBuild indexNew inpyfastx0.6.10$pyfastxindex-husage:pyfastxindex[-h][-f]fastx[fastx...]positionalarguments:fastxfastaorfastqfile,gzipsupportoptionalarguments:-h,--helpshowthishelpmessageandexit-f,--fullbuildfullindex,basecompositionwillbecalculatedShow statistics information$pyfastxstat-husage:pyfastxinfo[-h]fastxpositionalarguments:fastxinputfastaorfastqfile,gzipsupportoptionalarguments:-h,--helpshowthishelpmessageandexitSplit FASTA/Q file$pyfastxsplit-husage:pyfastxsplit[-h](-nint|-cint)[-ostr]fastxpositionalarguments:fastxfastaorfastqfile,gzipsupportoptionalarguments:-h,--helpshowthishelpmessageandexit-nintsplitafasta/qfileintoNnewfileswithevensize-cintsplitafasta/qfileintomultiplefilescontainingthesamesequencecounts-ostr,--out-dirstroutputdirectory,defaultiscurrentfolderConvert FASTQ to FASTA file$pyfastxfq2fa-husage:pyfastxfq2fa[-h][-ostr]fastxpositionalarguments:fastxfastqfile,gzipsupportoptionalarguments:-h,--helpshowthishelpmessageandexit-ostr,--out-filestroutputfile,default:outputtostdoutGet subsequence with region$pyfastxsubseq-husage:pyfastxsubseq[-h][-rstr|-bstr][-ostr]fastx[region[region...]]positionalarguments:fastxinputfastafile,gzipsupportregionformatischr:start-end,startandendpositionis1-based,multiplenameswereseparatedbyspaceoptionalarguments:-h,--helpshowthishelpmessageandexit-rstr,--region-filestrtab-delimitedfile,oneregionperline,bothstartandendpositionare1-based-bstr,--bed-filestrtab-delimitedBEDfile,0-basedstartpositionand1-basedendposition-ostr,--out-filestroutputfile,default:outputtostdoutSample sequences$pyfastxsample-husage:pyfastxsample[-h](-nint|-pfloat)[-sint][--sequential-read][-ostr]fastxpositionalarguments:fastxfastaorfastqfile,gzipsupportoptionalarguments:-h,--helpshowthishelpmessageandexit-nintnumberofsequencestobesampled-pfloatproportionofsequencestobesampled,0~1-sint,--seedintrandomseed,defaultisthecurrentsystemtime--sequential-readstartsequentialreading,particularlysuitableforsamplinglargenumbersofsequences-ostr,--out-filestroutputfile,default:outputtostdoutExtract sequencesNew inpyfastx0.6.10$pyfastxextract-husage:pyfastxextract[-h][-lstr][--reverse-complement][--out-fasta][-ostr][--sequential-read]fastx[name[name...]]positionalarguments:fastxfastaorfastqfile,gzipsupportnamesequencenameorreadname,multiplenameswereseparatedbyspaceoptionalarguments:-h,--helpshowthishelpmessageandexit-lstr,--list-filestrafilecontainingsequenceorreadnames,onenameperline--reverse-complementoutputreversecomplementsequence--out-fastaoutputfastaformatwhenextractreadsfromfastq,defaultoutputfastqformat-ostr,--out-filestroutputfile,default:outputtostdout--sequential-readstartsequentialreading,particularlysuitableforextractinglargenumbersofsequencesDrawbacksIf you intensively check sequence names exists in FASTA file usinginoperator on FASTA object like:>>>fa=pyfastx.Fasta('tests/data/test.fa.gz')>>># Suppose seqnames has 100000 names>>>forseqnameinseqnames:>>>ifseqnameinfa:>>>dosomethingThis will take a long time to finish. Becuase, pyfastx does not load the index into memory, theinoperating is corresponding to sql query existence from index database. The faster alternative way to do this is:>>>fa=pyfastx.Fasta('tests/data/test.fa.gz')>>># load all sequence names into a set object>>>all_names=set(fa.keys())>>>forseqnameinseqnames:>>>ifseqnameinall_names:>>>dosomethingTestingThepyfaidxmodule was used to testpyfastx. First, make sure you have a suitable version installed:pip install pyfastxTo test pyfastx, you should also install pyfaidx 0.5.8:pip install pyfaidx==0.5.8Then, to run the tests:$ python setup.py testAcknowledgementskseq.handzlibwas used to parse FASTA format.Sqlite3was used to store built indexes.pyfastxcan randomly access to sequences from gzipped FASTA file mainly attributed toindexed_gzip.