Use Query List To Extra Sequeces
Question:
A database containing sequences as follows:
>leaf_1
AAGACCATTCGAGCTTATCTCTTC
>leaf_2
ATGGAGAAGGAAATGAAGAGCAGT
>leaf_3
TGGCTGTAAGTCATACCTGTCA
>leaf_4
CGCGGAGTAGATCAGTTTGGTA
>leaf_5
AGTAACGGCTTTACAAGAATCAAA
......
Now I have a query file (inquiry.txt), which looks like:
>leaf_2
>leaf_4
>leaf_5
Need an output file (result.txt) looks like:
>leaf_2
ATGGAGAAGGAAATGAAGAGCAGT
>leaf_4
CGCGGAGTAGATCAGTTTGGTA
>leaf_5
AGTAACGGCTTTACAAGAATCAAA
Could anyone help with this question? Many thanks.
• 2,377 views
•
link
2 answers
Try?
$ perl below-script.pl all-sequences.txt inquiry.txt
#!/usr/bin/perl
open (INPUT, $ARGV[0]) or die $1;
open (QUERY, $ARGV[1]) or die $1;
open (OUTPUT, ">result.txt");
chomp (my @array=<QUERY>);
while (<INPUT>) {
foreach my $temp (@array){
if ($_ =~ $temp) {
$nextline = <INPUT>;
print OUTPUT "$_$nextline";
}
}
}
close (OUTPUT);
close (QUERY);
close (INPUT);
• 0 views
•
link
You may also try the following Perl script... and this works for fasta format input files!
use strict;
use warnings;
my @genes;
open my $list, '<file2.list';
while (my $line = <$list>) {
push (@genes, $1) if $line =~ /[^>]+>([^|]+)/;
}
my $input;
close $list;
{
local $/ = undef;
open my $fasta, '<file1.fasta';
$input = <$fasta>;
close $fasta;
}
my @lines = split(/>/,$input);
foreach my $l (@lines) {
foreach my $reg (@genes) {
print ">$l" if $l =~ /$reg\|/;
}
}
File 2 will your query file and File1, the fasta sequence file in this case!
• 1 views
•
link
Log in to answer this question.
This is a pretty common question: Extracting Sequence From A 3Gb Fasta File?