Solved

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

Posted on 2006-11-05
3
200 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SIMPLE Perl Regex 1 158
perl to convert excel to csv 3 208
.properties file to call function/method 9 61
Regular Expression question to filter with negation. 6 95
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…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

776 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