Solved

longest sequence...

Posted on 2009-04-10
6
177 Views
Last Modified: 2012-05-06
I got the below code from expert-exchange for getting the longest sequence.... starts with atg and ends with any of 3 codens..

when i give one sequence as input it gives perfect answer ....

but when i give two sequence as inputs it's giving answer for only one sequence....

so what modifications should i do...


sample sequences:


>G7H5
AATATGATTTTGAATTTGGTTCAAAATGAAACCGTCTCCGTTCATTGTTTTGATATTTGCTGTTATTATAGGCCTGTGTGGTTGTGCACCACCCAAGGCCGAAGAAACTCAATCTGCTACGAGTACGAAAGCCGAGTCTTCTAATGCGGGTCAGAGCGGAAATCGATATCCACCGGTGAAGATGAATTTTGAAAAAGTGTTTACTCCTAGTTTTTGTAAAGGTTTGCAAGATCAGCAATCAAAAATTGAAGAACTTTCGGCAGACTTGGAGAGGTTTGAGGGTCAGGAATTGAAGTCAAATTATGGAACATATTCCGACAAAAAGGACCATAAATAAAAATTTGTCCAGCAAAAGATATGGTTGCATAATAAACGCAAATATAATCATACACGCCCAAAAAAAAAAAAAAAAAAAAAAAA

>G8C4
GGGAGTATAATCTTGAATTTGGTTCAAAATGAAACTGTCTCTGTTCATTATTTTTTTGATATTTGCTGTTATTATAGGCCTGTGTGGTTGTGCACCACCCAAGGCCGAAGGAACTAAATCTGGTATGGGAACGCAAGCCGAGTCTTCTAATGCGGGTCAGAGAGGAAGTCGAAACAATGGCATCTCATCGGCGGAGTTGAACTTTGACAGAATTTCTCCTGGTTTTATTAAAGGTTTGCGTGAAGATCAATCAGGATATGAAAAAGTTGGAGAGATCTTGAAGAGGGCTCAGGATCAGCAATTGAAGTCAAATTATGGAAAATATTCCGACAAAAAGGCCCATAATTAAAAATTTGTTCAGCAAAAAATTTGGTTGCATAATAAACCCAAAAATAATCATCCCCGCAAAAAAAAAAAAAAAAAAAAAAAAAA
#!/usr/bin/perl

use warnings;

use strict;
 

open INPUT,"<input.txt" or die $!;

my $name=<INPUT>;

local $/;

$_ = <INPUT>;

close INPUT;

s/\s+//g;

my $longest_str ='';

my $longest_len = 0;

open P,">possible.txt" or die $!;

while( /ATG(?=((?:...)*?(?:TAA|TAG|TGA)))/g ){

   print P "ATG$1\n";

    if( length $1 >$longest_len ){

        $longest_str=$1;

        $longest_len=length $1;

    }

}

close P;

open OUTPUT,">output.fasta" or die $!;

print OUTPUT $name,"ATG",$longest_str if $longest_len;

close OUTPUT

Open in new window

0
Comment
Question by:shragi
  • 3
  • 2
6 Comments
 
LVL 25

Accepted Solution

by:
lwadwell earned 500 total points
ID: 24120119
Hi shragi,

you will need to change the code to loop through the input file and process each "set" of sequences.  I have had an attempt at it below ... I think it does what you want.

lwadwell
#!/usr/bin/perl
use warnings;
use strict;
 
open INPUT,"<input.txt" or die $!;
open OUTPUT,">output.fasta" or die $!; 
my $name; 
while ( my $string = <INPUT> ) {
	chomp($string);            # remove trailing new lines
	$string =~ s/\s+//g;       # remove whitespace
	next if ( $string eq "" ); # start loop again if blank line
	if ( $string =~ /^>/ ) {   # if line starts with a '>', save as $name
		$name = $string;
		next;
	}
	my $longest_str ='';
	my $longest_len = 0;
	open P,">possible.txt" or die $!;
	while( $string =~ /ATG(?=((?:...)*?(?:TAA|TAG|TGA)))/g ){
   		print P "ATG$1\n";
    	if ( length $1 >$longest_len ){
        	$longest_str=$1;
        	$longest_len=length $1;
    	}
	}
	close P;
	print OUTPUT $name,"ATG",$longest_str,"\n" if $longest_len;
}
close INPUT;
close OUTPUT

Open in new window

0
 

Author Comment

by:shragi
ID: 24128135
one small change required..

there is no space between name and sequence...
0
 

Author Comment

by:shragi
ID: 24128136
I need a space between them...
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Expert Comment

by:vikaskhoria
ID: 24128310
Just change line 27 in the script above as:
(added space before and after ATG in quotes)
print OUTPUT $name," ATG ",$longest_str,"\n" if $longest_len;

0
 
LVL 25

Expert Comment

by:lwadwell
ID: 24128492
If you don't want one after the ATG then use
print OUTPUT $name," ATG",$longest_str,"\n" if $longest_len;

Open in new window

0
 

Author Closing Comment

by:shragi
ID: 31568994
Perfect..
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now