annotate gff_to_bed_converter.py @ 0:498748c87252 draft

planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
author iuc
date Fri, 14 Jun 2024 21:23:54 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
1 #!/usr/bin/env python
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
2
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
3 import sys
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
4
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
5 assert sys.version_info[:2] >= (2, 6)
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
6
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
7
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
8 def __main__():
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
9 skipped_lines = 0
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
10 first_skipped_line = None
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
11 # was sys.argv[2] but we need stdout for a pipe in bam_bed_gff_to_bigwig.xml
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
12 for i, line in enumerate(sys.stdin):
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
13 line = line.rstrip("\r\n")
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
14 if line and not line.startswith("#"):
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
15 try:
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
16 elems = line.split("\t")
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
17 start = str(int(elems[3]) - 1)
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
18 endoff = str(int(elems[4]) - 1)
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
19 # GFF format: chrom, source, name, chromStart, chromEnd, score, strand
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
20 # bedtools puts out only 4 fields: chrom, chromStart, chromEnd, score
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
21 sys.stdout.write(f"{elems[0]}\t{start}\t{endoff}\t0\n")
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
22 except Exception:
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
23 skipped_lines += 1
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
24 if not first_skipped_line:
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
25 first_skipped_line = i + 1
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
26 else:
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
27 skipped_lines += 1
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
28 if not first_skipped_line:
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
29 first_skipped_line = i + 1
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
30
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
31
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
32 if __name__ == "__main__":
498748c87252 planemo upload for repository https://www.encodeproject.org/software/bedgraphtobigwig/ commit fa9d44f1ca94a7522f21db6c7771764e1b8d92a5
iuc
parents:
diff changeset
33 __main__()