Calculate the direction of gggenes data in R

  Kiến thức lập trình

How could I plot a group of genes in the same directions using gggenes and ggplot2 ?

I have a data obtained from a .gff file, it was generated with prokka, then it was imported with gggenomes::read_feats function, and get the genes that I want to plot, it generate the next data:

df
     file_id      seq_id  start    end strand        feat_id      locus_tag orientation     gene       cluster position
1  GENOME300 GENOME300_1 199743 201911      - IMEHDJCA_00189 IMEHDJCA_00189          -1    geneE cluster_00365   200827
2  GENOME300 GENOME300_1 201914 203275      - IMEHDJCA_00190 IMEHDJCA_00190          -1    geneD cluster_01313   202594
3  GENOME300 GENOME300_1 203272 205377      - IMEHDJCA_00191 IMEHDJCA_00191          -1    geneB cluster_00403   204324
4  GENOME300 GENOME300_1 205817 206176      + IMEHDJCA_00192 IMEHDJCA_00192           1 gene1033 cluster_06099   205996
5  GENOME300 GENOME300_1 206268 206663      + IMEHDJCA_00193 IMEHDJCA_00193           1    geneC cluster_05858   206465
6  GENOME300 GENOME300_1 206686 222306      + IMEHDJCA_00194 IMEHDJCA_00194           1    geneA cluster_00001   214496
7  GENOME320 GENOME320_8 123699 139310      - ILCJGNBA_01570 ILCJGNBA_01570          -1    geneA cluster_00001   131504
8  GENOME320 GENOME320_8 139333 139728      - ILCJGNBA_01571 ILCJGNBA_01571          -1    geneC cluster_05858   139530
9  GENOME320 GENOME320_8 139820 140179      - ILCJGNBA_01572 ILCJGNBA_01572          -1 gene1033 cluster_06099   139999
10 GENOME320 GENOME320_8 140619 142724      + ILCJGNBA_01573 ILCJGNBA_01573           1    geneB cluster_00403   141671
11 GENOME320 GENOME320_8 142721 144082      + ILCJGNBA_01574 ILCJGNBA_01574           1    geneD cluster_01322   143401
12 GENOME320 GENOME320_8 144085 146253      + ILCJGNBA_01575 ILCJGNBA_01575           1    geneE cluster_00365   145169

When I generate the plot, the genes of each genome are in different direction, is any way to recalculate the position for genes in GENOME320 and be in the same direction than GENOME300 ??

ggplot(df, aes(xmin = start, xmax = end, y = file_id, fill = gene)) +
    geom_gene_arrow(aes(forward = orientation), arrow_body_height = unit(7, "mm"), 
                    arrowhead_height = unit(7, "mm"), 
                    arrowhead_width = unit(5.7, "mm")) + 
    scale_fill_manual(values = c("orange", "blue", "red",  "green", "yellow", "#878787")) +
    facet_wrap(~ file_id, scales = "free", ncol = 1) +
    scale_y_discrete(position="right") +
    gggenes::theme_genes() +
    theme(panel.background = element_rect(fill = 'white' , color = 'white' ),
          panel.grid.major.y = ggplot2::element_line(colour = "grey", linewidth = 0.6),
          axis.title.y= element_blank(), 
          axis.text.y = element_text(size = 14, # sample name size
                                     family="Times New Roman", 
                                     face="bold"),
          plot.margin = unit(c(t=0.3, b=0.3, r=0.3, l=0.001), "mm") 
    )

enter image description here

Any suggestion ??!!

thanks

LEAVE A COMMENT