DessimozLab / read2tree

a tool for inferring species tree from sequencing reads
MIT License
142 stars 18 forks source link

ValueError: fetch called on bamfile without index #27

Closed CJJ8848 closed 1 year ago

CJJ8848 commented 1 year ago

Hi,

If you can help, I would appreciate it.

Install from source:

build from source

conda create -n r2ttry -c conda-forge biopython numpy Cython ete3 lxml tqdm scipy pyparsing requests natsort pyyaml filelock python=3.10.8

conda activate r2ttry

conda install -c bioconda dendropy pysam

error

Found conflicts! Looking for incompatible packages.
This can take several minutes. Press CTRL-C to abort.
failed

UnsatisfiableError: The following specifications were found
to be incompatible with the existing python installation in your environment:

Specifications:

Your python: python=3.10.8

If python is on the left-most side of the chain, that's the version you've asked for. When python appears to the right, that indicates that the thing on the left is somehow not available for the python version you are constrained to. Note that conda will not change your python version to a different minor version unless you explicitly specify that.

The following specifications were found to be incompatible with each other:

Output in format: Requested package -> Available versions

Package setuptools conflicts for: dendropy -> setuptools python=3.10.8 -> pip -> setuptools

Package _libgcc_mutex conflicts for: python=3.10.8 -> libgcc-ng[version='>=11.2.0'] -> _libgcc_mutex[version='|0.1',build='main|conda_forge|main'] pysam -> libgcc-ng[version='>=12'] -> _libgcc_mutex[version='|0.1',build='main|conda_forge|main']The following specifications were found to be incompatible with your system:

Your installed version is: 2.17

fix with pip install dendropy and pip install pysam

pip install dendropy

Successfully installed dendropy-4.6.0

pip install pysam

Successfully installed pysam-0.21.0

error when conda install -c bioconda mafft iqtree ngmlr nextgenmap samtools

install one by one

all succuess except found conficts with samtools

conda install -c "bioconda/label/cf201901" samtools

git clone https://github.com/DessimozLab/read2tree.git cd read2tree python setup.py install

finish install

start read2tree

generate the reference done with 'read2tree --standalone_path ${markers} --output_path ${output} --reference '

!!! Then here is the error log when I run the command 'read2tree --standalone_path ${markers} --output_path ${output} --reads ${pathtofq}/${historicalsample}' with python 3.10.8

(r2ttry) [jiajucui@vic r2tAt]$ bash 17samples_7ref_At.sh 17 HB0863_At.fastq.gz --- Re-load ogs and find their corresponding DNA seq from output folder --- Re-loading files: 200 OGs [00:00, 483.34 OGs/s] --- Generating reference for mapping from folder --- Re-loading references for mapping from folder: 100%|███████████| 7/7 [00:00<00:00, 254.98 species/s] Loading alignments : 200 Alignment [00:00, 570.35 Alignment/s] --- Mapping of reads to reference sequences --- Mapping reads to species: 0%| | 0/7 [00:00<?, ? species/s]2023-05-13 00:15:37,324 - read2tree.Mapper - INFO - HB0863_At: --- Mapping of reads to ARAAL reference species ---

[E::idx_find_and_load] Could not retrieve index file for '/tmp/ngm_fyxw08ui/ARAAL_OGs.fa.bam' 2023-05-13 00:20:11,847 - read2tree.Mapper - INFO - HB0863_At: Mapped 60956 / 6359239 reads to ARAAL_OGs.fa 2023-05-13 00:20:11,914 - read2tree.Mapper - INFO - HB0863_At: Mapping to ARAAL_OGs.fa references took 274.5886769294739. [E::idx_find_and_load] Could not retrieve index file for '/tmp/ngm_fyxw08ui/ARAAL_OGs_post_sorted.bam' Mapping reads to species: 0%| | 0/7 [04:35<?, ? species/s] Traceback (most recent call last): File "/home/jiajucui/miniconda3/envs/r2ttry/bin/read2tree", line 4, in import('pkg_resources').run_script('read2tree==0.1.5', 'read2tree') File "/home/jiajucui/miniconda3/envs/r2ttry/lib/python3.10/site-packages/pkg_resources/init.py", line 720, in run_script self.require(requires)[0].run_script(script_name, ns) File "/home/jiajucui/miniconda3/envs/r2ttry/lib/python3.10/site-packages/pkg_resources/init.py", line 1570, in run_script exec(script_code, namespace, namespace) File "/home/jiajucui/miniconda3/envs/r2ttry/lib/python3.10/site-packages/read2tree-0.1.5-py3.10.egg/EGG-INFO/scripts/read2tree", line 16, in File "/home/jiajucui/miniconda3/envs/r2ttry/lib/python3.10/site-packages/read2tree-0.1.5-py3.10.egg/read2tree/main.py", line 357, in main File "/home/jiajucui/miniconda3/envs/r2ttry/lib/python3.10/site-packages/read2tree-0.1.5-py3.10.egg/read2tree/Mapper.py", line 80, in init File "/home/jiajucui/miniconda3/envs/r2ttry/lib/python3.10/site-packages/read2tree-0.1.5-py3.10.egg/read2tree/Mapper.py", line 289, in _map_reads_to_references File "/home/jiajucui/miniconda3/envs/r2ttry/lib/python3.10/site-packages/read2tree-0.1.5-py3.10.egg/read2tree/Mapper.py", line 138, in _call_wrapper File "/home/jiajucui/miniconda3/envs/r2ttry/lib/python3.10/site-packages/read2tree-0.1.5-py3.10.egg/read2tree/Mapper.py", line 570, in _post_process_read_mapping File "/home/jiajucui/miniconda3/envs/r2ttry/lib/python3.10/site-packages/read2tree-0.1.5-py3.10.egg/read2tree/Mapper.py", line 499, in _build_consensus_seq_v2 File "pysam/libcalignmentfile.pyx", line 1098, in pysam.libcalignmentfile.AlignmentFile.fetch ValueError: fetch called on bamfile without index

Please could you check the error? Thanks in advance.

CJJ8848 commented 1 year ago

I fixed it. I checked the mplog.log file and found that the error occured due to incomplete samtools index '2023-05-13 00:20:12,949 - read2tree.Mapper - DEBUG - Shell command failed to execute 2023-05-13 00:20:12,950 - read2tree.Mapper - DEBUG - samtools index -@ 1 /tmp/ngm_fyxw08ui/ARAAL_OGs_post_sorted.bam'.

I run the samtools index -@ 1 sth.bam in the shell directly. It failed since the samtools version installed with bioconda in my python3.10.8 env is 1.3.1, which has no argument '-@' (ref: http://www.htslib.org/doc/1.3.1/samtools.html check the index part). Usually the conda -bioconda will install samtools 1.7.1 which is ok with -@, but I dont know why it install 1.3.1 in my env with pythhon3.10.8. I checked the source code of Mapper.sh in the read2tree folder (/read2tree/read2tree/Mapper.sh), and change the line 164 and 560 'samtools index -@ ' + str(self.args.threads) ... to 'samtools index'... Then after python setup.py install the r2t folder again, the command line generatin reads of my species worked.

I will keep the comments so that others could check. Thanks for the amazing tool! It's efficient on providing an initial glance of the phylogeny. Love it.