Solved

longest sequence...

Posted on 2009-04-10
6
180 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
HTTP Error 502.2 - Bad Gateway 3 217
Migrate OTRS to newest version. 1 334
Writing a parser for java language 4 79
Perl regex to replace any capital letters not preceded by ">" 6 121
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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