Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Help with printing sorted expression Post 302517915 by pawannoel on Thursday 28th of April 2011 06:46:44 AM
Old 04-28-2011
Bug

@Bartus
I have 2 questions about a script relating to the parts in red
1. How can I combine the two IF statements in the WHILE loop so that I get output only if those conditions are met.
2. How so I print sorted results of hash of hashes in the END part
Script
Code:
#!/usr/bin/perl 
print "Enter minimum coverage: ";
chomp($min_cov=<STDIN>);
print "Enter minimum novel_Allele_Starts: ";
chomp($min_nas=<STDIN>);
open I, "$ARGV[0]";
while (<I>){
         @F=split;     
  $F[8]=~/coverage=([^;]+)/;
  if ($1>=$min_cov){
  $cov{$F[0]}{$F[3]}+=$1;
  $F[8]=~/novelAlleleStarts=([^;]+)/;
  if ($1>=$min_nas){
  $nas{$F[0]}{$F[3]}+=$1;
  }
  $n{$F[0]}{$F[3]}++;
  $h{$F[0]}++;
  }
}
END{
    for $i (keys %cov){
    for $j (keys %{$cov{$i}}){
      print "$i\t$j\t";
      printf "%.1f\t", ($cov{$i}{$j}/$n{$i}{$j});
      printf "%.1f\n", ($nas{$i}{$j}/$n{$i}{$j});   
    }
  }
  for $i (keys %h){
      @sorted=sort {$a cmp $b} keys %h;
  }
for $i (@sorted){
  print "$i\t$h{$i}\n";
        $t+=$h{$i};
 }
}

sample file for running script
Code:
SK1.chr10    SOLiD_diBayes    SNP    3120    3120    1.000000    .    .    genotype=A;reference=G;coverage=179;refAlleleCounts=32;refAlleleStarts=21;refAlleleMeanQV=15;novelAlleleCounts=117;novelAlleleStarts=27;novelAlleleMeanQV=17;diColor1=23;diColor2=23;het=0;flag=h8, 
SK1.chr01    SOLiD_diBayes    SNP    8621    8621    0.000000    .    .    genotype=C;reference=T;coverage=198;refAlleleCounts=5;refAlleleStarts=5;refAlleleMeanQV=18;novelAlleleCounts=150;novelAlleleStarts=49;novelAlleleMeanQV=18;diColor1=21;diColor2=21;het=0;flag=h4,h10,h9, 
SK1.chrm    SOLiD_diBayes    SNP    8844    8844    1.000000    .    .    genotype=C;reference=A;coverage=205;refAlleleCounts=38;refAlleleStarts=21;refAlleleMeanQV=24;novelAlleleCounts=164;novelAlleleStarts=51;novelAlleleMeanQV=27;diColor1=01;diColor2=01;het=0;flag=h8, 
SK1.chr07    SOLiD_diBayes    SNP    8852    8852    1.000000    .    .    genotype=T;reference=C;coverage=161;refAlleleCounts=31;refAlleleStarts=16;refAlleleMeanQV=24;novelAlleleCounts=127;novelAlleleStarts=47;novelAlleleMeanQV=23;diColor1=11;diColor2=11;het=0;flag=h8, 
SK1.chr07    SOLiD_diBayes    SNP    8865    8865    0.999102    .    .    genotype=G;reference=A;coverage=74;refAlleleCounts=11;refAlleleStarts=7;refAlleleMeanQV=26;novelAlleleCounts=59;novelAlleleStarts=29;novelAlleleMeanQV=24;diColor1=12;diColor2=12;het=0;flag=h8,

I'm not able to figure it out, can you please enlighten on this?
Cheers and have a nice day Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sorted processes

Hi, I am trying to make a script that creates a list of all active (alive) processes sorted by size and then print this list on screen. Could anyone help me? Thaks a lot (7 Replies)
Discussion started by: pro
7 Replies

2. Programming

error: initializer expression list treated as compound expression

I had seen this error for the first time ..... error: initializer expression list treated as compound expression please help.... (12 Replies)
Discussion started by: arunchaudhary19
12 Replies

3. Shell Programming and Scripting

SED printing just parts of lines that match an expression

Hi - I am guessing this is fairly simple for someone .. but I can not quite figure it out. I need a sed command to print just parts of lines from a file. e.g. filea.txt 4710451 : Success : MODIFY : cn=user1,dc=org,dc=uk Message log started Message log ended 4710452 : Success : MODIFY :... (7 Replies)
Discussion started by: sniper57
7 Replies

4. UNIX for Advanced & Expert Users

Sorted file

Hi Is there any unix shell command or utility to know if the file is sorted or not? Thanks (3 Replies)
Discussion started by: ksailesh
3 Replies

