Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: How do I remove spaces between sequences in a file

by bingalee (Acolyte)
on Jun 19, 2013 at 22:12 UTC ( #1039854=note: print w/ replies, xml ) Need Help??


in reply to Re: How do I remove spaces between sequences in a file
in thread How do I remove spaces between sequences in a file

No- like this

CCTGCCCGGGCGGAGGGAGGCGCGGCGCAACGGACTTCATGCTGCCACCCGCCGACCCG CACCTCACCGGCTCACCTACACCCTCCTCTTCGTTCGTCTCTTATCCATGCAATGCATC GTCTGACCTTGCCTTTTGTCTTTTACAAACACTGCCATCAGCAAATCATGCTATTTTTA TGCCGTCACGTTTCATGCAGCTATGTGTAAATAAATAAAACGTATATAACGCATTTTAA TCATAGATCCCCGACGCAACAACAATTGCAGCCACACCCCCGCGGAGCCATCACCTTTC ACTCTAATTAGAAACATCGACCTGCTCAACCCACCGAGGAATATAGACTGTTTTTTTTT CTATGTGGAAATACCAAGTAGTAGTGCCAAACGCTAAAAGGGTATGCATCTTAATTGAT GAGCTGTGAGGGTGCAATCTACAAGAGTGCGGGTTCGCGTTCAGTCCAAGCTGAACATA AACGCAACGCAAGGCCCCTCGACGCAGATACCGCGCTCAGGAGCATTCGAGAAGCCGAA GAAAATTCGAAGACGAGGACCAGCTACACTGCGGACGGACTTCGGGCATGGAGGGCCAG TTCCAGGTTGGCAAGGAGGAGGTCATCCAAGCATGGTACATGGACGACAGTGAAGAGGA CCAGAGGCTTCCTCATCATCGTGAGCCCAAAGAATTCATTCCTCTCGACAAACTTTCCG AACTAGGAATATTAAGCTGGCGCCTAAATGCTGATGATTGGGAGAATGATGAGAACCTC AAGAAAATTCGTGAAGCCAGGGGTTACTCTTACATGGACATTTGTGATGTGTGCCCAGA GAAGTTGCCAAATTACGAGGCTAAGATAAAGAATTTCTTTGAAGAACACTTGCATACTG ATGAAGAGATACGATATTGCCTTGAGGGTAGCGGCTACTTTGATGTGAGGGACCAAGAT GATCAGTGGATCCGTGTAGCGGTAAAGAAAGGGGGCATGATCGTTTTGCCTGCAGGAAT GTATCATCGCTTTACGTTGGATAGTGACAACTACATCAAGGCAATGCGTCTATTTGTGG GTGAGCCTGTCTGGACACCATACAATCGTCCGCATGACCATCTCCCGGCTAGGAAGGAG TACGTCGAGAAAATCATCAACCGAGGTGGAAACCAAGCCGTCGAAGCTCGTTGAGCGTG TCCACTCTACATGTCCTCCTGCCGTCTCAGCCTCTTGTGTTTTACACCCTACAACTCCT AGTACCGCCGAATAAGATTTGCTATCTGCAATGTGCTCATGCCACCGCTGTGTGTGCCA GTTAACAGTTTGCACGAAACCCTAGATATTTTGTTATACGAATGAATGACATGTGGTGT TTGATAAATGATGAAACGATGATGGTTCAAATCAACCCACCTGTCTTTCACAAGTTCGA TGAAACGTTGCGCGCAATGGTTGTTTACTGAAAAGGATGCCTCTAACCAGCCGTCAGTC TGACTGGATGTCGTGGATCAACTGCCGACCAACATCTTGTCTGCGCTCGTGCCGCGTGA GTAACTGCTGTCGTTCTCACTGAGGGCGAGCAGGGCCTTGGTAATGATGTACTGTTTCA CAGTAACAGTTCTGTTGATCACCGAAAGGTTTGTGCAGGTTGATGTGATGTGACGATGC TGGGTGGCTCCTGCCTAGAAAACGTGTGGTGGTTGAAATGAACGCGTTCCATGTCTGTC GTCTAGTCACTCGTCGAGCTTTGGTCGGCGGAGCCGATCACCGGCCAAGAACATTTGTG ATCTCGATGATATACTTGTGTGCGGCTGCATTGCCGCACAAAAGGTTCATATTGCCATC ATCGTTCCTGCTCACAGATGGTAGTGGTGACGCACTGGCAAATAGACCTGATTTCATTG CGCAGCCAGATTCATCTATGGCTGAC


Comment on Re^2: How do I remove spaces between sequences in a file
Download Code
Re^3: How do I remove spaces between sequences in a file
by davido (Archbishop) on Jun 19, 2013 at 22:24 UTC

    Are you trying to say that you want to remove all spaces (including newlines) and then ensure that there's a newline after every 59th character?

    my $input = do { local $/ = undef; <DATA> }; $input =~ s/\s//mg; # Remove all whitespace. $input =~ s/(.{59})/$1\n/g; # Place a \n after every 59th character. print "$input\n"; __DATA__ GAGGGTGCAATCTACAAGAGTGCGGGTTCGCGTTCAGTCCAAGCTGAACATAAACGCAAC GCAAGGCCCCTCGACGCAGATACCGCGCTCAGGAGCATTCGAGAAGCCGAAGAAAATTCG AAGACGAGGACCAGCTACACTGCGGACGGACTTCGGGCATGGAGGGCCAGTTCCAG GTTGGCAAGGAGGAGGTCATCCAAGCATGGTACATGGACGACAGTGAAGAGGACCAGAGG CTTCCTCATCATCGTGAGCCCAAAGAATTCATTCCTCTCGACAAACTTTCCG AACTAGGAATATTAAGCTGGCGCCTAAATGCTGATGATTGGGAGAATGATGAGAACCTCA AGAAAATTCGTGAAGCCAGGGGTTACTCTTACATG GACATTTGTGATGTGTGCCCAGAGAAGTTGCCAAATTACGAGGCTAAGATAAAGAATTTC TTTGAAGAACACTTGCATACTGATGAAGAGATACGATATTGCCTTGAGGGTAGCG GCTACTTTGATGTGAGGGACCAAGATGATCAGTGGATCCGTGTAGCGGTAAAGAAAGGGG GCATGATCGTTTTGCCTGCAGGAATGTATCATCGCTTTACGTTGGATAGTGACAACTACA TCAAG GCAATGCGTCTATTTGTGGGTGAGCCTGTCTGGACACCATACAATCGTCCGCATGACCAT CTCCCGGCTAG

    ...produces...

    GAGGGTGCAATCTACAAGAGTGCGGGTTCGCGTTCAGTCCAAGCTGAACATAAACGCAA CGCAAGGCCCCTCGACGCAGATACCGCGCTCAGGAGCATTCGAGAAGCCGAAGAAAATT CGAAGACGAGGACCAGCTACACTGCGGACGGACTTCGGGCATGGAGGGCCAGTTCCAGG TTGGCAAGGAGGAGGTCATCCAAGCATGGTACATGGACGACAGTGAAGAGGACCAGAGG CTTCCTCATCATCGTGAGCCCAAAGAATTCATTCCTCTCGACAAACTTTCCGAACTAGG AATATTAAGCTGGCGCCTAAATGCTGATGATTGGGAGAATGATGAGAACCTCAAGAAAA TTCGTGAAGCCAGGGGTTACTCTTACATGGACATTTGTGATGTGTGCCCAGAGAAGTTG CCAAATTACGAGGCTAAGATAAAGAATTTCTTTGAAGAACACTTGCATACTGATGAAGA GATACGATATTGCCTTGAGGGTAGCGGCTACTTTGATGTGAGGGACCAAGATGATCAGT GGATCCGTGTAGCGGTAAAGAAAGGGGGCATGATCGTTTTGCCTGCAGGAATGTATCAT CGCTTTACGTTGGATAGTGACAACTACATCAAGGCAATGCGTCTATTTGTGGGTGAGCC TGTCTGGACACCATACAATCGTCCGCATGACCATCTCCCGGCTAG

    Dave

      Hey Dave, that's EXACTLY what I wanted. Thank you so much :D. This is the code I used,

      for($i=1;$i<=scalar(@detail);$i++) { print OUT "$detail[$i-1]"; if($i%59==0) { print OUT "\n"; } }

      but yours looks worked too. thanks :)

        It's an interesting choice that you decided to produce an off-by-one error in the generation of indexes in your loop control, and then remove it by subtracting one from the array indexing. Using a C-style loop you could have done this:

        for( my $i = 0; $i < @detail - 1; $i++ )

        ...or better...

        for( my $i = 0; $i < $#detail; $i++ )

        ...or even...

        foreach my $i ( 0 .. $#detail ) {

        Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1039854]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (8)
As of 2015-07-07 09:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls