Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

object of type 'int' has no len() in Scaffolds.py _remove_weakest len(path) #8

Open
gtrichard opened this issue Jan 30, 2019 · 7 comments

Comments

@gtrichard
Copy link
Collaborator

One of my former colleague is trying to use HiCAssembler. He launched the following command:

assemble -m hic_corrected.h5 -o ./assembly_output  --min_scaffold_length 10000 --bin_size 5000 --misassembly_zscore_threshold -1.0  --num_iterations 3 --num_processors 16 --fasta assembly.fa

And received this error:

Traceback (most recent call last):
  File "/groups/bipaa/env/HiCExplorer_2.1.4/bin/assemble", line 312, in <module>
    main(args)
  File "/groups/bipaa/env/HiCExplorer_2.1.4/bin/assemble", line 306, in main
    super_contigs = assembl.assemble_contigs()
  File "/groups/bipaa/env/HiCExplorer_2.1.4/lib/python2.7/site-packages/hicassembler/HiCAssembler.py", line 201, in assemble_contigs
    hub_solving_method='remove weakest')
  File "/groups/bipaa/env/HiCExplorer_2.1.4/lib/python2.7/site-packages/hicassembler/Scaffolds.py", line 27, in wrapper
    f_result = func(*args, **kwds)
  File "/groups/bipaa/env/HiCExplorer_2.1.4/lib/python2.7/site-packages/hicassembler/Scaffolds.py", line 1803, in join_paths_max_span_tree
    self._remove_weakest(nxG)
  File "/groups/bipaa/env/HiCExplorer_2.1.4/lib/python2.7/site-packages/hicassembler/Scaffolds.py", line 2002, in _remove_weakest
    if len(path) < 5:
TypeError: object of type 'int' has no len()

When checking the code of Scaffolds.py, between lines 1997 and 2006, I saw that path is defined as the length of something, so it is an integer that of course doesn't have a length itself so if len(path) < 5: is crashing.

                        # adj node is hub. In this case remove the node and the scaffold it belongs
                        # to from the graph
                        path  = len(self.pg_base[node])
                        # only remove if the path is not longer than 5. Otherwise
                        # a quite large scaffold can be removed.
                        if len(path) < 5:
                            for node_id in path:
                                G.remove_node(node_id)
                            self._remove_bin_path(self.pg_base.node[node]['initial_path'], split_scaffolds=True)
                            continue

I told him to replace line 1999 of Scaffolds.py path = len(self.pg_base[node]) by path = self.pg_base[node] . Then he received a different error:

Traceback (most recent call last):
  File "/groups/bipaa/env/HiCExplorer_2.1.4/bin/assemble", line 312, in <module>
    main(args)
  File "/groups/bipaa/env/HiCExplorer_2.1.4/bin/assemble", line 306, in main
    super_contigs = assembl.assemble_contigs()
  File "/groups/bipaa/env/HiCExplorer_2.1.4/lib/python2.7/site-packages/hicassembler/HiCAssembler.py", line 201, in assemble_contigs
    hub_solving_method='remove weakest')
  File "/groups/bipaa/env/HiCExplorer_2.1.4/lib/python2.7/site-packages/hicassembler/Scaffolds.py", line 27, in wrapper
    f_result = func(*args, **kwds)
  File "/groups/bipaa/env/HiCExplorer_2.1.4/lib/python2.7/site-packages/hicassembler/Scaffolds.py", line 1803, in join_paths_max_span_tree
    self._remove_weakest(nxG)
  File "/groups/bipaa/env/HiCExplorer_2.1.4/lib/python2.7/site-packages/hicassembler/Scaffolds.py", line 1968, in _remove_weakest
    adj_degree = sorted([(x, node_degree_mst[x]) for x in G.adj[node].keys()], key=lambda(k, v): v)[::-1]
  File "/groups/bipaa/env/HiCExplorer_2.1.4/lib/python2.7/site-packages/networkx/classes/coreviews.py", line 81, in __getitem__
    return AtlasView(self._atlas[name])
