Thanks for the help @JC
• 0 views
•
link
Hello Biostar
I have a multifasta file that contains protein sequences (of different sizes), I want to extract only those sequences that contain at least 5% of cysteines (C).
Can you give me a little script so that I can extract these sequences
Thank you in advance
Definitively you need some programming skills to do it by yourself. Here is some Perl code to do this:
#!/usr/bin/perl
use strict;
use warnings;
my $minC = 5; # Filter sequence below this percentage
$/ = "\n>"; # Read Fasta sequences in blocks
while (<>) {
s/>//g;
my ($seq_id, @seq) = split (/\n/, $_); # Separate sequence id from the sequence lines
my $seq = uc (join ("", @seq)); # Linearize the sequence in a single string, also using upper-case letters
my $len = length $seq; # Get sequence size
my $numC = $seq =~ tr/C/C/; # Quick way to count chars in a string
my $perC = 100 * $numC / $len; # Calc percentage of Cs
if ($perC >= $minC) { # Filter
print ">$_";
}
}
Usage: perl filterByC.pl < Fasta_In > Fasta_out
Thanks for the help @JC
With awk:
$ awk -v FS="\n" -v RS=">" '$0 { seq=$0; $1=""; c=gsub("C", "_", $0); l=gsub(/[A-Z_]/, ".", $0); if(c/l>0.05) printf ">"seq}' input.fa
> as the record separator and \n as a the field separator.seq.C there.C to _ to get the number of C._.Thanks for the help @finswimmer this is very useful
Thanks for the help
Log in to answer this question.
Sorry, we cannot "give you a little script". Please tell us what you've tried so far and where you're facing difficulties, and we can help you with specifics.
I can quantify the number of C (cystein) by grep but in each sequence (ID). I have several protein sequences in a single multifasta file, I am looking for an idea to quantify the number of C in each sequence at a time, for extract the sequences which contains 5% cysteine.
See this updated post:
https://web.archive.org/web/20071027112709/http://python.genedrift.org/2007/10/10/alternative-methods-to-split-a-fasta-file/
Let's use Python:
make your sequences looks like 2 strings each:
This is just an idea.