Solved

how to get rid of spaces in the output from this perl script

Posted on 2006-11-05
3
199 Views
Last Modified: 2010-03-05
Folks,
I have a perl script that actually parses following sample file:
gene            1995..3119
                     /gene="dnaN"
                     /locus_tag="AAur_0002"
     CDS             1995..3119
                     /gene="dnaN"
                     /locus_tag="AAur_0002"
                     /EC_number="2.7.7.7"
                     /note="identified by match to protein family HMM PF00712;
                     match to protein family HMM PF02767; match to protein
                     family HMM PF02768; match to protein family HMM TIGR00663"
                     /codon_start=1
                     /transl_table=11
                     /product="DNA polymerase III, beta subunit"
                     /protein_id="tigr:AAur_0002"
                     /translation="MKFRVDRDVLAEAVTWTARSLSPRPPVPVLSGLLLKAEAGTVSL
                     SSFDYETSARLEIPADIAVEGTILVSGRLLADICRSLPSAPVEVETDGSKVTLTCRRS
                     SFHLATMPESEYPALPALPAISGTLPGDAFAQAVSQVIIAASKDDTLPILTGVRMEIE
                     DDLITLLATDRYRLAMREVPWKPVTPGISTSALVKSKTLNEVAKTLGGSGDINLALAD
                     DDSRLIGFESGGRTTTSLLVDGDYPKIRSLFPDSTPIHATVQTQELVEAVRRVSLVAE
                     RNTPVRLAFTQGLLNLDAGTGEDAQASEELEAQLSGEDITVAFNPHYLVEGLSVIETK
                     YVRFSFTTAPKPAMITAQAEADGEDQDDYRYLVMPVRLPN"
gene            5318..5872
                     /locus_tag="AAur_0005"
     CDS             5318..5872
                     /locus_tag="AAur_0005"
                     /note="identified by match to protein family HMM PF05258"
                     /codon_start=1
                     /transl_table=11
                     /product="putative protein of unknown function (DUF721)"
                     /protein_id="tigr:AAur_0005"
                     /translation="MAKDSRDGLQPGREPDEIDAAQAALNRMREAAAARGEVRQRAPR
                     PGSAPKRQGLRDTRGFAQFHGSGRDPLGLGKVVGRLVAERGWTSPVAVGSVMAEWETL
                     VGPDISSHCTPESFTDTTLHVRCDSTAWATQLRLLSTSLLEMFRNELGEGVVTSIHVL
                     GPSAPSWRKGGRSVNGRGPRDTYG"


Here is the script:
use strict;
use vars
qw{
$table_line
};
$table_line ='';
while(<>)
{

        if(/^\s+\/product=(.*)/)
        {
                my $product =$1;
                while (<>)
                {
                        last unless /^\s+\/product=(.*)/;
                        $product =$product.$1;

                }
                $table_line =$table_line.$product."\t";
        }
                if(/^\s+\/protein_id=(.*)/)
        {
                $table_line = $table_line.$1."\t";

        }
         if(/^\s+\/translation=(.*)/)
        {
                my $translation = $1;
                while (<>)
                {
                        last unless /^\s+\        (.*)/;
                        $translation=$translation.$1;
                }
                $table_line=$table_line.$translation."\t";

        }
                print "$table_line\n";
                $table_line ="";


}


Here is the output from the script:  This script parses the input file and puts required entries in tabbed format in a output file:












"DNA polymerase III, beta subunit"      "tigr:AAur_0002"
"MKFRVDRDVLAEAVTWTARSLSPRPPVPVLSGLLLKAEAGTVSLSSFDYETSARLEIPADIAVEGTILVSGRLLADICRSLPSAPVEVETDGSKVTLTCRRSSFHLATMPESEYPALPALPAISGTLPGDAFAQAVSQVIIAASKDDTLPILTGVRMEIEDDLITLLATDRYRLAMREVPWKPVTPGISTSALVKSKTLNEVAKTLGGSGDINLALADDDSRLIGFESGGRTTTSLLVDGDYPKIRSLFPDSTPIHATVQTQELVEAVRRVSLVAERNTPVRLAFTQGLLNLDAGTGEDAQASEELEAQLSGEDITVAFNPHYLVEGLSVIETKYVRFSFTTAPKPAMITAQAEADGEDQDDYRYLVMPVRLPN"






"putative protein of unknown function (DUF721)" "tigr:AAur_0005"
"MAKDSRDGLQPGREPDEIDAAQAALNRMREAAAARGEVRQRAPRPGSAPKRQGLRDTRGFAQFHGSGRDPLGLGKVVGRLVAERGWTSPVAVGSVMAEWETLVGPDISSHCTPESFTDTTLHVRCDSTAWATQLRLLSTSLLEMFRNELGEGVVTSIHVLGPSAPSWRKGGRSVNGRGPRDTYG"


I wanted this script to inseatd not to print the blank spaces , instead it shd just print the required output in tabbed format .. any clues how can i get rid  of these blank spaces ..
0
Comment
Question by:bjuneja_2000
3 Comments
 
LVL 17

Expert Comment

by:mjcoyne
ID: 17878438
Before printing, try:

$table_line =~ s/^\s*$//g;
0
 

Author Comment

by:bjuneja_2000
ID: 17878659
hmm ,
Actually I tried that before , it didn't work .., not sure why ..
Any other clue ?
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 17878692
       print "$table_line\n" if $table_line;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

948 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

17 Experts available now in Live!

Get 1:1 Help Now