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
Bio::PopGen::Genotype(3pm)				User Contributed Perl Documentation				Bio::PopGen::Genotype(3pm)

NAME
Bio::PopGen::Genotype - An implementation of GenotypeI which is just an allele container SYNOPSIS
use Bio::PopGen::Genotype; my $genotype = Bio::PopGen::Genotype->new(-marker_name => $name, -individual_id => $indid, -alleles => @alleles); DESCRIPTION
This object will contain alleles for a given marker for a given individual. The class variable BlankAlleles (accessible through $Bio::PopGen::Genotype::BlankAlleles = 'somepattern') can be set to a regexp pattern for identifying blank alleles which should no be counted (they are effectively missing data). By default it set to match white space, '-', 'N' or 'n', and '?' as blank alleles which are skipped. FEEDBACK
Mailing Lists User feedback is an integral part of the evolution of this and other Bioperl modules. Send your comments and suggestions preferably to the Bioperl mailing list. Your participation is much appreciated. bioperl-l@bioperl.org - General discussion http://bioperl.org/wiki/Mailing_lists - About the mailing lists Support Please direct usage questions or support issues to the mailing list: bioperl-l@bioperl.org rather than to the module maintainer directly. Many experienced and reponsive experts will be able look at the problem and quickly address it. Please include a thorough description of the problem with code and data examples if at all possible. Reporting Bugs Report bugs to the Bioperl bug tracking system to help us keep track of the bugs and their resolution. Bug reports can be submitted via the web: https://redmine.open-bio.org/projects/bioperl/ AUTHOR - Jason Stajich Email jason-at-bioperl.org CONTRIBUTORS
Matthew Hahn, matthew.hahn-at-duke.edu APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ new Title : new Usage : my $obj = Bio::PopGen::Genotype->new(); Function: Builds a new Bio::PopGen::Genotype object Returns : an instance of Bio::PopGen::Genotype Args : -marker_name => string representing name of the marker -individual_id => string representing individual id (optional) -alleles => arrayref with each item in the array being an allele marker_name Title : marker_name Usage : my $name = $genotype->marker_name(); Function: Get the marker name for a genotype result Returns : string Args : [optional] marker name value to store individual_id Title : individual_id Usage : my $indid = $genotype->individual_id(); Function: Gets the individual id associated with a genotype This is effectively a back reference since we will typically associate a genotype with an individual with an individual HAS-A genotype relationship. Returns : unique id string for an individual Args : none get_Alleles Title : get_Alleles Usage : my @alleles = $genotype->get_Alleles(); Function: Get the alleles for a given marker and individual Returns : array of alleles (strings in this implementation) Args : $showblank - boolean flag to indicate return ALL alleles not skipping the coded EMPTY alleles Note : Uses the class variable $BlankAlleles to test if alleles should be skipped or not. add_Allele Title : add_Allele Usage : $genotype->add_Allele(@alleles); Function: Add alleles to the genotype, at this point there is no verification to insure that haploid individuals only have 1 allele or that diploids only have 2 - we assume that is done by the user creating these objects Returns : count of the number of alleles in genotype Args : Array of alleles to store reset_Alleles Title : reset_Alleles Usage : $genotype->reset_Alleles; Function: Resets the stored alleles so the list is empty Returns : None Args : None perl v5.14.2 2012-03-02 Bio::PopGen::Genotype(3pm)
All times are GMT -4. The time now is 12:34 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy