Filtering my major and minor values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Filtering my major and minor values
# 8  
Old 01-03-2013
try also:
Code:
awk '
{
  delete a; mx=0; mn=100;
  for (i=2; i<=NF; i++) a[$i]++;
  for (i in a) {
    if (a[i] > mx ) mx=a[i];
    if (a[i] < mn ) mn=a[i];
  }
}
(mn / mx) * 100 > 30
' input

# 9  
Old 01-03-2013
Quote:
Originally Posted by rdrtx1
try also:
Code:
awk '
{
  delete a; mx=0; mn=100;
  for (i=2; i<=NF; i++) a[$i]++;
  for (i in a) {
    if (a[i] > mx ) mx=a[i];
    if (a[i] < mn ) mn=a[i];
  }
}
(mn / mx) * 100 > 30
' input

good idea, but.... a couple of missing points:
  1. you're counting Ns as legit fields while they should be skipped
  2. there's no provision to print lines with more than 2 unique field values
  3. 'delete a' doesn't work on all awk-s. Most awk's don't allow deleting the whole array that way, but only individual array entries. Therefore, the trick is to use 'split' to null-out the array in one step.
# 10  
Old 01-04-2013
Hi,

There is one more filter that needs to be considered.
I want to treat any character other than A,C,G,T,N as a missing value N.
In the example, the character Y is treated as if it was a missing value N since it
does not belong to the subset {A,C,G,T,N}.

For example the row
Code:
S10_14113072        A    C    C    A    A    Y

needs to be treated the same as
Code:
S10_14113072        A    C    C    A    A    N

But if such a row appears in the output it should appear as
Code:
S10_14113072        A    C    C    A    A    Y

---------- Post updated at 06:02 PM ---------- Previous update was at 05:57 PM ----------

I have done a small modification
Code:
if ($i != "[ACGTN]") { $i = "N" }

Doesnt seem to work. please help me with the correct code?


Code:
function initVars()
{
  split("",n)
  split("",a)
  c=0
}

{
  for(i=2;i<=NF;i++)
    if ($i != "[ACGTN]") { $i = "N" } 
    if ($i != "N") {
     if (!($i in a))
       n[++c]=$i
     a[$i]++
    }

  if (c>2) { initVars(); print;next }

  div=a[n[1]]/a[n[2]]
  div=(div>1)?1/div:div
  if ( div*100 > 30)
     print
  initVars()
}


Last edited by newbie83; 01-04-2013 at 06:18 PM..
# 11  
Old 01-04-2013
Change
Code:
  for(i=2;i<=NF;i++)
    if ($i != "[ACGTN]") { $i = "N" } 
    if ($i != "N") {
     if (!($i in a))
       n[++c]=$i
     a[$i]++
    }

to
Code:
  for(i=2;i<=NF;i++)
    if ($i ~ /[ACGT]/) {
     if (!($i in a))
       n[++c]=$i
     a[$i]++
    }

# 12  
Old 01-05-2013
awk

Code:
awk '{
    l_max=l_min=hasN=cnt=0
    delete _
    for(i=2;i<=NF;i++){
        if($i=="N")
            hasN=1
        _[$i]++
    }
    for(i in _){
        cnt++
        if(l_max==0 || _[i]>=l_max)
            l_max=_[i]
        if(l_min==0 || _[i]<=l_min)
            l_min=_[i]
    }
    if((cnt==2 && hasN==0) || (cnt==3 && hasN==1)){
        per=l_min/l_max
        if(per>=0.3)
            print $0
    }
}' yourfile

# 13  
Old 01-05-2013
change
Code:
if ($i != "N") {

to
Code:
if ($i != "N" && $i ~ /[ACGT]/ {

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

Major and Minor number of Virtual File System

Hi friends, Please let me know if there is any way to find out Major and Minor numbers of virtual file system like below: /devices 0K 0K 0K 0% /devices ctfs 0K 0K 0K 0% /system/contract proc 0K 0K ... (8 Replies)
Discussion started by: nitj
8 Replies

2. Shell Programming and Scripting

How to filter out major and minor?

Hi, I have line like this : proj_name/module/trunk/module_1_0 where the first "1" refers to major version and second "0" refers to minor version. any AWK or command like that so that I can filter out the major and minor ? like major= command | input line minor= command |... (4 Replies)
Discussion started by: bhaskar_m
4 Replies

3. Programming

which head file for major and minor function?

#include <sys/types.h> #include <sys/stat.h> #include <sys/termios.h> #include <stdio.h> #include <stdlib.h> #include <stddef.h> #include <string.h> #include <unistd.h> #include <signal.h> #include <sys/mkdev.h> int main(int argc, char *argv) { int i; struct stat buf; ... (4 Replies)
Discussion started by: konvalo
4 Replies

4. AIX

Difference between Major and Minor in AIX

Difference between Major and Minor in AIX (5 Replies)
Discussion started by: AIXlearner
5 Replies

5. AIX

how do I change major-minor numbers of disk devices

Good evening ... does anyone of you know how to change major/minor numbers of disk devices ? I had to migrate from raid1 to raid5 and this messed up my ASM cluster - I know which devices should have which IDs to match the content - but I have no idea how to change it. Any help would be... (2 Replies)
Discussion started by: zxmaus
2 Replies

6. Solaris

Help with Major and minor number

Hi Does anyone know what the major and minor numbers are in Solaris? (2 Replies)
Discussion started by: wisdom
2 Replies

7. Shell Programming and Scripting

sort major.minor.release_build_x

would like to order this input based on major.minor.release AND build number Label abc_def_0.0.3_build_999 2008/08/01 'Created by me.' Label abc_def_0.0.9_build_1000 2008/08/01 'Created by me.' Label abc_def_9.0.9_build_10001 2008/08/01 'Created by me.' Label abc_def_10.9.100_build_2... (4 Replies)
Discussion started by: gurpal2000
4 Replies

8. Solaris

major & minor number

Hi Can anyone tell me what is major number and minor number in the mknod command. Also what these numbers mean. I have gone through the man pages but still I couldn't understand. Regards (3 Replies)
Discussion started by: RajaRC
3 Replies

9. Programming

Device Major/Minor numbers

To further my fledgling knowledge of C, I am re-writing some of the Unix command set. My current command is an ls-style command. All works well, except for device files. How do I get the major/minor numbers for the dev files? I see from the stat struct there are st_rdev and st_dev members. Do... (1 Reply)
Discussion started by: zazzybob
1 Replies
Login or Register to Ask a Question