annotate gff_to_bed_converter.py @ 4:78e7461e8946 draft

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