Mercurial > repos > p.lucas > fasta_to_fastq
comparison fasta_to_fastq.py @ 1:60e768cf5101 draft
Uploaded
author | p.lucas |
---|---|
date | Tue, 23 Jul 2024 14:28:53 +0000 |
parents | |
children | 2f317786c4e7 |
comparison
equal
deleted
inserted
replaced
0:3c99ff6e67ca | 1:60e768cf5101 |
---|---|
1 #!/usr/bin/python | |
2 #-*- coding: utf-8 -*- | |
3 | |
4 """ | |
5 | |
6 Scripts ayant pour rôle l'extraction de tous les noms de segment contenus dans un fichier genbank. | |
7 Réalisé par Pierrick Lucas. | |
8 Usage : python fastq_to_fastq.py -i sequences.fasta -s 40 -o output_file.fastq | |
9 | |
10 """ | |
11 | |
12 # Import | |
13 import argparse | |
14 import sys | |
15 import os | |
16 from Bio import SeqIO | |
17 | |
18 ##### MAIN | |
19 def __main__(): | |
20 # Options : | |
21 parser = argparse.ArgumentParser(description="""Takes a fasta file and converts it to fastq file with a fake quality score.""", | |
22 epilog="""This script need few options, use -h to see it.""") | |
23 parser.add_argument("-i", "--infile", dest="infile", help="Input fasta file.") | |
24 parser.add_argument("-s", "--score", type=int, default=40, dest="score", help="Quality score you wanted for each base in all reads. (default: 40)") | |
25 parser.add_argument("-o", "--outfile", dest="outfile", help="Output file in fastq format.") | |
26 | |
27 if len(sys.argv) == 1 or len(sys.argv) < 5 or len(sys.argv) > 7: | |
28 parser.print_help() | |
29 sys.exit(1) | |
30 | |
31 # Get options : | |
32 options = parser.parse_args() | |
33 infile = options.infile | |
34 score = options.score | |
35 outfile = options.outfile | |
36 | |
37 outputfile = open(outfile,"w") | |
38 | |
39 # Check score | |
40 if score < 0: | |
41 sys.exit("Error: only positive integers for the score".format(score)) | |
42 | |
43 # Create fastq output file | |
44 with open(infile, "r") as inf: | |
45 for record in SeqIO.parse(inf, "fasta"): | |
46 record.letter_annotations["phred_quality"] = [score] * len(record) | |
47 SeqIO.write(record, outputfile, "fastq") | |
48 | |
49 # Close output file | |
50 outputfile.close() | |
51 | |
52 #### MAIN END | |
53 if __name__ == "__main__": __main__() |