cozygene / FEAST

Fast expectation maximization for microbial source tracking
Other
114 stars 59 forks source link

Error in mixing_proportions[which(rownames(mixing_proportions) %in% SinkNames), : incorrect number of dimensions #50

Open melissaszy opened 1 year ago

melissaszy commented 1 year ago

Hello,

i downloaded the sample dataset and tried the sample code: library(FEAST) setwd("C:/Users/feast_trial") metadata <- Load_metadata(metadata_path = "metadata_example_multi.txt") otus <- Load_CountMatrix(CountMatrix_path = "otu_example_multi.txt") FEAST_output <- FEAST(C = otus, metadata = metadata, different_sources_flag = 1, dir_path = "C:/Users/feast_trial", outfile="demo") PlotSourceContribution(SinkNames = rownames(FEAST_output)[c(5:8)], SourceNames = colnames(FEAST_output), dir_path = "C:/Users/feast_trial", mixing_proportions = FEAST_output, Plot_title = "Test_",Same_sources_flag = 0, N = 4)

my first issue is when i ran the code above to generate FEAST_output. the tutorial states that: "FEAST will then save the file demo_FEAST.txt - A file containing an S1 by S2 matrix P, where S1 is the number sinks and S2 is the number of sources (including an unknown source). Each row in matrix P sums to 1." in my directory, i only have "demo_source_contributions_matrix.txt" file generated.

my second issue is with PlotSourceContribution

i got this error message: "Error in mixing_proportions[which(rownames(mixing_proportions) %in% SinkNames), : incorrect number of dimensions"

i am using: R version 4.2.2 FEAST version 0.1.0

May I ask how what is wrong and how i can fix these issues?

Thank you for your time!

junzhao23y commented 1 year ago

hi! I'm having the same problem as you. I wonder if you have solved it now? I'll check and check again in the next few days

Olivia-hhg commented 1 year ago

Yes, I have found a solution to the issue, but I am now somewhat busy. When I have time, I'll respond to you.

高会会

@. | On 7/9/2023 @.> wrote:

hi! I'm having the same problem as you. I wonder if you have solved it now? I'll check and check again in the next few days

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

Olivia-hhg commented 1 year ago

Hi! I apologize for the email's delayed response. The out_example_multi.txt file may include a format error that is the cause of this issue. Find this file, open it in Excel, and shift the row name one space to the left. For the whole code, please see the appendix.

高会会

@. | On 7/9/2023 @.> wrote: Yes, I have found a solution to the issue, but I am now somewhat busy. When I have time, I'll respond to you.

高会会

@. | On 7/9/2023 @.> wrote:

hi! I'm having the same problem as you. I wonder if you have solved it now? I'll check and check again in the next few days

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***> FEAST:快速准确的微生物溯源分析

加载R包

Packages <- c("Rcpp", "RcppArmadillo", "vegan", "dplyr", "reshape2", "gridExtra", "ggplot2", "ggthemes") lapply(Packages, library, character.only = TRUE)

下载FEAST

注:下载的FEAST位于"C:\Users\ghh\AppData\Local\R\win-library\4.3\FEAST"目录, 且下载之后没有Data_files文件夹,如果想用demo数据需要去GitHub本地化下载。 devtools::install_github("cozygene/FEAST")

加载FEAST

library(FEAST)

导入数据

注:下载的FEAST没有demo数据,手动下载数据后置于Data_files中,Data_files位于"C:\Users\ghh\AppData\Local\R\win-library\4.3\FEAST" 目录下,otu_example_multi.txt格式上出现了一个错误,应用excel打开并进行调整,错误为行名左移了一格。 metadata <- Load_metadata(metadata_path = "~/FEAST/Data_files/metadata_example_multi.txt") otus <- Load_CountMatrix(CountMatrix_path = "~/FEAST/Data_files/otu_example_multi.txt")

运行FEAST

注:~为C:\Users\ghh\AppData\Local\R\win-library\4.3,每个人的R中~不同,应先找到自己的下载目录。 FEAST_output <- FEAST(C = otus, metadata = metadata, different_sources_flag = 1, dir_path = "~/FEAST/Data_files/", outfile="demo") 输出的文件位于Data_files中,文件名为demo_source_contributions_matrix.txt,注:该文件也出现错误,错误为行名左移一格,置于excel中修改

可视化数据

PlotSourceContribution(SinkNames = rownames(FEAST_output)[c(5:8)], SourceNames = colnames(FEAST_output), dir_path = "~/FEAST/Data_files/", mixing_proportions = FEAST_output, Plottitle = "Test",Same_sources_flag = 0, N = 4)

Olivia-hhg commented 1 year ago

Additionally, please take note that the demo_source_contributions_matrix.txt file will likewise experience the same format fault as the out_example_multi.txt file, and that the fix is the same.

高会会

@. | On 7/10/2023 @.> wrote: Hi! I apologize for the email's delayed response. The out_example_multi.txt file may include a format error that is the cause of this issue. Find this file, open it in Excel, and shift the row name one space to the left. For the whole code, please see the appendix.

高会会

@. | On 7/9/2023 @.> wrote: Yes, I have found a solution to the issue, but I am now somewhat busy. When I have time, I'll respond to you.

高会会

@. | On 7/9/2023 @.> wrote:

hi! I'm having the same problem as you. I wonder if you have solved it now? I'll check and check again in the next few days

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

junzhao23y commented 1 year ago

Thank you so much for your help! I could run my own data now. I can not plot by this code but the result file (although format fault )is enough 😁

Best wishes

On Mon, Jul 10, 2023 at 3:29 AM Olivia-hhg @.***> wrote:

Additionally, please take note that the demo_source_contributions_matrix.txt file will likewise experience the same format fault as the out_example_multi.txt file, and that the fix is the same.

高会会

@. | On 7/10/2023 @.> wrote: Hi! I apologize for the email's delayed response. The out_example_multi.txt file may include a format error that is the cause of this issue. Find this file, open it in Excel, and shift the row name one space to the left. For the whole code, please see the appendix.

高会会

@. | On 7/9/2023 @.> wrote: Yes, I have found a solution to the issue, but I am now somewhat busy. When I have time, I'll respond to you.

高会会

@. | On 7/9/2023 @.> wrote:

hi! I'm having the same problem as you. I wonder if you have solved it now? I'll check and check again in the next few days

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/cozygene/FEAST/issues/50#issuecomment-1627916959, or unsubscribe https://github.com/notifications/unsubscribe-auth/BBEZSMSWMPSVBWE6IDFH3R3XPNLGXANCNFSM6AAAAAAVUWJ6ZY . You are receiving this because you commented.Message ID: @.***>

Panda-smile commented 7 months ago

同学,我也遇到相同问题,你方便给指导下吗?

Olivia-hhg commented 6 months ago

不好意思,刚看到邮件,请问你已经解决了吗?

高会会

@. | On 12/20/2023 @.> wrote:

同学,我也遇到相同问题,你方便给指导下吗?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

Panda-smile commented 6 months ago

没有噢同学,所以是什么问题导致的呢?

发自我的iPhone

------------------ Original ------------------ From: Olivia-hhg @.> Date: Thu,Dec 28,2023 4:18 PM To: cozygene/FEAST @.> Cc: zhangbenbenchina @.>, Comment @.> Subject: Re: [cozygene/FEAST] Error inmixing_proportions[which(rownames(mixing_proportions) %in% SinkNames), : incorrect number of dimensions (Issue #50)

不好意思,刚看到邮件,请问你已经解决了吗?

高会会

@. | On 12/20/2023 @.> wrote:

同学,我也遇到相同问题,你方便给指导下吗?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.> — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.>

Olivia-hhg commented 6 months ago
好久之前用的了,记忆不是很清晰了,但是我记得是文件位置还有数据格式的问题,我把测通的代码和操作方式 整理在了文本文档中,以附件形式先发给你,你先看看,如果不行我们可以加微信(17320273631)交流,再共同解决问题。 高会会

@. | On 12/29/2023 @.> wrote:

没有噢同学,所以是什么问题导致的呢?

发自我的iPhone

------------------ Original ------------------ From: Olivia-hhg @.> Date: Thu,Dec 28,2023 4:18 PM To: cozygene/FEAST @.> Cc: zhangbenbenchina @.>, Comment @.> Subject: Re: [cozygene/FEAST] Error inmixing_proportions[which(rownames(mixing_proportions) %in% SinkNames), : incorrect number of dimensions (Issue #50)

不好意思,刚看到邮件,请问你已经解决了吗?

高会会

@. | On 12/20/2023 @.> wrote:

同学,我也遇到相同问题,你方便给指导下吗?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.> — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.>

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***> FEAST:快速准确的微生物溯源分析

加载R包

Packages <- c("Rcpp", "RcppArmadillo", "vegan", "dplyr", "reshape2", "gridExtra", "ggplot2", "ggthemes") lapply(Packages, library, character.only = TRUE)

下载FEAST

注:下载的FEAST位于"C:\Users\ghh\AppData\Local\R\win-library\4.3\FEAST"目录, 且下载之后没有Data_files文件夹,如果想用demo数据需要去GitHub本地化下载。 devtools::install_github("cozygene/FEAST")

加载FEAST

library(FEAST)

导入数据

注:下载的FEAST没有demo数据,手动下载数据后置于Data_files中,Data_files位于"C:\Users\ghh\AppData\Local\R\win-library\4.3\FEAST" 目录下,otu_example_multi.txt格式上出现了一个错误,应用excel打开并进行调整,错误为行名左移了一格。 metadata <- Load_metadata(metadata_path = "~/FEAST/Data_files/metadata_example_multi.txt") otus <- Load_CountMatrix(CountMatrix_path = "~/FEAST/Data_files/otu_example_multi.txt")

运行FEAST

注:~为C:\Users\ghh\AppData\Local\R\win-library\4.3 FEAST_output <- FEAST(C = otus, metadata = metadata, different_sources_flag = 1, dir_path = "~/FEAST/Data_files/", outfile="demo") 输出的文件位于Data_files中,文件名为demo_source_contributions_matrix.txt,注:该文件也出现错误,错误为行名左移一格,置于excel中修改

可视化数据

PlotSourceContribution(SinkNames = rownames(FEAST_output)[c(5:8)], SourceNames = colnames(FEAST_output), dir_path = "~/FEAST/Data_files/", mixing_proportions = FEAST_output, Plottitle = "Test",Same_sources_flag = 0, N = 4)

Panda-smile commented 6 months ago

谢谢同学啦,那我先试试~(ง •̀_•́)ง加油

发自我的iPhone

------------------ Original ------------------ From: Olivia-hhg @.> Date: Fri,Dec 29,2023 9:55 AM To: cozygene/FEAST @.> Cc: zhangbenbenchina @.>, Comment @.> Subject: Re: [cozygene/FEAST] Error inmixing_proportions[which(rownames(mixing_proportions) %in% SinkNames), : incorrect number of dimensions (Issue #50)

好久之前用的了,记忆不是很清晰了,但是我记得是文件位置还有数据格式的问题,我把测通的代码和操作方式 整理在了文本文档中,以附件形式先发给你,你先看看,如果不行我们可以加微信(17320273631)交流,再共同解决问题。 高会会

@. | On 12/29/2023 @.> wrote:

没有噢同学,所以是什么问题导致的呢?

发自我的iPhone

------------------ Original ------------------ From: Olivia-hhg @.&gt; Date: Thu,Dec 28,2023 4:18 PM To: cozygene/FEAST @.&gt; Cc: zhangbenbenchina @.&gt;, Comment @.&gt; Subject: Re: [cozygene/FEAST] Error inmixing_proportions[which(rownames(mixing_proportions) %in% SinkNames), : incorrect number of dimensions (Issue #50)

不好意思,刚看到邮件,请问你已经解决了吗?

高会会

@. | On 12/20/2023 @.&gt; wrote:

同学,我也遇到相同问题,你方便给指导下吗?

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.&gt; — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.&gt;

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***> FEAST:快速准确的微生物溯源分析

加载R包

Packages <- c("Rcpp", "RcppArmadillo", "vegan", "dplyr", "reshape2", "gridExtra", "ggplot2", "ggthemes") lapply(Packages, library, character.only = TRUE)

下载FEAST

注:下载的FEAST位于"C:\Users\ghh\AppData\Local\R\win-library\4.3\FEAST"目录, 且下载之后没有Data_files文件夹,如果想用demo数据需要去GitHub本地化下载。 devtools::install_github("cozygene/FEAST")

加载FEAST

library(FEAST)

导入数据

注:下载的FEAST没有demo数据,手动下载数据后置于Data_files中,Data_files位于"C:\Users\ghh\AppData\Local\R\win-library\4.3\FEAST" 目录下,otu_example_multi.txt格式上出现了一个错误,应用excel打开并进行调整,错误为行名左移了一格。 metadata <- Load_metadata(metadata_path = "~/FEAST/Data_files/metadata_example_multi.txt") otus <- Load_CountMatrix(CountMatrix_path = "~/FEAST/Data_files/otu_example_multi.txt")

运行FEAST

注:~为C:\Users\ghh\AppData\Local\R\win-library\4.3 FEAST_output <- FEAST(C = otus, metadata = metadata, different_sources_flag = 1, dir_path = "~/FEAST/Data_files/", outfile="demo") 输出的文件位于Data_files中,文件名为demo_source_contributions_matrix.txt,注:该文件也出现错误,错误为行名左移一格,置于excel中修改

可视化数据

PlotSourceContribution(SinkNames = rownames(FEAST_output)[c(5:8)], SourceNames = colnames(FEAST_output), dir_path = "~/FEAST/Data_files/", mixing_proportions = FEAST_output, Plottitle = "Test",Same_sources_flag = 0, N = 4) — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

NeginValizadegan commented 1 month ago

It seems that the demo input files were fixed but the issues persists. Still there is only one output (demo_source_contributions_matrix.txt) and the plot cannot be created because The FEAST_output is a list so doesn't have row and col names. For plot, changing it from rownames(FEAST_output) and colnames(FEAST_output) to rownames(FEAST_output$data_prop) and colnames(FEAST_output$data_prop) will create a plot. Whether this is the plot it was supposed to create, not sure. But even with demo data, we don't get the main output which is proportions of sink in sources.

abossers-uu commented 1 month ago

You can circumvent the plotting problem by LOADING the FEAST output matrix and use that as input for the plot.
See example below:

FEAST_output <- FEAST(C = otus, metadata = metadata, different_sources_flag = 1, dir_path = "./Data_files_out",outfile="demo")
K = 2 #number of sinks to plot
FEAST_output.loaded <- read.table("./Data_files_out/demo_source_contributions_matrix.txt",row.names=1 )
PlotSourceContribution(SinkNames = rownames(FEAST_output.loaded)[c(1:K)],
                       SourceNames = colnames(FEAST_output.loaded), dir_path = "./Data_files_out",
                       mixing_proportions = FEAST_output.loaded, Plot_title = "Test_",Same_sources_flag = 0, N = 2)

To create a bit of sensible plot you can use a boxplot:

out2 <- FEAST_output.loaded %>%
  rownames_to_column("Sink") %>%
  pivot_longer( -Sink, names_to="Source", values_to="Fraction", values_drop_na=TRUE ) %>%
  mutate( "Source" = str_replace_all( Source, "ERR\\d+_", "" ) ) %>%
  mutate( "Sink" = str_replace_all( Sink, "_Env_\\d+$", "" ) ) #%>%

ggplot( out2, aes(Source, Fraction, fill=Source) ) + 
  geom_boxplot( coef=NULL, outlier.colour = NA ) + 
  geom_jitter( width=0.1 ) +
  coord_flip()

Which gives me:
image