annotate gff3_splitgff.py @ 4:4b60e0b6a150 draft

planemo upload commit f33bdf952d796c5d7a240b132af3c4cbd102decc
author cpt
date Fri, 05 Jan 2024 05:52:42 +0000
parents 8bd03ba8510a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
1 #!/usr/bin/env python
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
2 import sys
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
3 import argparse
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
4 from Bio import SeqIO
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
5 from Bio.Seq import Seq
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
6 from CPT_GFFParser import gffParse, gffWrite
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
7
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
8 if __name__ == "__main__":
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
9 parser = argparse.ArgumentParser(
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
10 description="Sample script to add an attribute to a feature via web services"
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
11 )
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
12 parser.add_argument("data", type=argparse.FileType("r"), help="GFF3 File")
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
13 parser.add_argument(
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
14 "--gff",
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
15 type=argparse.FileType("w"),
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
16 help="Output Annotations",
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
17 default="data.gff3",
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
18 )
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
19 parser.add_argument(
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
20 "--fasta",
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
21 type=argparse.FileType("w"),
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
22 help="Output Sequence",
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
23 default="data.fa",
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
24 )
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
25 args = parser.parse_args()
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
26
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
27 for record in gffParse(args.data):
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
28 gffWrite([record], args.gff)
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
29 record.description = ""
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
30
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
31 if isinstance(record.seq, str):
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
32 record.seq = Seq(record.seq)
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
33
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
34 SeqIO.write([record], args.fasta, "fasta")
8bd03ba8510a planemo upload commit edc74553919d09dcbe27fcadf144612c1ad3a2a2
cpt
parents:
diff changeset
35 sys.exit()