YuLab-SMU / ggmsa

:traffic_light: Visualizing publication-quality multiple sequence alignment using ggplot2
http://yulab-smu.top/ggmsa
203 stars 23 forks source link

Adjusting x axis of facet_msa? #26

Open bickibird opened 2 years ago

bickibird commented 2 years ago

Hi, I'm having difficulty visualising a sequence alignment using facet_msa. I'm knitting to a Word document. The characters end up being too narrow. The following codes were used:

{r amino-acid-sequence, fig.asp=0.3, fig.width= 10}
ggmsa(aa_seq_src, char_width = 0.9, seq_name = TRUE, color = "Chemistry_AA") +
 facet_msa(field = 200)

image

I tried changing char_width to something smaller:

{r amino-acid-sequence, fig.asp=0.3, fig.width= 10}
ggmsa(aa_seq_src, char_width = 0.1, seq_name = TRUE, color = "Chemistry_AA") +
 facet_msa(field = 200)

image

I tried adding + coord_cartesian() but nothing changed.

I also tried reducing the field to 100 and the characters end up disappearing:

{r amino-acid-sequence, fig.asp=0.3, fig.width= 10}
ggmsa(aa_seq_src, char_width = 0.1, seq_name = TRUE, color = "Chemistry_AA") +
 facet_msa(field = 100)

image

If I replace fig.asp with out.width the following occurs:

{r amino-acid-sequence, out.width = "500%", fig.width= 10}
ggmsa(aa_seq_src, char_width = 0.1, seq_name = TRUE, color = "Chemistry_AA") +
 facet_msa(field = 100)

image

Any ideas on what's going on and how I can adjust the x axis of the facets so that they are not too narrow?

nyzhoulang commented 2 years ago

Hi, @bickibird

The cause of the issues is that the canvas space is too narrow.

I suggest that renaming the second sequence name ADF454451...H7N6 to H7N6 because the long name will take up more drawing space. And giving more canvas space, see the following examples:

{r fig.asp=0.3, fig.width= 10}
ggmsa("align_fasta.fas", 
      start = 500,
      end = 1060,
      char_width = 0.9, 
      seq_name = TRUE, 
      color = "Chemistry_NT") +
  facet_msa(200)

image

{r  fig.asp=0.5, fig.width= 17}
ggmsa("align_fasta1.fas", 
      start = 500,
      end = 1060,
      color = "Chemistry_NT", 
      seq_name = TRUE, 
       border = NA) + 
  facet_msa(100)

image

Thanks, Lang

bickibird commented 2 years ago

Hi Lang,

Thanks so much for your quick reply. I have another question.

I am trying to annotate a specific region of the sequence using a trick you showed me before. However, it doesn't work if on a facet below the first one. Please see examples below:

p <- ggmsa(aa_sequence, 
           char_width = 0.7,
           seq_name = TRUE, consensus_views = TRUE, disagreement = FALSE, use_dot = FALSE, ref = "A_HA_H7",
           color = "Chemistry_AA") +
  facet_msa(field = 100) 

dummy <- subset(p$layers[[1]]$data,  facet == 0)

p + geom_rect(data = dummy, mapping = aes(xmin = 32, xmax = 42, ymin = -Inf, ymax = Inf),
color = "black", size = 1.5, fill = NA) 

sequence

p <- ggmsa(aa_sequence, 
           char_width = 0.7,
           seq_name = TRUE, consensus_views = TRUE, disagreement = FALSE, use_dot = FALSE, ref = "A_HA_H7",
           color = "Chemistry_AA") +
  facet_msa(field = 100) 

dummy <- subset(p$layers[[1]]$data,  facet == 0)

p + geom_rect(data = dummy, mapping = aes(xmin = 332, xmax = 342, ymin = -Inf, ymax = Inf),
color = "black", size = 1.5, fill = NA) 

sequence

nyzhoulang commented 2 years ago

Hi @bickibird

dummy <- subset(p$layers[[1]]$data, facet == 0)

The specified facet is wrong, the region 332-342 is in the fourth row. Thus, you can replace facet == 3 with facet == 0 (facet start at 0).

Thanks, Lang