biofile-kit 0.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. biofile_kit-0.0.0/LICENSE +21 -0
  2. biofile_kit-0.0.0/PKG-INFO +50 -0
  3. biofile_kit-0.0.0/README.md +32 -0
  4. biofile_kit-0.0.0/biofile_kit/bin/fasta_tools.py +53 -0
  5. biofile_kit-0.0.0/biofile_kit/bin/gff_tools.py +33 -0
  6. biofile_kit-0.0.0/biofile_kit/bin/gtf_tools.py +30 -0
  7. biofile_kit-0.0.0/biofile_kit/fasta_utils/ORF_finder.py +94 -0
  8. biofile_kit-0.0.0/biofile_kit/fasta_utils/SSR_finder.py +58 -0
  9. biofile_kit-0.0.0/biofile_kit/fasta_utils/__init__.py +30 -0
  10. biofile_kit-0.0.0/biofile_kit/fasta_utils/fa2tab.py +42 -0
  11. biofile_kit-0.0.0/biofile_kit/fasta_utils/format_fasta.py +91 -0
  12. biofile_kit-0.0.0/biofile_kit/fasta_utils/gap_location.py +38 -0
  13. biofile_kit-0.0.0/biofile_kit/fasta_utils/generate_random_nucl.py +66 -0
  14. biofile_kit-0.0.0/biofile_kit/fasta_utils/get_longest_seq_for_gene.py +46 -0
  15. biofile_kit-0.0.0/biofile_kit/fasta_utils/get_reverse_complementary_seq.py +43 -0
  16. biofile_kit-0.0.0/biofile_kit/fasta_utils/get_seq_len.py +41 -0
  17. biofile_kit-0.0.0/biofile_kit/fasta_utils/id_index_seq.py +76 -0
  18. biofile_kit-0.0.0/biofile_kit/fasta_utils/motif_finder.py +67 -0
  19. biofile_kit-0.0.0/biofile_kit/fasta_utils/seq_rename.py +50 -0
  20. biofile_kit-0.0.0/biofile_kit/gff_utils/__init__.py +18 -0
  21. biofile_kit-0.0.0/biofile_kit/gff_utils/get_feature_density.py +52 -0
  22. biofile_kit-0.0.0/biofile_kit/gff_utils/gff2bed.py +43 -0
  23. biofile_kit-0.0.0/biofile_kit/gff_utils/gff2gtf.py +38 -0
  24. biofile_kit-0.0.0/biofile_kit/gff_utils/gff_extract_seq.py +81 -0
  25. biofile_kit-0.0.0/biofile_kit/gff_utils/gff_sort.py +34 -0
  26. biofile_kit-0.0.0/biofile_kit/gff_utils/rename.py +73 -0
  27. biofile_kit-0.0.0/biofile_kit/gtf_utils/__init__.py +12 -0
  28. biofile_kit-0.0.0/biofile_kit/gtf_utils/gtf2bed.py +38 -0
  29. biofile_kit-0.0.0/biofile_kit/gtf_utils/gtf_extract_seq.py +41 -0
  30. biofile_kit-0.0.0/biofile_kit/gtf_utils/gtf_sort.py +35 -0
  31. biofile_kit-0.0.0/pyproject.toml +20 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Leo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,50 @@
