Hot answers tagged

9 votes
Accepted

Splitting fasta file into smaller files based on header pattern

Here's a simple awk approach: awk '{if(/^>/){split($1,a,"[|.]")}print >> a[2]".fa"}' Protein_FASTA.txt Or, more concisely, just: ...
terdon's user avatar
  • 9,826
9 votes
Accepted

Extract nanopore read ID & start times from fastq file

awk '{if(NR%4==1) print $1, $5}' file.fastq | sed -e "s/ start_time=/, /" -e "s/^@//" The awk command gets the first of every ...
Devon Ryan's user avatar
  • 19.6k
9 votes

How I can change the name of multiple files at once in R or terminal?

Use perl-rename. This is usually called rename on Debian-based systems like Ubuntu or Mint, and ...
terdon's user avatar
  • 9,826
8 votes
Accepted

Calculating read average length in a Fastq file with bioawk/awk

This can also be done with regular awk. awk '{if(NR%4==2) {count++; bases += length} } END{print bases/count}' <fastq_file> The ...
Bioathlete's user avatar
  • 2,574
7 votes

Remove/delete sequences by ID from multifasta

Just today I wrote a script to do exactly this using Biopython. I also add a warning If any the headers I wanted to filter was not present in the original fasta. So ...
Kamil S Jaron's user avatar
7 votes

Remove/delete sequences by ID from multifasta

Suppose you keep sequence names in ids.txt and sequences in seq.fa: ...
user172818's user avatar
  • 6,525
7 votes

change/edit FASTA headers

One way using awk: awk 'BEGIN { FS=OFS="|" } /^>/ { print ">" $2, "1", "training"; next }1' file.fa This sets the ...
Steve's user avatar
  • 3,069
7 votes

Extract lines from a file based on a range of coordinates listed on a second file

If you have a VCF file with an intact header, you can use bcftools for this. All you need to do first is to bgzip and index your VCF: ...
Steve's user avatar
  • 3,069
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

Remove/delete sequences by ID from multifasta

If you want to learn how to do things with command-line tools, you can linearize the FASTA with awk, pipe to grep to filter for ...
Alex Reynolds's user avatar
6 votes

Extract nanopore read ID & start times from fastq file

Since the string start_time will only appear on the header line, or else you don't have a valid fastq file, you can simply do: ...
terdon's user avatar
  • 9,826
5 votes
Accepted

How can I edit a specific FASTQ read in place, given the read ID?

You'll first need to determine the appropriate line number, which you can do with grep -m1 -nw "@31027" foo.fastq. After that, note that you can provide a line ...
Devon Ryan's user avatar
  • 19.6k
5 votes

Downloading URL using AWK for fixed fields

awk '{print "wget " $9 " -O " $1 "_" $2 ".fastq.gz"}' tmp will give you ...
Bioathlete's user avatar
  • 2,574
5 votes
Accepted

How I can change the name of multiple files at once in R or terminal?

just to complete your question, you can do it in R in one line. After setting the directory as your working directory, just type the following: ...
dc37's user avatar
  • 1,021
4 votes

Downloading URL using AWK for fixed fields

A variation of Bioathlete’s answer that doesn't suffer from escaping issues: ...
David Foerster's user avatar
4 votes
Accepted

split 1 column input into 5 column bed file

The following Python script seems to do the job. ...
Daniel Standage's user avatar
4 votes
Accepted

Edit all the fasta headers using awk

EDIT after OP's update: Try this Perl one-liner: perl -pe 'BEGIN { $i = 1 } $i += s{>([^_]+)_.*_}{>RNA${i}#${1}/}' input_file > output_file Here, the ...
Timur Shtatland's user avatar
4 votes

Removing particular line along with Fasta header in fasta file

You can use awk here, by setting the input (RS) and output (ORS) record separator, this is ...
terdon's user avatar
  • 9,826
4 votes
Accepted

Extract lines from a file based on a range of coordinates listed on a second file

Using GNU awk for arrays of arrays: ...
Ed Morton's user avatar
  • 176
4 votes
Accepted

Remove low quality reads

Use an off the shelf tool for read preprocessing. Here is one: ./fastq_qual_trimmer -i test.fq -m 35 -H 10 That one does exactly what you want but seems a little ...
Maximilian Press's user avatar
3 votes
Accepted

How to extract all pair end fastq.gz files from multiple subdirectory to a single folder

Go to the common parent folder under which all FASTQ.GZ files reside. They could be in sub-folders under the folder, but all of them should have the folder you're in as a common parent folder. From ...
Ram RS's user avatar
  • 2,279
3 votes

Calculating read average length in a Fastq file with bioawk/awk

This script is wrong because a quality string may start with @. With bioawk, it can be simplified to: ...
user172818's user avatar
  • 6,525
3 votes

Remove/delete sequences by ID from multifasta

Using the FastaToTbl and TblToFasta scripts I have posted before, you can do: ...
terdon's user avatar
  • 9,826
3 votes

Extract nanopore read ID & start times from fastq file

Albacore produces a sequencing_summary.txt file (actually TSV, not CSV) in the same directory as the workspace folder that might ...
gringer's user avatar
  • 13.9k
3 votes

How can I compare two bed files?

From a set operations viewpoint, consider your hg37 regions as a "reference" set and hg38 as a "map" set. If you have these sets in BED format, BEDOPS lets you do set operations on them with various ...
Alex Reynolds's user avatar
3 votes

split 1 column input into 5 column bed file

The Python script in my first response is heavy on regex matching, which is pretty clunky in Python. I like Python much better than Perl overall, but a throwaway script like this will be clearer and ...
Daniel Standage's user avatar
3 votes

split 1 column input into 5 column bed file

Quick Perl solution (following on from Daniel's answer saying that this would be "clearer and more concise in Perl"). I was a bit confused with your BED output because you've treated the start/end ...
gringer's user avatar
  • 13.9k
3 votes
Accepted

awk working with large files

Maybe comm, which is part of GNU coreutils, is more efficient. comm writes to standard output lines that are common, and lines that are unique, to two input files; a file name of ‘-’ means standard ...
Sebastian Müller's user avatar
3 votes
Accepted

Filter out other character after the genotype

Using sed: ...
oliv's user avatar
  • 181
3 votes

Merging two files together

I'd recommend using R and either merge or one of the joins. Assuming your data is not too large, ...
Ram RS's user avatar
  • 2,279

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