Hi All,
I have a sequence of character like "ACDFGEYRTWJSHDGKSKSDHFCNDHD" and I am trying to format in a way such that the output looks like this
A C D F G E Y R T W
J S H D G K S K S D
H F C N D H D
ie, one space between each character and 10 character in one line.
I am getting the sequence in tab separated list but not able to format 10 character per line with one spacing.
Any help will be appreciated.
Thanks
Kumar
4 1983
What have you tried so far?
All you need to do is to split the string into characters and use the indices of resulting array for character count to format it accordingly...
Thanks for the reply,
here is my code -
#!/usr/bin/perl
-
use strict;
-
use warnings;
-
my %one2three = ( 'G'=>'GLY','A'=>'ALA','V'=>'VAL','L'=>'LEU','I'=>'ILE',
-
'S'=>'SER','T'=>'THR','C'=>'CYS','M'=>'MET','P'=>'PRO',
-
'D'=>'ASP','N'=>'ASN','E'=>'GLU','Q'=>'GLN','K'=>'LYS',
-
'R'=>'ARG','H'=>'HIS','F'=>'PHE','Y'=>'TYR','W'=>'TRP',
-
'B'=>'ASX','Z'=>'GLX','X'=>'UNK');
-
my $count = 0;my @val;my ($line,$seq);
-
-
open (FH, "GHHDP") or die "Check for the file";
-
my @prot = <FH>;
-
close FH;
-
-
foreach $line (@prot)
-
{
-
if($line =~/^\s*#/)
-
{next;}
-
elsif($line =~/^>(.*)/)
-
{ my $title = $1;
-
print "* $title\n*\n";
-
}
-
else{$seq .= $line;}
-
}
-
$seq=~ s/\s//g;
-
my @ss = split(//,$seq);
-
foreach my $rr(@ss)
-
{
-
$rrr = $one2three{$rr};
-
print "$rrr\t";
-
$count +=1;
-
}
-
print "$count\n";
-
thanks
Kumar
You are printing out three-letter representations of the amino acids and not single characters as in your initial posting. However, logic remains the same. You are formatting your output with tab(\t). Replace that with a single space. -
foreach my $rr(@ss)
-
{
-
my $rrr= $one2three{$rr};
-
print "$rrr "; ##replace \t with single space
-
$count +=1;
-
print "\n" if($count%10==0); ## insert newline after every 10 records
-
}
-
- Nithin
Thanks Nithin for the reply,
I was getting confused by using the sprintf function but now its working fine. :)
Thanks
Kumar
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Mark |
last post by:
How do I output formatted numerical data to an external (text) file. At
a minimum I want to specify the number of decimal places to print.
Ideally I'd like the type of control the fortran FORMAT...
|
by: Matthew Thorley |
last post by:
Greetings, perhaps someone can explain this. I get to different styles
of formatting for xmla and xmlb when I do the following:
from elementtree import ElementTree as et
xmla =...
|
by: Joe C |
last post by:
I've written a console application and would like to isolate all screen
output so that it will be easier to migrate the code to a GUI-type platform
without modification to the base code. As a...
|
by: Jason Heyes |
last post by:
I am starting to worry about the performance of formatted read/write
operations on data-redundant objects in my program.What can I do to improve
this performance should it become an issue?
...
|
by: Steven T. Hatton |
last post by:
I'm still not completely sure what's going on with C++ I/O regarding the
extractors and inserters. The following document seems a bit inconsistent:...
|
by: Magix |
last post by:
Hi,
I want to use fprintf to write to a file. My question about the formatted
output
How can I format so that I can allocate certain width for each %s
(Left-aignlied) ?
Example:
fprintf("%s...
|
by: Craig Petrie |
last post by:
Hi,
I have a large table in Word 2003 that has formatted text in the cells and
wish to read and convert a cells formatted contents to html output via
vb.net code. The formatting contains the...
|
by: Tarun Mistry |
last post by:
Hi everyone, is it possible to return the formatted interpretation of an
XmlDocument object?
Using an XmlWriter object I can write a formatted document to a file,
however I want to store it...
|
by: Jojo |
last post by:
Hi all,
I was wondering how I can perform formatted output with C++ strings. For
example, suppose I have in plain C:
sprintf(C_string, "%5.2f %6d");
How can I do such a thing with C++...
|
by: keith |
last post by:
I've been beating my head against this for a little while, so perhaps
someone can help me out here? The code below should output exactly as
follows (the hex data lines up in a fixed font):
DATA...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |