Structure Harvester with Python

426 views
Skip to first unread message

Travis Rainey

unread,
Feb 14, 2024, 3:34:28 PMFeb 14
to structure-software
Greetings all, 

I've been using the Structure Harvester website for Evanno method and generating CLUMPP files. I know it is down and that the Python script is available. However, I have never used Python, and all the replies on forums and such just refer back to the github page for Structure Harvester. It seems to be a simple one line of code, but I cannot get this to work. I have the two ".py" files in a directory with my STRUCTURE results folder, and I've tried to run it many times working on small syntax changes to no avail. 
Is there a step-by-step tutorial on using SH in Python somewhere for someone like me with no Python experience?

Thanks for any help,
Travis

Vikram Chhatre

unread,
Feb 14, 2024, 3:35:26 PMFeb 14
to structure...@googlegroups.com
Show us:

- The code you are typing exactly
- A listing of your current directory (ls -l)



--
You received this message because you are subscribed to the Google Groups "structure-software" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structure-softw...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/structure-software/34285e54-8eb0-4ad2-84ef-eb6aaf594fafn%40googlegroups.com.

Travis Rainey

unread,
Feb 14, 2024, 4:02:23 PMFeb 14
to structure-software
currently, I've been trying iterations like or similar to this, trying with different quote and slash variations...

python 'C:\Users\raine1t\Desktop\python2\structureHarvester.py' --dir='C:\Users\raine1t\Desktop\python2\STR4_results.zip' --out='C:\Users\raine1t\Desktop\python2'

the directory is at... 

C:\Users\raine1t\Desktop\python2

within the directory, I have the "harvesterCore.py" and "structureHarvester.py" files, straight from the github page, and my STRUCTURE results folder (STR4_results), both zipped and unzipped

Vikram Chhatre

unread,
Feb 14, 2024, 4:10:03 PMFeb 14
to structure...@googlegroups.com
You do not need quotations around the paths. And the --dir option is looking for the directory containing structure results, not a file, so remove the zip file name.

cd C:\Users\raine1t\Desktop

python python2\structureHarvester.py --dir=python2\ --out=python2\ --evanno --clumpp



Travis Rainey

unread,
Feb 14, 2024, 4:25:54 PMFeb 14
to structure-software
Thank you for your help!
Now, when trying to set the directory, I'm getting a syntax error...
 
   cd C:\Users\raine1t\Desktop
       ^
SyntaxError: invalid syntax

Vikram Chhatre

unread,
Feb 14, 2024, 4:27:07 PMFeb 14
to structure...@googlegroups.com
I don't use Windows so can't help you there. A crash course in Windows commandline interface is in order.

Travis Rainey

unread,
Feb 14, 2024, 10:49:04 PMFeb 14
to structure-software

import os
os.chdir('C:/Users/raine1t/Desktop/python2')
os.getcwd()
outputs...
 'C:\\Users\\raine1t\\Desktop\\python2' 

then trying the SH code...
python python2\structureHarvester.py --dir=python2\ --out=python2\ --evanno --clumpp
SyntaxError: unexpected character after line continuation character

error seems to be referring to the "s" after the first backslash...

Vikram Chhatre

unread,
Feb 14, 2024, 10:53:57 PMFeb 14
to structure...@googlegroups.com
You are already inside the python2 folder. So you will call the harvester script directly, not nested inside that folder. Same thing for the input and output flags. You are specifying a folder but you are already inside it. In Linux/OSX, you can specify the current directory with a period ("."), not sure if it's the same in Windows.

I highly recommend reading a basic windows/linux commandline tutorial to help you understand the relative positions within the directory tree.

Reply all
Reply to author
Forward
0 new messages