Hot answers tagged

22 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
user avatar
  • 2,086
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: ...
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: ...
user avatar
  • 8,151
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
user avatar
  • 609
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: <...
user avatar
  • 19.2k
8 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 ...
user avatar
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: ...
user avatar
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: ...
user avatar
  • 527
6 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
user avatar
6 votes
Accepted

how to remove range from fasta header

Invest some time in learning unix tools such as grep, sed and awk. ...
user avatar
  • 1,367
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 & ...
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 ...
user avatar
  • 7,721
6 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: ...
user avatar
  • 777
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: ...
user avatar
  • 1,332
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 ...
user avatar
  • 3,091
5 votes
Accepted

How can I run a command for multiple files?

Assuming all your vcfs are in the same folder: ...
user avatar
  • 796
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 ...
user avatar
  • 8,151
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: ...
user avatar
  • 8,151
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 ...
user avatar
  • 2,646
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 ...
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 ...
user avatar
  • 584
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/...
user avatar
  • 1,672
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 ...
user avatar
  • 7,721
4 votes
Accepted

Pattern mining from a genomic sequence

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

Moving file based on their names

First of all you are getting an error because you are missing a then in the third line of your code and then a fi to close the <...
user avatar
  • 3,477
4 votes

Removing duplicate FASTA sequences based on headers with Bash

One way using awk: awk '/^>/ { f = !a[$0]++ } f' seqs.fa Explanation: The above is basically the same as: ...
user avatar
  • 777
4 votes

Calling for one specific SNP from multiple sequencing runs

Getting SNPs from whole-genome data is usually done via mapping sequencing reads on the reference (bwa-mem or bowtie are two popular mappers) and then using one of variant calling tools (like ...
user avatar
  • 5,327
3 votes

How to merge .fastq.qz files into a single .fastq.gz with their same id without losing any content in parallel

We sequence DNA on daily basis. Like terdon said, you can use cat to group all the FastQ of all your sample whether they are ...
user avatar

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