lomSpace has asked for the wisdom of the Perl Monks concerning the following question:
Hello!
I have a file that I have split and put into a hash and sorted based on the keys. Example:
For each key name/id, I want to do the following:Eif2b2 fail Eif2b2 pass5 Eif2b2 fail Eif2b2 pass2 Eif2b2 fail Eif2b2 pass4 Eif2b2 fail 49334 fail 49334 fail 49334 pass1 49334 fail 49334 pass4 Oxct1 pass4 Oxct1 fail Oxct1 pass4 Oxct1 fail
1. Count keys with no values above pass4 (pass1 to 3 are fine, 4 to fail are bad).
2. Count the keys which after excluding pass4 to fail have only one key value pair.
I would appreciate the monks direction.#!/usr/bin/perl -w use strict; use warnings; open( my $in, "c:/Documents and Settings/mydir/Desktop/current/mart_ex +port.txt" ); open( my $out, ">c:/Documents and Settings/mydir/Desktop/current/mart_ +export_counts.txt" ); my $first_line = <$in>; chomp $first_line; my %clone_hash; while (<$in>) { chomp; my @fields = split /\t/; my ($gene_symbol, $esc_qc, $qc_id) = ($fields[1], $fields[8], $fie +lds[9]); #my $count = 0; #my $clone1 = 0; $clone_hash{$gene_symbol} = $esc_qc; } # sort the oligos by gene_symbol my @sorted_keys = sort { $a <=> $b || $b cmp $a } keys %clone_hash; foreach my $key (@sorted_keys) { print $out "$key = $clone_hash{$key}\n"; } close ($in); close ($out);
|
---|