This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Extracting unmapped reads from a sam file and converting to fastq

Hi, I am new to bioinformatics so please be kind.

I am trying to retrieve unmapped reads from a sam file named aln.sam on command line (HPC). I have installed samtools and I ran it with this code:

module load bioconda
conda install -c bioconda samtools
cd /path to working directory
samtools view -f 4 -i aln.sam > unmapped_reads.sam

The error message I get is

/tmp/slurmd/job...../slurm_script: samtools: command not found.

I need help correcting this and how do I convert the unmapped reads to a fastq file.

samtools

It means that the directory where conda installed samtools is not available from the nodes that are running your SLURM job. Can you show us your exact SLURM submission command/script? At a minimum you will need to conda activate for this to work.

You should need to install conda only once while creating a new environment. After that you will only need to conda activate env.

Thanks. The slurm script script is :

#!/bin/bash
#SBATCH --job-name
#SBATCH --account
#SBATCH --partition=compute
#SBATCH --cpus-per-task
#SBATCH --time =

module load bioconda
conda install -c bioconda samtools
conda activate nanopore_env

cd /path to working directory

samtools view -f 4 -i aln.sam > unmapped_reads.sam

conda activate nanopore_env

What environment is this and how is it related to original question?

As noted already, see if your cluster already has a module for samtools (or another program that depends on samtools, which is bound to include samtools) and just load that module. Doing the conda install inside slurm script is not good practice. If you want to do that do it outside script and activate the environment before submitting the job (or inside the script).

It just means that it does not find the tool samtools. Create conda environment(cona create), activate it (conda activate), install samtools inside the env (conda install).

Are you sure they haven't installed samtools as a module already?

no it wasnt, if it was wouldnt it recognize the command?

Not by default. You will have to module load samtools for that command to become available.

Thank you everyone, the command has been recognized.

Which solution worked (from above)? I can move that comment to an answer. You can accept the answer (green check mark) to provide closure to this thread.

0 answers

No answers yet.

Log in to answer this question.