5. Shell Programming and Scripting

sed not printing lines before a regular expression.

Hey, I found a way to print the lines which is just before a regular expression, not including the expression. sed -n '/regexp/{n;p;}' myfile Now I'm looking for a way to print all lines, exept the regular expression and also the line before the same regular expression. Use code tags. (1 Reply)
Discussion started by: Livio
1 Replies

6. Shell Programming and Scripting

Printing several lines of a file after a specific expression

Hello, I want to print a number of lines of a file after a specific expression of a line. I have this sed command but it prints only 1 line after the expression. How could I adapt it to print for instance 10 lines after or 15 lines after ? sed -n '/regexp/{n;p;}' Thx & Regs, Rany. (5 Replies)
Discussion started by: rany1
5 Replies

7. Shell Programming and Scripting

Integer expression expected: with regular expression

CA_RELEASE has a value of 6. I need to check if that this is a numeric value. if not error. source $CA_VERSION_DATA if * ] then echo "CA_RELESE $CA_RELEASE is invalid" exit -1 fi + source /etc/ncgl/ca_version_data ++ CA_PRODUCT_ID=samxts ++ CA_RELEASE=6 ++ CA_WEEK_NO=7 ++... (3 Replies)
Discussion started by: ketkee1985
3 Replies

8. UNIX for Dummies Questions & Answers

Help with printing sorted array of numbers

Dear All, I am trying to sort an array of numbers to retrieve the mimimum and maximum values of numbers in that array, by printing the first and last elements of the sorted array. My code is @sorted_numbers = sort (@numbers); print "@sorted_numbers\n"; print "$sorted_numbers,... (0 Replies)
Discussion started by: pawannoel
0 Replies

9. UNIX for Advanced & Expert Users

sed: -e expression #1, char 0: no previous regular expression

Hello All, I'm trying to extract the lines between two consecutive elements of an array from a file. My array looks like: problem_arr=(PRS111 PRS213 PRS234) j=0 while } ] do k=`expr $j + 1` sed -n "/${problem_arr}/,/${problem_arr}/p" problemid.txt ---some operation goes... (11 Replies)
Discussion started by: InduInduIndu
11 Replies

10. Shell Programming and Scripting

sed , awk script for printing matched line before regular expression

hi All , I am having a large file with lots of modules as shown below ############################################### module KKK kksd kskks jsn;lsm jsnlsn; Ring jjsjsj kskmsm jjs endmodule module llll 1kksd11 k232skks j33sn;l55sm (6 Replies)
Discussion started by: kshitij
6 Replies
VP(4)							     Kernel Interfaces Manual							     VP(4)

NAME
vp - Versatec printer-plotter DESCRIPTION
Vp0 is the interface to a Versatec D1200A printer-plotter with a Versatec C-PDP11(DMA) controller. Ordinarily bytes written on it are interpreted as ASCII characters and printed. As a printer, it writes 64 lines of 132 characters each on 11 by 8.5 inch paper. Only some of the ASCII control characters are interpreted. NL performs the usual new-line function, i.e. spaces up the paper and resets to the left margin. It is ignored however following a CR which ends a non-empty line. CR is ignored if the current line is empty but is otherwise like NL. FF resets to the left margin and then to the top of the next page. EOT resets to the left margin, advances 8 inches, and then performs a FF. The ioctl(2) system call may be used to change the mode of the device. Only the first word of the 3-word argument structure is used. The bits mean: 0400 Enter simultaneous print/plot mode. 0200 Enter plot mode. 0100 Enter print mode (default on open). 040 Send remote terminate. 020 Send remote form-feed. 010 Send remote EOT. 04 Send remote clear. 02 Send remote reset. On open a reset, clear, and form-feed are performed automatically. Notice that the mode bits are not encoded, so that it is required that exactly one be set. In plot mode each byte is interpreted as 8 bits of which the high-order is plotted to the left; a `1' leaves a visible dot. A full line of dots is produced by 264 bytes; lines are terminated only by count or by a remote terminate function. There are 200 dots per inch both ver- tically and horizontally. When simultaneous print-plot mode is entered exactly one line of characters, terminated by NL, CR, or the remote terminate function, should be written. Then the device enters plot mode and at least 20 lines of plotting bytes should be sent. As the line of characters (which is 20 dots high) is printed, the plotting bytes overlay the characters. Notice that it is impossible to print characters on baselines that differ by fewer than 20 dot-lines. In print mode lines may be terminated either with an appropriate ASCII character or by using the remote terminate function. FILES
/dev/vp0 SEE ALSO
opr(1) VP(4)
All times are GMT -4. The time now is 03:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy