<p>Could you try loading <code>fastStructure</code> via conda?</p>
<pre><code>conda create --name faststruc python=3.9 # there can be issues with 3.10
conda activate faststruc
conda install -c bioconda faststructure 
</code></pre>
<p>It will then ask you whether you want to install <code>numpy</code> and <code>scipy</code> automatically. Furthermore all dependencies are installed and connectivity will have already been tested. You can easily delete everything afterwards by deleting the environment <code>faststruc</code> so keeps everything clean.</p>
<hr />
<p>The code in question is here:</p>
<p><a href="https://programtalk.com/python-examples/vars.utils.insum/" rel="nofollow noreferrer">https://programtalk.com/python-examples/vars.utils.insum/</a></p>
<p>Its a <code>numpy</code> calculation, what they are doing is navigating Python by leveraging the power of <code>numpy</code>, which is very fast.</p>
<p>Code ...</p>
<pre><code>bestKs = []
for file in files:
    handle = open(file,'r')
    Q = np.array([map(float,line.strip().split()) for line in handle])
    Q = Q/utils.insum(Q,[1])
    handle.close()
    N = Q.shape[0]
    C = np.cuemsum(np.sort(Q.sum(0))[::-1])
    bestKs.append(np.sum(C&lt;N-1)+1)

return bestKs
</code></pre>
<p>The code looks good, they know their stuff.</p>

CC BY-SA 4.0
2022-07-08T04:05:50.523Z
2022-07-08T04:13:45.433Z
2022-07-08T04:13:45.433Z
M__
<p>I've been working with the fastStructure program and am on the step of analyzing model complexity using the provided chooseK.py script. I have been running into the following error:</p>
<pre><code>Traceback (most recent call last):
  File &quot;chooseK.py&quot;, line 109, in &lt;module&gt;
    bestKs = parse_varQs(files)
  File &quot;chooseK.py&quot;, line 54, in parse_varQs
    Q = Q/utils.insum(Q,[1])
AttributeError: module 'vars' has no attribute 'insum'
</code></pre>
<p>I have run into 'AttributeError' messages in the past and have attempted the solution of renaming files in my working directory that may be shadowing the real module (similar to: <a href="https://stackoverflow.com/questions/36530726/using-numpy-module-object-has-no-attribute-array">https://stackoverflow.com/questions/36530726/using-numpy-module-object-has-no-attribute-array</a>), but this hasn't fixed anything. Reinstalling Numpy/Scipy/fastStructure has also been a dead end.</p>
<p>Any suggestions are much appreciated! Happy to provide more info as needed.</p>
<p>-A</p>

CC BY-SA 4.0
2022-07-07T21:12:41.820Z
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
Community
CC BY-SA 4.0
2022-07-08T00:13:09.057Z
did you build the library extensions? The module vars.utils are imported as utils, so the attribute insum is undetected. https://stackoverflow.com/questions/46312470/difference-between-methods-and-attributes-in-python
zorbax
<python><scipy>
AttributeError [in fastStructure's chooseK.py]: module 'vars' has no attribute 'insum'
# AttributeError [in fastStructure's chooseK.py]: module 'vars' has no attribute 'insum'

(Asked by: username_0 on 2022-07-07)

I've been working with the fastStructure program and am on the step of analyzing model complexity using the provided chooseK.py script. I have been running into the following error:
Traceback (most recent call last):
  File "chooseK.py", line 109, in 
    bestKs = parse_varQs(files)
  File "chooseK.py", line 54, in parse_varQs
    Q = Q/utils.insum(Q,[1])
AttributeError: module 'vars' has no attribute 'insum'

I have run into 'AttributeError' messages in the past and have attempted the solution of renaming files in my working directory that may be shadowing the real module (similar to: https://stackoverflow.com/questions/36530726/using-numpy-module-object-has-no-attribute-array), but this hasn't fixed anything. Reinstalling Numpy/Scipy/fastStructure has also been a dead end.
Any suggestions are much appreciated! Happy to provide more info as needed.
-A

**Tags:** python, scipy
> **Comments:**
> **username_1**: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.  
> **username_2**: did you build the library extensions? The module vars.utils are imported as utils, so the attribute insum is undetected. https://stackoverflow.com/questions/46312470/difference-between-methods-and-attributes-in-python  

---

## 1 answers

### Answer by username_3 on 2022-07-08. Score: 0

Could you try loading fastStructure via conda?
conda create --name faststruc python=3.9 # there can be issues with 3.10
conda activate faststruc
conda install -c bioconda faststructure 

It will then ask you whether you want to install numpy and scipy automatically. Furthermore all dependencies are installed and connectivity will have already been tested. You can easily delete everything afterwards by deleting the environment faststruc so keeps everything clean.

The code in question is here:
https://programtalk.com/python-examples/vars.utils.insum/
Its a numpy calculation, what they are doing is navigating Python by leveraging the power of numpy, which is very fast.
Code ...
bestKs = []
for file in files:
    handle = open(file,'r')
    Q = np.array([map(float,line.strip().split()) for line in handle])
    Q = Q/utils.insum(Q,[1])
    handle.close()
    N = Q.shape[0]
    C = np.cuemsum(np.sort(Q.sum(0))[::-1])
    bestKs.append(np.sum(C
The code looks good, they know their stuff.


---

