Solved

longest sequence...

Posted on 2009-04-10
6
181 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

856 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