mmatschiner / tutorials

Tutorials on phylogenetic and phylogenomic inference
354 stars 165 forks source link

executing plot_d.rd script with issues #5

Closed dongyiyi closed 3 years ago

dongyiyi commented 4 years ago

Hi, I tried to run the plot_d.rd with your example dataset in ruby 2.7 in Win10 but I got the error: Traceback (most recent call last): 2: from test.rb:81:in <main>' 1: from test.rb:81:inopen' test.rb:81:in `initialize': no implicit conversion of nil into String (TypeError) What should I do? I have no idea Thanks!

mmatschiner commented 4 years ago

Hi, I just tried the same and it worked for me (on Mac OS X). Can you tell me what's on line 81 of your test.rb script? Did you try the command after downloading the three files using the links in the paragraph that starts with "To plot the heatmap, use the Ruby script..."?

dongyiyi commented 4 years ago

Hi, I downloaded the species_order.txt, samplestree.txt, samplesDmin.txt and samples__BBAA.txt. Then I copied the codes from your rsc folder run the codes: Traceback (most recent call last): 2: from test.rb:81:in

' 1: from test.rb:81:in open' test.rb:81:in `initialize': no implicit conversion of nil into String (TypeError) ################################### 80 # Read the order file. 81 order_file = File.open(heatmap_name_order_file_name) 82 order_lines = order_file.readlines 83 names_ordered = [] 84 order_lines.each do |l| 85 names_ordered << l.strip unless l[0] == "#" 86 end 87 88 # Read the asymmetry table file. 89 asymmetry_table_file = File.open(asymmetry_table_file_name) 90 asymmetry_table_lines = asymmetry_table_file.readlines

Besides, I tried to download the plot_d.rd from your link and save it to my PC. But I executed the plot_d.rd and got errors below: plot_d.rb:7: syntax error, unexpected '<' <!DOCTYPE html> plot_d.rb:8: syntax error, unexpected '<'

plot_d.rb:9: syntax error, unexpected '<' plot_d.rb:11: syntax error, unexpected '<'
mmatschiner commented 4 years ago

I see, I think you downloaded the scripts including the HTML in which they are embedded. Can you try to download in this way:

  1. Click on the links for plot_d.rb and the input files at https://github.com/mmatschiner/tutorials/tree/master/analysis_of_introgression_with_snp_data
  2. Then do right-click on the button saying "Raw" near the top right of the next window.
  3. Select "Download Linked File" (this is what it says in Safari - might be different with other browsers).

These files should not have the line numbers at the start of each line, as in the text that you pasted above.

dongyiyi commented 4 years ago

I noticed that I downloaded the HTML file, and there is not a button to "Download file". So I copy the code from https://github.com/mmatschiner/tutorials/blob/master/analysis_of_introgression_with_snp_data/src/plot_d.rb

I got the error the first one that I mentioned: Traceback (most recent call last): 2: from test.rb:81:in ' 1: from test.rb:81:in open' test.rb:81:in `initialize': no implicit conversion of nil into String (TypeError)

Yes, there is not the line number in the script.

mmatschiner commented 4 years ago

Can you try to download the files attached here in an archive and use these: Archive.zip Or at least compare them to your versions of the files? For me, it worked with the files in the archive. It seems there's an issue with the command line arguments in your case, because the second argument is apparently not recognized (the heatmap_name_order_file_name). Can you make sure that you use this command: ruby plot_d.rb samples__Dmin.txt species_order.txt 0.7 samples__Dmin.svg

dongyiyi commented 4 years ago

Thanks, I downloaded the whole tutorials-master.zip, run the plot_d.rd; Or I downloaded the Archive.zip.

I got the same errors: Traceback (most recent call last): 2: from test.rb:81:in ' 1: from test.rb:81:in open' test.rb:81:in `initialize': no implicit conversion of nil into String (TypeError)

mmatschiner commented 4 years ago

Are you sure you're running the script plot_d.rb? The error message indicates that you are running a script named test.rb.

dongyiyi commented 4 years ago

Yes, I am runnig the plot_d.rd Traceback (most recent call last): 2: from plot_d.rb:81:in <main>' 1: from plot_d.rb:81:inopen' plot_d.rb:81:in `initialize': no implicit conversion of nil into String (TypeError)

mmatschiner commented 4 years ago

Weird. Can you try to run the same command with the modfied version of the script that I attach here (sorry, it has to be compressed, otherwise GitHub won't allow uploading here): plot_d_edit.rb.zip So after uncompressing, run: ruby plot_d_edit.rb samples__Dmin.txt species_order.txt 0.7 samples__Dmin.svg The output of this may help us to understand what's going on.

dongyiyi commented 4 years ago

Cool! I didn't get any errors, but no output file "samplesDmin.svg" in the folder. I can't find the result. ruby plot_d_edit.rb samplesDmin.txt species_order.txt 0.7 samplesDmin.svg asymmetry_table_file_name: samples__Dmin.txt heatmap_name_order_file_name: species_order.txt max_d_value: 0.7 plot_file_name: samplesDmin.svg

mmatschiner commented 4 years ago

Thanks. I'm still not sure what's wrong, though. This script shows that "species_order.txt" is correctly recognized as parameter "heatmap_name_order_file_name". If you now delete lines 80-84 in the script plot_d_edit.rb, this script should have the exact same content as the original script plot_d.rb. Can you please do that and see if it runs then?

dongyiyi commented 4 years ago

I deleted lines 80-84 in the Plot_d_edit.rb, got the same error: Traceback (most recent call last): 2: from plot_d_edit.rb:82:in <main>' 1: from plot_d_edit.rb:82:inopen' plot_d_edit.rb:82:in `initialize': no implicit conversion of nil into String (TypeError)

Where I can find the output files? There is not SVG file in the current folder.

dongyiyi commented 4 years ago

Hi, Good news! I moved the "end" to the last line in the original plot_d.rd script, I got the result!

Read the order file.

order_file = File.open(heatmapname_order_file_name) order_lines = order_file.readlines names_ordered = [] order_lines.each do |l| names_ordered << l.strip unless l[0] == "#" First, end #about line 92 or 93, I deleted "end" then, I added the end ant the end of the script. When I run the script plot_d.rd, I can get the result, but I just ruby plot_d.rd, I still get the same errors: main.rb:84:in initialize': no implicit conversion of nil into String (TypeError) from main.rb:84:inopen' from main.rb:84:in `

' The run needs to take a long time, I don't check the results. I will compare these results with the pictures posted online.

mmatschiner commented 4 years ago

Did you get an SVG file? I'ld be surprised, the end is there for a reason and it should not be moved. I guess you mean the end in the line after names_ordered << l.strip unless l[0] == "#"; thus, the one that is on line 85 in this version: https://github.com/mmatschiner/tutorials/blob/master/analysis_of_introgression_with_snp_data/src/plot_d.rb Moving this end can impossibly be the solution. I'm not sure what you mean with this line:

When I run the script plot_d.rd, I can get the result, but I just ruby plot_d.rd, I still get the same errors

Is there something else that you do with the script? From your error message it now seems to be called main.rb. Did you only rename?