30
votes
Accepted
What is a quick way to find the reverse complement in bash
Thanks to Manu Tamminen for this solution:
echo ACCTTGAAA | tr ACGTacgt TGCAtgca | rev
10
votes
Removing duplicate FASTA sequences based on headers with Bash
If you want to avoid using extra libraries for any reason, you can just use a simple Python script (version 3.6 and above) to do this:
...
9
votes
Accepted
How to merge .fastq.qz files into a single .fastq.gz with their same id without losing any content in parallel
All you need is cat. You won't find any better tool for a simple job like this. Just run:
...
9
votes
Accepted
Calculating average coverage for .bam files (sequence data)
For a quick estimate you’re making it more complicated than necessary.
The theoretical average coverage is $\frac{n \cdot \hat l}{N}$ where $n$ is the number of reads, $\hat l$ is the average read ...
9
votes
Removing duplicate FASTA sequences based on headers with Bash
You can use seqkit for this purpose.
seqkit rmdup -n seqs.fa -o seqs_without_duplicate.fa
8
votes
Edit FASTA header using sed
awk 'BEGIN{FS="::"}{if($1~">"){printf(">%s_%s\n",$2,substr($1,2))}else{print $0}}' input_file.fa > output.fa
An explanation of the non-obvious bits:
<...
8
votes
Accepted
How to get rows with similar values in two different columns using command line?
I think it is easy to do with awk, e.g. see here.
For your example, with your data in file:
...
7
votes
What is a quick way to find the reverse complement in bash
Reverse complement FASTA/Q:
seqtk seq -r in.fa > out.fa
https://github.com/lh3/seqtk
7
votes
How can I add a ";" at the end of each fasta header line in a file?
One way, using sed and a regex address to select only the header lines and apply a substitution to append a semicolon to the end of each line:
...
6
votes
Accepted
How to extract values from second file on the basis common first column?
I like to use the join command for this. For your example above, you can simply use the following:
...
6
votes
Accepted
how to remove range from fasta header
Invest some time in learning unix tools such as grep, sed and awk.
...
6
votes
Accepted
How to align output of grep --color=always? (To QC fasta/fastq files)
Perhaps, grep is not the best tool to use in this case, but it should be in principle possible by using grep & ...
6
votes
How can I add a ";" at the end of each fasta header line in a file?
... using the legendary Perl pie
perl -p -i -e 's/^(>.*)/$1;/' mybacteria.fa
Input
...

M__♦
- 11.9k
6
votes
Accepted
A bash script for running on a bunch of bam files
There are a couple ways to approach this, one is to create output files based on the BAM input file name - the other approach is to make a new folder (based on the ...
5
votes
Accepted
Sort vcf by contig and position within contig
You could simply use bcftools sort for it:
$ bcftools sort input.vcf > output.vcf
If you really want to use bash only, you can do this:
...
5
votes
BAM to gene expression matrix (UMI counts per gene per cell),10X
How to re-analyze 10X BAM files?
This is a great question and honestly, I don't think there was an easy way to do this at the time the question was asked. The reason is that if you want to re-do the ...
5
votes
Bash scripting FastQC for multiple fastq files in multiple directories
multiqc kind of glazes over some important information, like the exact adapters and duplicated sequences in a library. If you plan to spend big $$ for sequencing a ...
5
votes
Accepted
5
votes
Accepted
Changing this code in a way to work for my files
Using shell loops for text practice is considered bad practice. It is exceedingly slow, the syntax is complicated so it's very easy to get it wrong and it's just painful. The shell isn't designed as a ...
5
votes
Accepted
Using variables with fasterq-dump?
You have an obvious error in your shell script that should have given you an error message:
sra_code = "DRR163""$i"
Should be:
...
5
votes
Accepted
How to measure the total size of a fastq file in base pairs?
I've been using this:
cat file.fastq | paste - - - - | cut -f 2 | tr -d '\n' | wc -c
Explanation :
paste - - - - : print four ...
5
votes
Accepted
Trying to create a .bam file without the need for a .sam file
This is an error from bwa saying that it can't find your input files:
Here's a checklist:
Check that you have no whitespace after your ...
5
votes
Parallelize or qsub a bash script
What's best is quite subjective. My preference would be use Nextflow to abstract away the underlying job submission system and then use the sge executor to submit the jobs to the cluster. The only ...
5
votes
Easier / lazy way to convert an existing bash pipeline to nextflow pipeline?
If your objective is to convert Bash scripts into Nextflow code, you might find Viash (https://viash.io) a particularly useful open source tool. It automatically generates independent Nextflow modules ...
4
votes
Accepted
Replace lowercase characters with -
The following sed command will do the trick.
sed -e '/^[^>]/ s/[a-z]/\-/g' in.fna > out.fna
Lines starting with ...
4
votes
BAM to gene expression matrix (UMI counts per gene per cell),10X
You should be able to parse out what you need using the tags in the .bam. 10xGenomics' website says what tags they add.
https://support.10xgenomics.com/single-cell-gene-expression/software/pipelines/...
4
votes
Accepted
How to combine multiple files into one file?
The bug in your loop appears be "> filename" per column, this over-rides the last iteration resulting in a file with a single column, which has been over-written ...

M__♦
- 11.9k
4
votes
Accepted
Pattern mining from a genomic sequence
echo ">ATGCTTATTGCCCATTTCGTGCATGCATATGCGCATTCGCGATCGATTAGGGATAT" | grep -oP 'TTCG[CGT][ATGC]{1,15}TTCG[CGT]'
[CGT] looks ...
4
votes
How I can run this code on my files?
$f in your command is not pointing anywhere since your for loop was defined as for file in *.vcf;. You should use ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
bash × 112python × 15
linux × 14
r × 12
fasta × 12
awk × 9
shell × 8
samtools × 7
fastq × 7
sequence-alignment × 6
phylogenetics × 6
rna-seq × 5
loop × 5
vcf × 4
perl × 4
command-line × 4
proteins × 3
genome × 3
phylogeny × 3
database × 3
protein-structure × 3
sequence-analysis × 3
blast × 3
bed × 3
filtering × 3