Edinburgh-Genome-Foundry / DnaFeaturesViewer

:eye: Python library to plot DNA sequence features (e.g. from Genbank files)
https://edinburgh-genome-foundry.github.io/DnaFeaturesViewer/
MIT License
584 stars 90 forks source link

figure is not coming #71

Closed byeollee closed 1 year ago

byeollee commented 1 year ago

Hi,

I got some problem to visualize my plot

here is my code

`# plot makeing

from dna_features_viewer import GraphicFeature, GraphicRecord import pprint from BCBio import GFF from dna_features_viewer import BiopythonTranslator import matplotlib as mpl from matplotlib import pyplot as plt

filelist = os.listdir() gffinput = [file for file in filelist if file.endswith(".gff")]

mpl.rcParams['font.family'] = "Times new roman" mpl.rc('xtick', labelsize=5)

class CustomTranslator(BiopythonTranslator): label_fields = ["label", "note", "name", "gene"]

def compute_feature_legend_text(self, feature):
    return feature.type

def compute_feature_color(self, feature):
    return {
        "IP" : "#ffd383",
        "AH" : "yellow",
    }[feature.type]

def compute_feature_box_color(self, feature):
    return "white"

def compute_feature_box_linewidth(self, feature):
    return 0

translator = CustomTranslator()

for file in gffinput: fig, ax = plt.subplots() gff_records = [] file2 = open(file) for rec in GFF.parse(file2): gff_records.append(rec) else: file2.close() for line in startend: if str(file) in str(line): start = int(line.split("\t")[1]) end = int(line.split("\t")[2].split("\n")[0]) record = translator.translate_record(gffrecords[0][start:end]) ax, = record.plot(figure_width=13, strand_in_label_threshold=7) ax.figure.savefig(f"{file}.svg", bbox_inches="tight")`

after blank plot coming...

Thank you.

I attach my one gff file.

IPGI_1 CDS IP 515265 537111 . + 0 IPGI_1 IPGI_2 CDS IP 671625 676541 . + 0 IPGI_2 IPGI_3 CDS IP 1054545 1062076 . + 0 IPGI_3 AHGI1 CDS AH 140000 145000 . + 0 AHGI1 AHGI2 CDS AH 217500 222500 . + 0 AHGI2 AHGI3 CDS AH 517500 537500 . + 0 AHGI3 AHGI4 CDS AH 670000 677500 . + 0 AHGI4 AHGI5 CDS AH 1237500 1242500 . + 0 AHGI5 AHGI6 CDS AH 1745000 1750000 . + 0 AHGI6 AHGI7 CDS AH 1830000 1837500 . + 0 AHGI7 AHGI8 CDS AH 2245000 2250000 . + 0 AHGI8 AHGI9 CDS AH 2682500 2697500 . + 0 AHGI9 AHGI10 CDS AH 3062500 3067500 . + 0 AHGI10 AHGI11 CDS AH 3092500 3105000 . + 0 AHGI11 AHGI12 CDS AH 3107500 3115000 . + 0 AHGI12 AHGI13 CDS AH 3125000 3130000 . + 0 AHGI13 AHGI14 CDS AH 3170000 3177500 . + 0 AHGI14 AHGI15 CDS AH 3185000 3195000 . + 0 AHGI15 AHGI16 CDS AH 3275000 3280000 . + 0 AHGI16