KeyError: 19322

He installed HiCAssembler and HiCExplorer with the following commands:

conda create -p /groups/bipaa/env/HiCExplorer_2.1.4 HiCExplorer=2.1.4 biopython=1.73 python=2.7
source activate /groups/bipaa/env/HiCExplorer_2.1.4
pip install hicassembler
@gtrichard gtrichard changed the title _remove_weakest len(path) object of type 'int' has no len() object of type 'int' has no len() in Scaffolds.py _remove_weakest len(path) Jan 30, 2019
@fidelram
Copy link
Contributor

fidelram commented Feb 1, 2019

Looks like a corner condition was reached and the code was not prepared to handle it. Path, in this case is a list of id, that define continuity of a sequence. It should not be an integer. I would need some sample data to debug that.

@gtrichard
Copy link
Collaborator Author

gtrichard commented Feb 1, 2019

Ok, so path = len(self.pg_base[node]) should definitely be path = self.pg_base[node] ?

Corner would mean what? The following?

         ---o---------o
          /            \
       /                \
o-----o-----o-----o-----o-----o-----o

Any idea about the cause of this?

For the sample data you would need the whole h5 matrix + fasta?

Thanks a bunch for the answer.

@xinwang-bio
Copy link

@gtrichard Hi I also face this error. How you can fix it ?

@xuxiaoman0212
Copy link

xuxiaoman0212 commented Feb 16, 2020

I got the same error.

`INFO:Scaffolds:Entering join_paths_max_span_tree
/public1/home/ruifeng/anaconda3/envs/hicexplorer/lib/python3.6/site-packages/scipy/sparse/compressed.py:742: SparseEfficiencyWarning: Changing the sparsity structure of a csr_matrix is expensive. lil_matrix is more efficient.
SparseEfficiencyWarning)
INFO:Scaffolds:320 hubs were found
WARNING:Scaffolds:

Hub-hub contact for bin_id:20481 scaffold: scaffold_177_1 degree: 4
with bin_id: 20358 scaffold: scaffold_115/2_2 degree:4

##############
these cases could introduce problems in the assembly.
Thus, node is being removed from the graph.
##############

Traceback (most recent call last):
File "/public1/home/ruifeng/anaconda3/envs/hicexplorer/bin/assemble", line 312, in
main(args)
File "/public1/home/ruifeng/anaconda3/envs/hicexplorer/bin/assemble", line 306, in main
super_contigs = assembl.assemble_contigs()
File "/public1/home/ruifeng/anaconda3/envs/hicexplorer/lib/python3.6/site-packages/hicassembler/HiCAssembler.py", line 201, in assemble_contigs
hub_solving_method='remove weakest')
File "/public1/home/ruifeng/anaconda3/envs/hicexplorer/lib/python3.6/site-packages/hicassembler/Scaffolds.py", line 27, in wrapper
f_result = func(*args, **kwds)
File "/public1/home/ruifeng/anaconda3/envs/hicexplorer/lib/python3.6/site-packages/hicassembler/Scaffolds.py", line 1814, in join_paths_max_span_tree
self._remove_weakest(nxG)
File "/public1/home/ruifeng/anaconda3/envs/hicexplorer/lib/python3.6/site-packages/hicassembler/Scaffolds.py", line 2013, in _remove_weakest
if len(path) < 5:
TypeError: object of type 'int' has no len()
`

Hi @gtrichard @wangxinbio, how did you solve it?

Hi @fidelram, is there any software update regarding this error?

Thanks!

@gtrichard
Copy link
Collaborator Author

I didn't solve it.

@grpiccoli
Copy link

Has someone solved this issue?

@grpiccoli
Copy link

@gtrichard you did solve it in the end, thank you for the comment, that was the solution, cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants