how to use list of gene id to get cds sequence(cds fasta file have many annotation, only gene id: is same to query id) i have a question when i want to extract cds sequence using gene id. but cds file is not just start with >gene is, it has many other annotation. the only same  is star with gene:

cds fasta:

&gt;Zm002 cds gene:Zm1d035916 gene_biotype:protein_coding 
ATCGGCAT
&gt;Zm001 cds RefGen_v4:9:153880862:153883850:-1 gene:Zm1d048 gene_biotype:protein_coding
ATGCGGCA


gene_list

Zm1d035916
Zm1d048 


how to get result like

&gt;Zm1d035916
ATCGGCAT
&gt;Zm1d048 
ATGCGGCA
If you can use awk, you could use this simple script:

awk '
BEGIN {p=0}
NR==FNR {gid[$1];next}
/^&gt;/{
  p=0;
  for(g in gid){
    re="\\sgene:"g"\\s"
    if($0~re){p=1;break}
  }
}p' gene_list cds.fasta


You can also put the code inside a script file:

extract_genes.awk

#!/usr/bin/awk
BEGIN {
  p = 0; # p indicates whether to print a line or not
}
# while scanning the first file, store gene ids in an array
NR==FNR {
  gid[$1];
  next
}
# check FASTA headers
/^&gt;/ {
  p = 0;
  for(g in gid) {
    # construct regular expression to match gene id in FASTA header
    re = "\\sgene:"g"\\s";
    if ($0~re) { # a match was found!
      p = 1;
      break;
    }
  }
}
p # print line or not?


And call it like this:

awk -f extract_genes.awk gene_list cds.fasta