Preparing a bed file for showing gene structure(exon/intron) by GSDS from a list of gene ID
How can I prepare a bed file for showing gene structure(exon/intron) by GSDS from a list of gene ID?
• 393 views
•
link
1 answer
looks like you are referring to https://gsds.gao-lab.org/
the example 'bed file' they give is quite unconventional
this script that I used gemini to create tries to convert gff3 into this 'bed file' type format. there are probably other considerations but ultimately you might consider using other software for plotting the gene structure, like R https://dzhang32.github.io/ggtranscript/
import sys
def convert_gff3_to_bed(input_file):
with open(input_file, 'r') as f:
for line in f:
# Skip comments and empty lines
if line.startswith('#') or not line.strip():
continue
parts = line.strip().split('\t')
if len(parts) < 9:
continue
# Extract GFF3 columns
seqid = parts[0]
feature_type = parts[2]
start = int(parts[3])
end = int(parts[4])
phase = parts[7]
# Adjust to 0-based start for BED style
# GFF [start, end] -> BED [start-1, end)
bed_start = start - 1
bed_end = end
# Format the output (seqid, start, end, feature, phase)
# We use '.' if the phase is undefined/empty
out_phase = phase if phase != '.' else '.'
print(f"{seqid}\t{bed_start}\t{bed_end}\t{feature_type}\t{out_phase}")
if __name__ == "__main__":
# Usage: python script.py your_file.gff3
if len(sys.argv) > 1:
convert_gff3_to_bed(sys.argv[1])
else:
print("Please provide a GFF3 file path.")
• 0 views
•
link
Log in to answer this question.