1

I can extract list of patterns using following command,

fgrep -A 1 -f patternlist.txt filename.fasta

but, is there a way I can extract without creating another file (patternlist.txt in this case) from other command's output?

Such as:

cut -d "      "  Cell_cycle.txt -f 1 | grep ...???... filename.fasta

EDIT:

The Cell_cycle.txt looks like this:

$ cat Cell_cycle_Kegg_pathway
ctg2977_3.g207.t1   K06626
P05_Ctg654_12.g311.t2   K03094
P06_Ctg710_7.g346.t1    K05868

i want to take the first column and extract those sequences from fasta file.

EDIT 2:

I have list of sequences in a UniqueSeq_28Dec2014.fasta

>ctg1474_1.g69.t1 (first line)
atgaaatgttggtgcagcgccctggcacttctcc...... (second line)
>ctg1475_1.g70.t1 (third line)
atgaaattgcagcgccctggcacttctcctgcag...... (fourth line)

I want to print the first two sequences (from lines 1 to 4). However, I do not want to use head -4 UniqueSeq_28Dec2014.fasta which can also give my output, but I want it using process substitution.

I tried the following command but does not seem to work. I just see 4 empty lines.

grep -A 1 -Ff <(grep '>' UniqueSeq_28Dec2014.fasta |head -4) UniqueSeq_28Dec2014.fasta
  • 1
    Yes you can. Do you mind letting us know what the pattern is? – Sree Dec 8 '14 at 5:25
1

Use process substitution <():

fgrep -A 1 -f <(cut -d " " -f 1 Cell_cycle.txt)  filename.fasta
  • Hi was trying to implement your answer in other instance. The following does not give me output: grep -A 1 -Ff <(grep '>' UniqueSeq_28Dec2014.fasta |head -4) UniqueSeq_28Dec2014.fasta I just wanted to extract only top 4 sequences this way. – Prakki Rama Dec 10 '14 at 8:25
  • What is the content of UniqueSeq_28Dec2014.fasta? – jimmij Dec 10 '14 at 8:32
  • It is sequence file in fasta format. First line contains a header with ">" in the beginning and second line contains a sequence of letters (and file contains many headers and sequences). – Prakki Rama Dec 10 '14 at 8:36
  • @PrakkiRama please edit your question and give a short sample of the file which don't work. I cannot reproduce the problem from your description. – jimmij Dec 10 '14 at 11:00
  • 1
    @PrakkiRama your command works fine for me - it just reproduce the file, whole four lines. You don't even need head -4, just grep -A 1 -Ff <(grep '>' UniqueSeq_28Dec2014.fasta) UniqueSeq_28Dec2014.fasta is enough in this example. If it doesn't work test in steps, so first what grep '>' UniqueSeq_28Dec2014.fasta returns. It should be two lines: first and third. It is also wise idea to pass --colour=auto in order to see what exactly matches, in this case > at the beginning of the line should be highlighted. – jimmij Dec 11 '14 at 3:02
1

Also this(for slightly shorter and more readability):

grep -Ff <(awk '{print $1}' Cell_cycle.txt) filename.fasta

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.