1
+ Metadata-Version: 2.1
2
+ Name: biofile-kit
3
+ Version: 0.0.0
4
+ Summary: Bioinformatics File Operations Toolkit.
5
+ Author: Wenlin Xu
6
+ Author-email: wenlinxu.njfu@outlook.com
7
+ Requires-Python: >=3.8,<4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.8
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Requires-Dist: pybioinformatic (==1.2.2)
16
+ Description-Content-Type: text/markdown
17
+
18
+ # Introduction
19
+ **BioFileKit: Designed to provide bioinformatics researchers and developers with a powerful, user-friendly and
20
+ extensible Python toolkit, it focuses on simplifying the reading, writing, conversion, parsing and basic operations of
21
+ various biological data file formats. Say goodbye to reinventing the wheel and the cumbersome format analysis, and
22
+ focus on your scientific discoveries!**
23
+
24
+ # Install
25
+ ```
26
+ pip install biofile_kit
27
+ ```
28
+
29
+ # Usage example
30
+ ## Generate random nucleotide sequences
31
+ ```shell
32
+ fasta_tools random_nucl -n seq1,seq2 -l 1000,1200
33
+ ```
34
+ ```
35
+ >seq1 length=1000
36
+ CGCCAGGCCTGCCCTGCGACGGAGGTTCCCCGTATGACTGCCCTATATCATTCCTGCTAAACTCAATCCACAAGATCAATTCACTCCGGGGAACAACTGCCACTAGAAACCGTAGGTTACCATCAATAGTTCCCCACTTGGAGGAAGAAGTCTTTGAAGCAGGTTGTCATCCAGCATTCTTTCTAAACGTCATTGGACATAGGGGTAAGCTCATATCCTCTCCCAACCATTCAGAAGTCCATGACCATGTCCGGTGCAAATTTGAAAGTCATGATGGTGAGGGAGCAAGAGAGCGCAGATCACGGATAAGTATTAAAAAGTGCTGTCGAGGCCGCAGTGGAAGTGACTAATTGGCTGATGCACGGACCTCCAGTGTACAGCTCATGTTTCAGGTGCGTCGGACTGTCAGTGACTCAATTTTCTGGGCCCAACTCCGCGTTCGGTGGATTAGTAACTATAGTGGTTGCATGAGGTACTGAGATTGAGCCGTGAAAAGCATTCAAAGTGCGGTTCCTCAACCTATTATTATTAAGACATAAGTTTGCTAGCGCTTTGTTGCAATCGTGTCGTGGAATGCGATTGATGCTTAGCAGTTTCCGGGAAGTACGGACTCATGCCGTTATGTGCGCCAACAAACAGCGCGTGTTTCATTTCGCGCCGGTCGCCTGGCGCGTGTTATGGGATCGCACTTCACCGTGCTGATATCGCTGAGGCGAGGGTTCCTCGAGATATTGGCTTGGCTCGCCAGGCAGTAGTCGTGGTCAGCCCGACTTGGCACGCTAAAGACGAGCCCACGTGCATTCGGTCGGAATCAGTTAGACGTCGAACGATTCGATCCAGCGTGAGGCCTATCCTTTGCCCATTTAACTCCGTATTCACGGTCTCCTTGATACATAGTGTACTTAGTGTTACCAGCGAACTCCGACGCGGACAGTGTCCTCGGAGTATTACCTCCAAAGAAATTCTCGGGCCGAACAGCGTAGTCTATACCGCCTGGGTG
37
+ >seq2 length=1200
38
+ ATAGGTGTAGTGTGTCTTCATCTTGATGTAAGTTCGTTCACCCAGATCTGCTAAAACGCATGGCATTTTTTTCGCATACGGTCCACTGGCACTATATGATTCCCAGTACTTCGCAGATTTGGGGGGGTAAGAGTCCGCGGAAGCGTTGTTCTGACGCGTACGCATGTTCGGTATTTTTTACGGGTGAGTTGCATCGGTTGTGTATTGGTCCATGTTAAGACGGTTATCGGGCAGGCTTCTCAATGCGGTGAGTCGGGAAGACACTAGCCAGCGAAATTATGTGATCGCTGGAATAGGATCGATGTAGCAACGACACTTTCCTGGCCTACAGACGGACTTGGACCGGATCAATCGTCTTATATAATAATACACGTCGCAGAACGGTCTGTGTATAGGACCGGTAGAATGAGTAGTTCATACTCCGGCCCGCAGGTACCCCTGTACGCATGAAAGTCCAAGCTCTCGCTGAACCGACACCTCTAGCCGAGGTACGTATGCATGACCTGGTTGTTCTCTTCGGGTCACGACAGTTGCCTATTTACGCTCGGATACCAGGAAACTTTGCCGGGAGTTCGCCCCCAGTAGTTCCCGGGTTGGGGTCGGGGTGTTCTGCCGATTACCGGATGTATCTCACCTGAGATTCAGCATCGGTGCGAACATCGTGAATCCTAAAGGTTGAACAAAGGAAGGCCTCCATGCGTTGGAAAGTCCTCGAAGTGGAGAAGTCTATCGTAGATCAACCGATAGGCAATGAAAAGAAAAAGCGCAACAGACGCCACGCTTCTAGATCGCAGTTGGCCTTTTAATGGCGAATCCATTTACCGAGCGAAGAAAAAGCCTGGCTAGCTTGTTTAAAACTGGTAACACTGAATCTCCGAAAGAGTAGCTATAGGCTCCCAGCACAGCCTGCGGCTGGCGCCAACGCCTAACGAAAATGCCAATCCACTTAGTTGTGTTAACTGTCTCCCCACTATATGCGGCTTACCAGGGAGTGTAATTTCTGGCGATGACCAGCGTTTCCTTTGGGTTCCGTCGAATTCCTTAGATCTAGGACAGCAGTTCGAATTACTTGGCGTGGTCGCATCAGGACTTCGCGTAGTGGCTATCCAGATCATAGACTGAGTCACGTATTTGACGCCAGACCTAAGACCCCACGATGGTTTCTAGTCGTAACTTGAGTGAGCTAGCTCGCCTCGTGTC
39
+ ```
40
+ ## ORF prediction
41
+ ```shell
42
+ fasta_tools random_nucl -n seq1,seq2 -l 1000,1200 | fasta_tools ORF_finder -c -
43
+ ```
44
+ ```
45
+ >seq1 length=42 ORF_prediction
46
+ MRLMLSSFREVRTHAVMCANKQRVFHFAPVAWRVLWDRTSPC*
47
+ >seq2 length=87 ORF_prediction
48
+ MIWIATTRSPDATTPSNSNCCPRSKEFDGTQRKRWSSPEITLPGKPHIVGRQLTQLSGLAFSLGVGASRRLCWEPIATLSEIQCYQF*
49
+ ```
50
+
@@ -0,0 +1,32 @@
1
+ # Introduction
2
+ **BioFileKit: Designed to provide bioinformatics researchers and developers with a powerful, user-friendly and
3
+ extensible Python toolkit, it focuses on simplifying the reading, writing, conversion, parsing and basic operations of
4
+ various biological data file formats. Say goodbye to reinventing the wheel and the cumbersome format analysis, and
5
+ focus on your scientific discoveries!**
6
+
7
+ # Install
8
+ ```
9
+ pip install biofile_kit
10
+ ```
11
+
12
+ # Usage example
13
+ ## Generate random nucleotide sequences
14
+ ```shell
15
+ fasta_tools random_nucl -n seq1,seq2 -l 1000,1200
16
+ ```
17
+ ```
18
+ >seq1 length=1000
19
+ CGCCAGGCCTGCCCTGCGACGGAGGTTCCCCGTATGACTGCCCTATATCATTCCTGCTAAACTCAATCCACAAGATCAATTCACTCCGGGGAACAACTGCCACTAGAAACCGTAGGTTACCATCAATAGTTCCCCACTTGGAGGAAGAAGTCTTTGAAGCAGGTTGTCATCCAGCATTCTTTCTAAACGTCATTGGACATAGGGGTAAGCTCATATCCTCTCCCAACCATTCAGAAGTCCATGACCATGTCCGGTGCAAATTTGAAAGTCATGATGGTGAGGGAGCAAGAGAGCGCAGATCACGGATAAGTATTAAAAAGTGCTGTCGAGGCCGCAGTGGAAGTGACTAATTGGCTGATGCACGGACCTCCAGTGTACAGCTCATGTTTCAGGTGCGTCGGACTGTCAGTGACTCAATTTTCTGGGCCCAACTCCGCGTTCGGTGGATTAGTAACTATAGTGGTTGCATGAGGTACTGAGATTGAGCCGTGAAAAGCATTCAAAGTGCGGTTCCTCAACCTATTATTATTAAGACATAAGTTTGCTAGCGCTTTGTTGCAATCGTGTCGTGGAATGCGATTGATGCTTAGCAGTTTCCGGGAAGTACGGACTCATGCCGTTATGTGCGCCAACAAACAGCGCGTGTTTCATTTCGCGCCGGTCGCCTGGCGCGTGTTATGGGATCGCACTTCACCGTGCTGATATCGCTGAGGCGAGGGTTCCTCGAGATATTGGCTTGGCTCGCCAGGCAGTAGTCGTGGTCAGCCCGACTTGGCACGCTAAAGACGAGCCCACGTGCATTCGGTCGGAATCAGTTAGACGTCGAACGATTCGATCCAGCGTGAGGCCTATCCTTTGCCCATTTAACTCCGTATTCACGGTCTCCTTGATACATAGTGTACTTAGTGTTACCAGCGAACTCCGACGCGGACAGTGTCCTCGGAGTATTACCTCCAAAGAAATTCTCGGGCCGAACAGCGTAGTCTATACCGCCTGGGTG
20
+ >seq2 length=1200
21
+ ATAGGTGTAGTGTGTCTTCATCTTGATGTAAGTTCGTTCACCCAGATCTGCTAAAACGCATGGCATTTTTTTCGCATACGGTCCACTGGCACTATATGATTCCCAGTACTTCGCAGATTTGGGGGGGTAAGAGTCCGCGGAAGCGTTGTTCTGACGCGTACGCATGTTCGGTATTTTTTACGGGTGAGTTGCATCGGTTGTGTATTGGTCCATGTTAAGACGGTTATCGGGCAGGCTTCTCAATGCGGTGAGTCGGGAAGACACTAGCCAGCGAAATTATGTGATCGCTGGAATAGGATCGATGTAGCAACGACACTTTCCTGGCCTACAGACGGACTTGGACCGGATCAATCGTCTTATATAATAATACACGTCGCAGAACGGTCTGTGTATAGGACCGGTAGAATGAGTAGTTCATACTCCGGCCCGCAGGTACCCCTGTACGCATGAAAGTCCAAGCTCTCGCTGAACCGACACCTCTAGCCGAGGTACGTATGCATGACCTGGTTGTTCTCTTCGGGTCACGACAGTTGCCTATTTACGCTCGGATACCAGGAAACTTTGCCGGGAGTTCGCCCCCAGTAGTTCCCGGGTTGGGGTCGGGGTGTTCTGCCGATTACCGGATGTATCTCACCTGAGATTCAGCATCGGTGCGAACATCGTGAATCCTAAAGGTTGAACAAAGGAAGGCCTCCATGCGTTGGAAAGTCCTCGAAGTGGAGAAGTCTATCGTAGATCAACCGATAGGCAATGAAAAGAAAAAGCGCAACAGACGCCACGCTTCTAGATCGCAGTTGGCCTTTTAATGGCGAATCCATTTACCGAGCGAAGAAAAAGCCTGGCTAGCTTGTTTAAAACTGGTAACACTGAATCTCCGAAAGAGTAGCTATAGGCTCCCAGCACAGCCTGCGGCTGGCGCCAACGCCTAACGAAAATGCCAATCCACTTAGTTGTGTTAACTGTCTCCCCACTATATGCGGCTTACCAGGGAGTGTAATTTCTGGCGATGACCAGCGTTTCCTTTGGGTTCCGTCGAATTCCTTAGATCTAGGACAGCAGTTCGAATTACTTGGCGTGGTCGCATCAGGACTTCGCGTAGTGGCTATCCAGATCATAGACTGAGTCACGTATTTGACGCCAGACCTAAGACCCCACGATGGTTTCTAGTCGTAACTTGAGTGAGCTAGCTCGCCTCGTGTC
22
+ ```
23
+ ## ORF prediction
24
+ ```shell
25
+ fasta_tools random_nucl -n seq1,seq2 -l 1000,1200 | fasta_tools ORF_finder -c -
26
+ ```
27
+ ```
28
+ >seq1 length=42 ORF_prediction
29
+ MRLMLSSFREVRTHAVMCANKQRVFHFAPVAWRVLWDRTSPC*
30
+ >seq2 length=87 ORF_prediction
31
+ MIWIATTRSPDATTPSNSNCCPRSKEFDGTQRKRWSSPEITLPGKPHIVGRQLTQLSGLAFSLGVGASRRLCWEPIATLSEIQCYQF*
32
+ ```
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env python
2
+ """
3
+ File: gff_tools.py
4
+ Description: Fasta file tools.
5
+ CreateDate: 2025/7/2
6
+ Author: xuwenlin
7
+ E-mail: wenlinxu.njfu@outlook.com
8
+ """
9
+ import click
10
+ from biofile_kit.fasta_utils import (
11
+ fa2tab,
12
+ format_fasta,
13
+ gap_location,
14
+ generate_random_nucl,
15
+ get_longest_seq_for_gene,
16
+ get_reverse_complementary_seq,
17
+ get_seq_len,
18
+ id_index_seq,
19
+ motif_finder,
20
+ ORF_finder,
21
+ seq_rename,
22
+ SSR_finder,
23
+ __version__
24
+ )
25
+ from pybioinformatic import Displayer
26
+
27
+ displayer = Displayer(__file__.split('/')[-1], version=__version__)
28
+
29
+
30
+ @click.group(context_settings=dict(help_option_names=['-h', '--help']))
31
+ @click.option('-V', '--version', 'version', help='Show author and version information.',
32
+ is_flag=True, is_eager=True, expose_value=False, callback=displayer.version_info)
33
+ def fasta_tools():
34
+ """Fasta file tools."""
35
+ pass
36
+
37
+
38
+ fasta_tools.add_command(fa2tab, 'fa2tab')
39
+ fasta_tools.add_command(format_fasta, 'format_fasta')
40
+ fasta_tools.add_command(gap_location, 'gap_location')
41
+ fasta_tools.add_command(generate_random_nucl, 'random_nucl')
42
+ fasta_tools.add_command(get_longest_seq_for_gene, 'get_longest_seq_for_gene')
43
+ fasta_tools.add_command(get_reverse_complementary_seq, 'get_reverse_complementary_seq')
44
+ fasta_tools.add_command(get_seq_len, 'get_seq_len')
45
+ fasta_tools.add_command(id_index_seq, 'id_index_seq')
46
+ fasta_tools.add_command(motif_finder, 'motif_finder')
47
+ fasta_tools.add_command(ORF_finder, 'ORF_finder')
48
+ fasta_tools.add_command(seq_rename, 'seq_rename')
49
+ fasta_tools.add_command(SSR_finder, 'SSR_finder')
50
+
51
+
52
+ if __name__ == '__main__':
53
+ fasta_tools()
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env python
2
+ """
3
+ File: gff_tools.py
4
+ Description: Gff file tools.
5
+ CreateDate: 2025/7/2
6
+ Author: xuwenlin
7
+ E-mail: wenlinxu.njfu@outlook.com
8
+ """
9
+ import click
10
+ from biofile_kit.gff_utils import get_feature_density, gff2bed, gff2gtf, gff_extract_seq, gff_sort, rename, __version__
11
+ from pybioinformatic import Displayer
12
+
13
+ displayer = Displayer(__file__.split('/')[-1], version=__version__)
14
+
15
+
16
+ @click.group(context_settings=dict(help_option_names=['-h', '--help']))
17
+ @click.option('-V', '--version', 'version', help='Show author and version information.',
18
+ is_flag=True, is_eager=True, expose_value=False, callback=displayer.version_info)
19
+ def gff_tools():
20
+ """Gff file tools."""
21
+ pass
22
+
23
+
24
+ gff_tools.add_command(get_feature_density, 'get_feature_density')
25
+ gff_tools.add_command(gff2bed, 'to_bed')
26
+ gff_tools.add_command(gff2gtf, 'to_gtf')
27
+ gff_tools.add_command(gff_extract_seq, 'extract_seq')
28
+ gff_tools.add_command(gff_sort, 'sort')
29
+ gff_tools.add_command(rename, 'rename')
30
+
31
+
32
+ if __name__ == '__main__':
33
+ gff_tools()
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env python
2
+ """
3
+ File: gff_tools.py
4
+ Description: Gtf file tools.
5
+ CreateDate: 2025/7/2
6
+ Author: xuwenlin
7
+ E-mail: wenlinxu.njfu@outlook.com
8
+ """
9
+ import click
10
+ from biofile_kit.gtf_utils import gtf2bed, gtf_extract_seq, gtf_sort, __version__
11
+ from pybioinformatic import Displayer
12
+
13
+ displayer = Displayer(__file__.split('/')[-1], version=__version__)
14
+
15
+
16
+ @click.group(context_settings=dict(help_option_names=['-h', '--help']))
17
+ @click.option('-V', '--version', 'version', help='Show author and version information.',
18
+ is_flag=True, is_eager=True, expose_value=False, callback=displayer.version_info)
19
+ def gtf_tools():
20
+ """Gtf file tools."""
21
+ pass
22
+
23
+
24
+ gtf_tools.add_command(gtf_sort, 'sort')
25
+ gtf_tools.add_command(gtf_extract_seq, 'extract_seq')
26
+ gtf_tools.add_command(gtf2bed, 'to_bed')
27
+
28
+
29
+ if __name__ == '__main__':
30
+ gtf_tools()
@@ -0,0 +1,94 @@
1
+ #!/usr/bin/env python
2
+ """
3
+ File: ORF_finder.py
4
+ Description: Search for open reading frames (ORFs) in the nucleotide sequence you enter, and return maximum length ORF of each nucleotide sequence.
5
+ CreateDate: 2022/3/25
6
+ Author: xuwenlin
7
+ E-mail: wenlinxu.njfu@outlook.com
8
+ """
9
+ from tqdm import tqdm
10
+ from io import TextIOWrapper
11
+ from typing import Tuple, Union
12
+ from os import name
13
+ from natsort import natsort_key
14
+ import click
15
+ from pybioinformatic import Fasta, Nucleotide, TaskManager, Timer, Displayer
16
+ displayer = Displayer(__file__.split('/')[-1], version='0.1.0')
17
+
18
+
19
+ def sub_processing(nucl_obj: Nucleotide, min_len: int, complete: bool, only_plus: bool):
20
+ ORF = nucl_obj.ORF_prediction(min_len, complete, only_plus)
21
+ return ORF
22
+
23
+
24
+ @Timer('ORF predicting.')
25
+ def main(fasta_files: Tuple[Union[str, TextIOWrapper]],
26
+ parse_seqids: bool = True,
27
+ min_len: int = 30,
28
+ complete: bool = True,
29
+ only_plus: bool = False,
30
+ log_file: TextIOWrapper = None,
31
+ output_path: str = None,
32
+ num_processes: int = 1):
33
+ tkm = TaskManager(num_processing=num_processes)
34
+ for fasta_file in fasta_files:
35
+ with Fasta(fasta_file) as fa:
36
+ tkm.params = ((nucl_obj, min_len, complete, only_plus) for nucl_obj in fa.parse(parse_seqids))
37
+ # Set output prefix
38
+ if name == 'posix': # linux
39
+ output_prefix = fa.name.split('/')[-1].replace('.gz', '').replace('<', '').replace('>', '')
40
+ else: # windows
41
+ output_prefix = fa.name.split('\\')[-1].replace('.gz', '').replace('<', '').replace('>', '')
42
+ output_prefix = '.'.join(output_prefix.split('.')[:-1])
43
+ # Show the progress bar on the command line.
44
+ if (log_file is not None) and (output_path is not None) and ('stdin' not in fa.name):
45
+ with open(f'{output_path}/{output_prefix}_pep.fa', 'w') as output_file:
46
+ with tqdm(total=fa.seq_num, unit=' sequence', desc=f'[Processing {fa.name}]') as pbar:
47
+ results = tkm.parallel_run_func(sub_processing, lambda _: pbar.update(1))
48
+ results = [i.get() for i in results]
49
+ log = '\n'.join([i for i in results if isinstance(i, str)])
50
+ click.echo(log, log_file, err=True)
51
+ ORFs = [ORF for ORF in results if not isinstance(ORF, str)]
52
+ ORFs.sort(key=lambda i: natsort_key(i.id))
53
+ for ORF in ORFs:
54
+ click.echo(ORF, output_file)
55
+ # Do not show the progress bar on the command line.
56
+ else:
57
+ output_file = open(f'{output_path}/{output_prefix}_pep.fa', 'w') if output_path else None
58
+ tkm.parallel_run_func(sub_processing,
59
+ lambda ORF: click.echo(ORF, log_file, err=True) if isinstance(ORF, str) else
60
+ click.echo(ORF, output_file))
61
+
62
+
63
+ @click.command(context_settings=dict(help_option_names=['-h', '--help']))
64
+ @click.argument('fasta_files', nargs=-1, metavar='<fasta files|stdin>', type=click.File('r'), required=True)
65
+ @click.option('-l', '--min-len', 'min_len',
66
+ metavar='<int>', type=int, default=30, show_default=True,
67
+ help='Minimal ORF length.')
68
+ @click.option('-p', '--parse-seqids', 'parse_seqids',
69
+ is_flag=True, flag_value=True,
70
+ help='Parse sequence id.')
71
+ @click.option('-c', '--completed', 'completed',
72
+ is_flag=True, flag_value=True,
73
+ help='Remain completed ORF.')
74
+ @click.option('-F', '--forward', 'forward',
75
+ is_flag=True, flag_value=True,
76
+ help='Only predict forward chain.')
77
+ @click.option('-log', '--logfile', 'log_file',
78
+ metavar='<file|stderr>', type=click.File('w'),
79
+ help='Write the sequence that not found ORF to logfile, stderr by default.')
80
+ @click.option('-o', '--output-path', 'output_path',
81
+ metavar='<path|stdout>',
82
+ help='Output path, stdout by default.')
83
+ @click.option('-n', '--num_processes', 'num_processes',
84
+ metavar='<int>', type=int, default=1, show_default=True,
85
+ help='Number of processes.')
86
+ @click.option('-V', '--version', 'version', help='Show author and version information.',
87
+ is_flag=True, is_eager=True, expose_value=False, callback=displayer.version_info)
88
+ def run(fasta_files, parse_seqids, min_len, completed, forward, log_file, output_path, num_processes):
89
+ """Search for open reading frames (ORFs) in the nucleotide sequence you enter, and return maximum length ORF of each nucleotide sequence."""
90
+ main(fasta_files, parse_seqids, min_len, completed, forward, log_file, output_path, num_processes)
91
+
92
+
93
+ if __name__ == '__main__':
94
+ run()
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env python
2
+ """
3
+ File: SSR_finder.py
4
+ Description: Find simple sequence repeat (SSR) in the DNA sequences.
5
+ CreateDate: 2023/9/9
6
+ Author: xuwenlin
7
+ E-mail: wenlinxu.njfu@outlook.com
8
+ """
9
+ from io import TextIOWrapper
10
+ from typing import Union
11
+ import click
12
+ from pybioinformatic import Fasta, Nucleotide, TaskManager, Displayer
13
+ displayer = Displayer(__file__.split('/')[-1], version='0.1.0')
14
+
15
+
16
+ def sub_processing(nucl: Nucleotide):
17
+ return nucl.find_SSR()
18
+
19
+
20
+ def main(fasta_file: Union[str, TextIOWrapper],
21
+ parse_seqids: bool,
22
+ quiet: bool,
23
+ num_processing: int,
24
+ output_file: TextIOWrapper = None):
25
+ click.echo('# Seq_id\tStart\tEnd\tSSR_unit\tSSR_seq', output_file)
26
+ with Fasta(fasta_file) as fa:
27
+ params = ((nucl,) for nucl in fa.parse(parse_seqids))
28
+ tkm = TaskManager(num_processing=num_processing, params=params)
29
+ tkm.parallel_run_func(sub_processing,
30
+ lambda i: click.echo(i.strip(), err=True) if not quiet and 'not found' in i else
31
+ click.echo(i.strip(), output_file))
32
+
33
+
34
+ @click.command(context_settings=dict(help_option_names=['-h', '--help']))
35
+ @click.option('-i', '--fasta_file', 'fasta_file',
36
+ metavar='<fasta file|stdin>', type=click.File('r'), required=True,
37
+ help='Input FASTA file.')
38
+ @click.option('-p', '--parse_seqids', 'parse_seqids',
39
+ is_flag=True, flag_value=True,
40
+ help='Parse sequence IDs.')
41
+ @click.option('-q', '--quiet', 'quiet',
42
+ is_flag=True, flag_value=True,
43
+ help='Do not report sequence that not found SSR motif.')
44
+ @click.option('-n', '--num_processing', 'num_processing',
45
+ metavar='<int>', type=int, default=1, show_default=True,
46
+ help='Number of processing.')
47
+ @click.option('-o', '--output_file', 'output_file',
48
+ metavar='<file|stdout>', type=click.File('w'),
49
+ help='Output file, stdout by default.')
50
+ @click.option('-V', '--version', 'version', help='Show author and version information.',
51
+ is_flag=True, is_eager=True, expose_value=False, callback=displayer.version_info)
52
+ def run(fasta_file, parse_seqids, quiet, num_processing, output_file):
53
+ """Find simple sequence repeat (SSR) in the DNA sequences."""
54
+ main(fasta_file, parse_seqids, quiet, num_processing, output_file)
55
+
56
+
57
+ if __name__ == '__main__':
58
+ run()
@@ -0,0 +1,30 @@
1
+ from biofile_kit.fasta_utils.fa2tab import run as fa2tab
2
+ from biofile_kit.fasta_utils.format_fasta import run as format_fasta
3
+ from biofile_kit.fasta_utils.gap_location import run as gap_location
4
+ from biofile_kit.fasta_utils.generate_random_nucl import run as generate_random_nucl
5
+ from biofile_kit.fasta_utils.get_longest_seq_for_gene import run as get_longest_seq_for_gene
6
+ from biofile_kit.fasta_utils.get_reverse_complementary_seq import run as get_reverse_complementary_seq
7
+ from biofile_kit.fasta_utils.get_seq_len import run as get_seq_len
8
+ from biofile_kit.fasta_utils.id_index_seq import run as id_index_seq
9
+ from biofile_kit.fasta_utils.motif_finder import run as motif_finder
10
+ from biofile_kit.fasta_utils.ORF_finder import run as ORF_finder
11
+ from biofile_kit.fasta_utils.seq_rename import run as seq_rename
12
+ from biofile_kit.fasta_utils.SSR_finder import run as SSR_finder
13
+
14
+ __version__ = '0.1.0'
15
+
16
+ __all__ = [
17
+ 'fa2tab',
18
+ 'format_fasta',
19
+ 'gap_location',
20
+ 'generate_random_nucl',
21
+ 'get_longest_seq_for_gene',
22
+ 'get_reverse_complementary_seq',
23
+ 'get_seq_len',
24
+ 'id_index_seq',
25
+ 'motif_finder',
26
+ 'ORF_finder',
27
+ 'seq_rename',
28
+ 'SSR_finder',
29
+ '__version__'
30
+ ]
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env python
2
+ """
3
+ File: fa2tab.py
4
+ Description:
5
+ CreateDate: 2023/10/14
6
+ Author: xuwenlin
7
+ E-mail: wenlinxu.njfu@outlook.com
8
+ """
9
+ from typing import Union
10
+ from io import TextIOWrapper
11
+ import click
12
+ from pybioinformatic import Fasta, Displayer
13
+ displayer = Displayer(__file__.split('/')[-1], version='0.1.0')
14
+
15
+
16
+ def main(fasta_file: Union[str, TextIOWrapper],
17
+ parse_seqids: bool = True,
18
+ output_file: TextIOWrapper = None):
19
+ with Fasta(fasta_file) as fa:
20
+ for ret in fa.fa2tab(parse_seqids):
21
+ click.echo(ret, output_file)
22
+
23
+
24
+ @click.command(context_settings=dict(help_option_names=['-h', '--help']))
25
+ @click.option('-i', '--fasta_file', 'fasta_file',
26
+ metavar='<fasta file|stdin>', type=click.File('r'), required=True,
27
+ help='Input FASTA file.')
28
+ @click.option('-p', '--parse_seqids', 'parse_seqids',
29
+ is_flag=True, flag_value=True,
30
+ help='Parse sequence id.')
31
+ @click.option('-o', '--output_file', 'output_file',
32
+ metavar='<file|stdout>', type=click.File('w'),
33
+ help='Output tab delimited text file, stdout by default.')
34
+ @click.option('-V', '--version', 'version', help='Show author and version information.',
35
+ is_flag=True, is_eager=True, expose_value=False, callback=displayer.version_info)
36
+ def run(fasta_file, parse_seqids, output_file):
37
+ """Description."""
38
+ main(fasta_file, parse_seqids, output_file)
39
+
40
+
41
+ if __name__ == '__main__':
42
+ run()
@@ -0,0 +1,91 @@
1
+ #!/usr/bin/env python
2
+ """
3
+ File: format_fasta.py
4
+ Description: Make each sequence to be displayed in a single line or in multiple lines and sort sequence by length or ID.
5
+ CreateDate: 2022/3/23
6
+ Author: xuwenlin
7
+ E-mail: wenlinxu.njfu@outlook.com
8
+ """
9
+ from typing import Union
10
+ from io import TextIOWrapper
11
+ from re import findall
12
+ from natsort import natsort_key
13
+ import click
14
+ from pybioinformatic import Fasta, Displayer
15
+ displayer = Displayer(__file__.split('/')[-1], version='0.2.0')
16
+
17
+
18
+ def main(fasta_file: Union[str, TextIOWrapper],
19
+ parse_seqids: bool = True,
20
+ char_num: int = 60,
21
+ sort_by_len: bool = True,
22
+ sort_by_id: bool = True,
23
+ reverse_id: bool = False,
24
+ reverse_len: bool = False,
25
+ out_file: TextIOWrapper = None):
26
+ with Fasta(fasta_file) as fa:
27
+ seq_obj_generator = fa.merge_sequence(parse_seqids) if char_num == 0 else \
28
+ fa.split_sequence(parse_seqids, char_num)
29
+ seq_obj_list = [seq_obj for seq_obj in seq_obj_generator]
30
+ if sort_by_len and not sort_by_id:
31
+ seq_obj_list.sort(key=lambda i: i.len, reverse=reverse_len)
32
+ elif not sort_by_len and sort_by_id:
33
+ seq_obj_list.sort(key=lambda seq_obj: natsort_key(seq_obj.id), reverse=reverse_id)
34
+ elif sort_by_len and sort_by_id:
35
+ if reverse_len:
36
+ seq_obj_list.sort(
37
+ key=lambda seq_obj: (-seq_obj.len, natsort_key(seq_obj.id), int(findall(r'\d+', seq_obj.id)[0])),
38
+ reverse=reverse_id
39
+ )
40
+ else:
41
+ seq_obj_list.sort(
42
+ key=lambda seq_obj: (seq_obj.len, natsort_key(seq_obj.id), int(findall(r'\d+', seq_obj.id)[0])),
43
+ reverse=reverse_id
44
+ )
45
+ for seq_obj in seq_obj_list:
46
+ click.echo(seq_obj, out_file)
47
+
48
+
49
+ @click.command(context_settings=dict(help_option_names=['-h', '--help']))
50
+ @click.argument('fasta_file', metavar='<fasta file|stdin>', nargs=1, required=True, type=click.File('r'))
51
+ @click.option('-p', '--parse_seqids', 'parse_seqids',
52
+ is_flag=True, flag_value=True,
53
+ help='Parse sequence id.')
54
+ @click.option('-n', '--char_num', 'char_num',
55
+ metavar='<int>', type=int, default=60, show_default=True,
56
+ help='Specify how many character show in per line, 0 presents one line show per sequence.')
57
+ @click.option('-l', '--sort_by_len', 'sort_by_len',
58
+ is_flag=True, flag_value=True,
59
+ help='Sort sequence by length. If both "-L, --sort_by_len" and "-I, --sort_by_id" options are specified, '
60
+ 'sort by length first then id by default.')
61
+ @click.option('-i', '--sort_by_id', 'sort_by_id',
62
+ is_flag=True, flag_value=True,
63
+ help='Sort sequence by id. If both "-L, --sort_by_len" and "-I, --sort_by_id" options are specified, '
64
+ 'sort by length first then id by default.')
65
+ @click.option('-r', '--reverse-id', 'reverse_id',
66
+ is_flag=True, flag_value=True,
67
+ help='Reverse the result of sort by id.')
68
+ @click.option('-R', '--reverse-len', 'reverse_len',
69
+ is_flag=True, flag_value=True,
70
+ help='Reverse the result of sort by length.')
71
+ @click.option('-o', '--output_file', 'outfile',
72
+ metavar='<fasta file|stdout>', type=click.File('w'),
73
+ help='Output file, stdout by default.')
74
+ @click.option('-V', '--version', 'version', help='Show author and version information.',
75
+ is_flag=True, is_eager=True, expose_value=False, callback=displayer.version_info)
76
+ def run(fasta_file, parse_seqids, char_num, sort_by_len, sort_by_id, reverse_id, reverse_len, outfile):
77
+ """Make each sequence to be displayed in a single line or in multiple lines and sort sequence by length or ID."""
78
+ main(
79
+ fasta_file=fasta_file,
80
+ parse_seqids=parse_seqids,
81
+ char_num=char_num,
82
+ sort_by_len=sort_by_len,
83
+ sort_by_id=sort_by_id,
84
+ reverse_id=reverse_id,
85
+ reverse_len=reverse_len,
86
+ out_file=outfile
87
+ )
88
+
89
+
90
+ if __name__ == '__main__':
91
+ run()
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env python
2
+ """
3
+ File: gap_location.py
4
+ Description: Gap location.
5
+ CreateDate: 2025/5/26
6
+ Author: xuwenlin
7
+ E-mail: wenlinxu.njfu@outlook.com
8
+ """
9
+ from typing import Union
10
+ from io import TextIOWrapper
11
+ import click
12
+ from pybioinformatic import Fasta, Displayer
13
+
14
+ displayer = Displayer(__file__.split('/')[-1], version='0.1.0')
15
+
16
+
17
+ def main(asm_file: Union[str, TextIOWrapper],
18
+ output_file: TextIOWrapper = None):
19
+ with Fasta(asm_file) as fa:
20
+ for seq_obj in fa.parse():
21
+ for gap in seq_obj.locate_gap():
22
+ click.echo(gap, output_file)
23
+
24
+
25
+ @click.command(context_settings=dict(help_option_names=['-h', '--help']))
26
+ @click.argument('asm_file', metavar='<assembly fasta file | stdin>', required=True, nargs=1)
27
+ @click.option('-o', '--output-file', 'output_file',
28
+ metavar='<file|stdout>', type=click.File('w'),
29
+ help='Output file, stdout by default.')
30
+ @click.option('-V', '--version', 'version', help='Show author and version information.',
31
+ is_flag=True, is_eager=True, expose_value=False, callback=displayer.version_info)
32
+ def run(asm_file, output_file):
33
+ """Gap location."""
34
+ main(asm_file, output_file)
35
+
36
+
37
+ if __name__ == '__main__':
38
+ run()
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env python
2
+ """
3
+ File: generate_random_nucl.py
4
+ Description: Generate random nucleotide sequence.
5
+ CreateDate: 2025/5/16
6
+ Author: xuwenlin
7
+ E-mail: wenlinxu.njfu@outlook.com
8
+ """
9
+ from io import TextIOWrapper
10
+ from typing import Union, List
11
+ import click
12
+ from pybioinformatic import Nucleotide, Displayer
13
+
14
+ displayer = Displayer(__file__.split('/')[-1], version='0.1.0')
15
+
16
+
17
+ def check_params(
18
+ names: Union[List[str], str, None],
19
+ length: Union[List[int], int, None]
20
+ ):
21
+ if all([isinstance(names, list), isinstance(length, list)]) and len(names) != len(length):
22
+ click.echo('\033[31mError: The name and the quantity of the length do not match.\033[0m', err=True)
23
+ exit()
24
+
25
+
26
+ def main(names: Union[List[str], str, None],
27
+ length: Union[List[int], str, None],
28
+ bias: Union[List[float], str, None],
29
+ output_file: TextIOWrapper = None):
30
+ check_params(names, length)
31
+ if isinstance(names, list) and isinstance(length, list):
32
+ for i in range(len(names)):
33
+ click.echo(Nucleotide.random_nucl(name=names[i], length=length[i], bias=bias), output_file)
34
+ else:
35
+ click.echo(Nucleotide.random_nucl(name=names, length=length, bias=bias), output_file)
36
+
37
+
38
+ @click.command(context_settings=dict(help_option_names=['-h', '--help']))
39
+ @click.option('-n', '--names', 'names', metavar='<str>',
40
+ help='Nucleotide sequence name. Multiple names should be separated by commas (eg. seq1,se2),'
41
+ 'and the number of names should be consistent with the "-l, --length" option values.')
42
+ @click.option('-l', '--length', 'length', metavar='<str>',
43
+ help='Nucleotide sequence length. Multiple length should be separated by commas,'
44
+ 'and the number of length should be consistent with the "-n, --names" option values (eg. 100,200).')
45
+ @click.option('-b', '--bias', 'bias', metavar='<str>',
46
+ help='Nucleotide sequence bias of AGCT. Multiple bias should be separated by commas (eg. 0.25,0.5,0.1,0.15).')
47
+ @click.option('-o', '--output-file', 'output_file',
48
+ metavar='<file|stdout>', type=click.File('w'),
49
+ help='Output file, stdout by default.')
50
+ @click.option('-V', '--version', 'version', help='Show author and version information.',
51
+ is_flag=True, is_eager=True, expose_value=False, callback=displayer.version_info)
52
+ def run(names, length, bias, output_file):
53
+ """Generate random nucleotide sequence."""
54
+ if names is not None and ',' in names:
55
+ names = names.split(',')
56
+ if length is not None and ',' in length:
57
+ length = [int(i) for i in length.split(',')]
58
+ elif isinstance(length, str):
59
+ length = int(length)
60
+ if bias is not None and ',' in bias:
61
+ bias = [float(i) for i in bias.split(',')]
62
+ main(names, length, bias, output_file)
63
+
64
+
65
+ if __name__ == '__main__':
66
+ run()