Hot answers tagged

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
winni2k's user avatar
  • 2,236
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: ...
Bioinfomrat's user avatar
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: ...
terdon's user avatar
  • 9,662
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 ...
Konrad Rudolph's user avatar
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
Mr_Z's user avatar
  • 629
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: <...
Devon Ryan's user avatar
  • 19.6k
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: ...
Maximilian Press's user avatar
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
user9619's user avatar
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: ...
Steve's user avatar
  • 3,059
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: ...
Scot's user avatar
  • 782
6 votes
Accepted

how to remove range from fasta header

Invest some time in learning unix tools such as grep, sed and awk. ...
Ram RS's user avatar
  • 2,086
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 & ...
Iakov Davydov's user avatar
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__'s user avatar
  • 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 ...
Scot's user avatar
  • 782
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: ...
finswimmer's user avatar
  • 1,342
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 ...
Brunox13's user avatar
  • 151
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 ...
conchoecia's user avatar
  • 3,141
5 votes
Accepted

How can I run a command for multiple files?

Assuming all your vcfs are in the same folder: ...
h3ab74's user avatar
  • 836
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 ...
terdon's user avatar
  • 9,662
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: ...
terdon's user avatar
  • 9,662
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 ...
aechchiki's user avatar
  • 2,676
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 ...
Bastian Schiffthaler's user avatar
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 ...
Steve's user avatar
  • 3,059
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 ...
Andy Boschmans's user avatar
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 ...
arup's user avatar
  • 604
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/...
swbarnes2's user avatar
  • 1,882
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__'s user avatar
  • 11.9k
4 votes
Accepted

Pattern mining from a genomic sequence

echo ">ATGCTTATTGCCCATTTCGTGCATGCATATGCGCATTCGCGATCGATTAGGGATAT" | grep -oP 'TTCG[CGT][ATGC]{1,15}TTCG[CGT]' [CGT] looks ...
haci's user avatar
  • 3,947
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 ...
haci's user avatar
  • 3,947

Only top scored, non community-wiki answers of a minimum length are eligible