annotate bbgbigwig/gff_to_bed_converter.py @ 0:4eadb56fa314 draft

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