I have a file with 16S sequences. some headers contain species information. For my purposes I would like to exclude a number of species from the file, therefore I would like to do a pattern matching within a 16S header (that contains other characters beyond the species name) to then remove that header and the following sequence.
So, I have:
>NCBI_ID1;high_rank_taxonomy;...;species_name1
ATCCTT
>NCBI_ID2;high_rank_taxonomy;...;species_name2
ATTTTCCC
>NCBI_ID3;high_rank_taxonomy;...;species_name3
TTTCCCCAAAA
>NCBI_ID4;high_rank_taxonomy;...;species_name4
CCCTTTAAA
I would like to exclude, say, species 1,2 and 4 to retain:
>NCBI_ID3;high_rank_taxonomy;...;species_name3
TTTCCCCAAAA
I found this solution in an adjacent question:
awk 'BEGIN{while((getline<"ids.txt")>0)l[">"$1]=1}/^>/{f=!l[$1]}f' seq.fa
where I have my species names in the file ids.txt and sequences in file seq.fa
but that would work if the whole of my header was just the species name (contents of each line in ids.txt), which is not the case.
I thought I could be smart and use *species_name1*
instead of species_name1
as contents of ids.txt but that apparently doesn't work.
Could someone help me with modifying the current solution to accommodate the existence of additinal strings in the headers?
Many thanks! A