Question: (Closed) How can I print all lines? PERL
gravatar for darya_boris
22 months ago by
darya_boris0 wrote:

Hello, I have such problem: I want to print all lines with new added column: IN or OUT, the script runs, but I can't understand, why there is only first line you have any suggestions?

This is my script:

use strict; 
use warnings;

open(FILE, "Q.txt");
my $file = <>;                            #FILE

my @column;

while (<>) {                               #FILE


chomp @column; 

my $number=0;

    while($number <= $#column) {                    #go through the array from 0 to the last element
    my $j;
    my $count=0;
        foreach ($j=$number; $j < $#column; $j++) {   #select the numbers from the beginning of the line 
        my $d=($column[$j]=~/(\d+)/)[0] - ($column[$j+1]=~/(\d+)/)[0];  #difference
            last if abs($d)!= 1;                    #if differ more than 1 - leave. I

        $count+=$d;                                     #accumulate the difference.     

    if(abs($count)>=8) {                            
    $column[$_].= " t\IN "      for $number..$j;                    

    $column[$number].= " \tOUT" ;                               
print for @column;              

And here is my INPUT FILE:

16 Q CAG
21 Q CAA
74 Q CAA
80 Q CAG
82 Q CAG
84 Q CAG
85 Q CAG
89 Q CAG
90 Q CAG
91 Q CAG
92 Q CAG
93 Q CAA
94 Q CAG
95 Q CAG
96 Q CAG
98 Q CAG
99 Q CAG
100 Q CAG
101 Q CAG
102 Q CAG
106 Q CAG
107 Q CAG
108 Q CAG
109 Q CAG
110 Q CAG
111 Q CAG
112 Q CAG
113 Q CAA
114 Q CAG
115 Q CAG
116 Q CAG
118 Q CAG
120 Q CAG
121 Q CAG
125 Q CAG
126 Q CAG
127 Q CAG
129 Q CAA
133 Q CAG
134 Q CAG
135 Q CAG
136 Q CAG
137 Q CAG
139 Q CAG
140 Q CAG
141 Q CAG
142 Q CAG
143 Q CAG
144 Q CAG
145 Q CAG
146 Q CAG
154 Q CAA
156 Q CAG
157 Q CAA
158 Q CAG
160 Q CAG
161 Q CAG
162 Q CAG
163 Q CAA
164 Q CAG
165 Q CAG
167 Q CAG
171 Q CAG
173 Q CAG
175 Q CAA

Here is my OUTPUT FILE:

5 Q CAA OUT and etc...but it prints only my first line

Thank you!

ADD COMMENTlink modified 22 months ago by Pierre Lindenbaum120k • written 22 months ago by darya_boris0

Hi can you explain the goal of this script with better example ? what you expect in out file ?

ADD REPLYlink written 22 months ago by Titus860

Hello, I expect my output file in this way:

and ect...(some will include IN)

I don't now, why the 1st line in this comment is shifted....

ADD REPLYlink modified 22 months ago • written 22 months ago by darya_boris0

ok then what is the condition for add IN or OUT at the end of your line , when i run you script only the first line is print in the while .... what is Q.txt file ? ....

ADD REPLYlink written 22 months ago by Titus860

I have a file that says: Column 1 is the amino acid sequence number "Q" and codons. Column 2 - sequence Q. Column 3 is the nucleotide corresponding to the given amino acid.

My codons, which are in the polyQ (IN) segment, must be in the sequence of digits from the first column of 8 and above, that is> = 8. For example, the first number in the first column = 5 After it goes not 6, 7, 8 and so on, but goes 16, we do not have a sequence of digits, which is 8 and higher. -> that is, the codon that is opposite to this digit 5 ​​- does not belong to the polyQ sequence, that is, it OUT

If we look at the number 84, we see that behind it is the next-in-order number of 85. That is, our limit is 2, because it consists of two numbers going one after another. But this does not correspond to the condition that the limit of numbers going after one another is 8 and higher, so these codons do not lie in the sequence polyQ.

If we look at the figure 89, then we see a sequence of 89, then there are numbers in order: 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102 -> The sequence of numbers after the other, which is greater than 8, which corresponds to our condition that the codons in the sequence of numbers from 8 and above refer to polyQ - (IN)

I need to write a script, with an additional column number 4, where IN or OUT will be specified, depending on where this codon lies - in the limit of numbers going one after another 8 and higher - IN; Or which do not lie in this limit, that is, less than 8 -OUT.

ADD REPLYlink written 22 months ago by darya_boris0

Hello darya_boris!

We believe that this post does not fit the main topic of this site.

This is a programming question. Please check/ask Stack Overflow.

For this reason we have closed your question. This allows us to keep the site focused on the topics that the community can help with.

If you disagree please tell us why in a reply below, we'll be happy to talk about it.


ADD REPLYlink written 22 months ago by RamRS22k
Please log in to add an answer.
The thread is closed. No new answers may be added.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1236 users visited in the last hour