This is impractical. A better solution would be to use a regex like >CONTIG_NAME[^>]+ but only if the engine supports multi-line matching (i.e., not the Unix grep tool).
Hi
I have a list of contigs and want to extract one contig (by its title). What is the exact command for that?
Thanks!
4 answers
This has already been addressed as Giovanni pointed out:
Please try at least a cursory search of the site before posting a new question!
Default grep can't find multiline patterns.
You can use pcregrep.
If you want to extract multiple contigs at different times, it is highly suggested that you build an index. Here some commands:
samtools faidx in.fasta #(create an index for the fasta file with all the contigs)
samtools faidx in.fasta contigname > contigname.fasta #(extract the single contig you need)
#to extract seqnames from MS blast result(seqtool) files:
grep contigname filename > out.txt
If you need more lines from contig add -A number after grep like: (for 3 lines)
grep -A 3 contigname filename > out.txt
I've used agrep for this (as in: agrep -d '^>' pattern contigs.fasta) but unfortunately it is unreliable, and has some ugly limitations. I also implemented my own tool (sgrep, part of the biohaskell stuff)
Log in to answer this question.
if your contig file is in fasta format, there are a lot of discussion already open. Have a search in the archives.