Thanks but motif position never remained same. Is there any solution in PERL?
Hello, I am looking for printing a specific length of amino acids before and after a motif. For example, See below sequence where the bold is motif. I need to print 83 residues before it and 254 residues after it.
HTRVTGGSAAHATNTFTSFFSQGAKQGVQLVNTNGSWHVNRTALNCNASLETGWVAGLFYYHKFNSSGCP ERMASCRPLADFDQGWGPISYANGSGPEHRPYCWHYPPKPCGIVPAQTVCGPVYCFTPSPVVVGTTDKFG VPTYNWGENETDVPVLNNTRPPLGNWFGCTWMNSSGYTKVCGAPPCVIGGVGNNTLHCPTDCFRKHPEAT YSRCGSGPWITPRCLVDYPYRLWHYPCTINYTLFKVRMYVGGVEHRLEAACNWTRGERCDPDDRDRSELS PLLLSTTQWQVLPCSFTTLPALTTGLIHLHQNIVDVQYLYGMGSSIVSWAIKWEYVILLFLLLADARICS CLWMMLLI
Thanks.
Reaz
2 answers
if you have a motif positions, create bed file with positions, motif_start-83 and motif_stop+254. Den use fastaFromBed
You can use this code:
while (<DATA>){
if ($_=~/(.{5})(QGWGP)(.{5})/i){
print "Before:$1\nAfter: $3\n";
}
}
__DATA__
SSGCPERMASCRPLADFDAAAAAQGWGPBBBBBISYANGSGPEHRPY
You can set motif as well as {number of characters you want before and after} in this code.
He needs the number of characters before and after the motif I understand correctly.
Hello Nari, I tried and it is working fine. I am just wondering now how can I implement it on a multifasta file? I appreciate for your help.
Just add to Nari's code to handle multifasta
open NN, fasta_file; $/=">"; foreach(<NN>) {chomp; next unless (my ($q_header, $q_sequence)= /(.*?)\n(.*)/s);## $q_sequence=~s/[\d\s>]//g;## if ($q_sequence=~/(.{5})(QGWGP)(.{5})/i){print "$q_header\tBefore:$1\tAfter: $3\n";}}close NN;
Log in to answer this question.
Do you have a file containing the motifs or something like that?
Yes I do have a file. How can I share?
I see you want to use perl, in which case I can't help you. But as a follow up question to get your problem a bit clearer, it's always the same motif, and the sequences are in fasta format?
In Python (which I can help with) you could do things like (pseudocode)
seqstring.index('QGWGP')to get the position of your motif in the sequence fragment, which then (knowing the total length) would be pretty straightforward to calculate the length before and after.But very very likely perl will have an alternative (or multiple alternatives) to do the same thing.
Thanks I am working on other suggestions.