fileMulti2TableMod1 Usage Example

5 downloads 0 Views 259KB Size Report
mail 5 now 7 tomorrow 7 string 5 do 6 comeon 45 work 455 mondo 3 bike 56. DN52ei1f:~ milospjanic$ cat 2.test mail 4 now 4 test 56. 0 · 0 · 1 · Unwatch. Star.
This repository

Search

Pull requests

Issues

Gist

milospjanic / fileMulti2TableMod1 Code

Issues 0

Unwatch

Pull requests 0

Wiki

Pulse

Graphs

1

Star

0

Fork

0

Settings

Create master table from featureCounts or HTSeq outputs — Edit 6 commits

Branch: master

1 branch

New pull request

0 releases

Create new file

milospjanic Update README.md

1 contributor

Upload files

Find file

Clone or download

Latest commit 9aeda77 on May 6

README.md

Update README.md

4 months ago

fileMulti2TableMod1.awk

Create fileMulti2TableMod1.awk

4 months ago

README.md

fileMulti2TableMod1 Lets say you have multiple files with the same first column and you want to merge them. Use this awk script fileMulti2TableMod1. All files will be compared to the rows from 1st column of the 1st file. if one of the files has a missing value(s) even though they contain the correct element in first column, rows with missing values are not excluded but missing values are set to 0. Rows with column 1 not present in column 1 of the first file will not be shown, as well as those rows from the first file that are missing in other files' first columns. Only those rows with 1st columns present in every file are shown. See example.

Usage awk -f fileMulti2TableMod1.awk 1.test 2.test 3.test 4.test 5.test 6.test

Example DN52ei1f:~ milospjanic$ cat 1.test mail 5 now 7 tomorrow 7 string 5 do 6 comeon 45 work 455 mondo 3 bike 56 DN52ei1f:~ milospjanic$ cat 2.test mail 4 now 4 test 56

tomorrow 4 string 4 do 4 dodo 0101 DN52ei1f:~ milospjanic$ mail 6 now 6 tomorrow 7 string 5 do 67 ubas 5889 dodo 456789 dove 67 blis 4499 fry 456 DN52ei1f:~ milospjanic$ mail 89 blab 5 now 75 tomorrow 75 string do 555 DN52ei1f:~ milospjanic$ do 456 now 567 string DN52ei1f:~ milospjanic$ do 456 now string

cat 3.test

cat 4.test

cat 5.test

cat 6.test

DN52ei1f:~ milospjanic$ awk -f fileMulti2TableMod1.awk 1.test 2.test 3.test 4.test 5.test 6.test do 6 4 67 555 456 456 now 7 4 6 75 567 0 string 5 4 5 0 0 0

© 2016 GitHub, Inc.

Terms

Privacy

Security

Status

Help

Contact GitHub

API

Training

Shop

Blog

About

This repository

Search

Pull requests

Issues

Gist

milospjanic / fileMulti2TableMod1 Code

Issues 0

Branch: master

Unwatch

Pull requests 0

Wiki

Pulse

Graphs

1

Star

0

Fork

0

Settings

fileMulti2TableMod1 / fileMulti2TableMod1.awk

Find file

milospjanic Create fileMulti2TableMod1.awk

Copy path

bb8f7fc on May 6

1 contributor

19 lines (11 sloc) 1

Raw

626 Bytes

Blame

History

# Read first file and put first column into hash table h1 and second column into hash h2 with keys from first column

2 3

NR==FNR { h1[$1] = $1; h2[$1] = $2; next; }

4 5

# Read $1 from second, third file etc, compare first column with hash h1, if positive add to hash column 2

6 7

NF{ if($1 in h1) h2[$1] = h2[$1] OFS $2;}

8 9

# Read $1 and if it is empty append 0 to hash h2

10 11

NF{ if($1 in h1 && $2=="") h2[$1] = h2[$1] OFS 0}

12 13

# At the end calculate lenght of the hash h2 if it is >ARGC-2 print, this eliminates truncated rows that couldnt be found in all f

14 15

END { for(k in h2)

16

if(split(h2[k], a) > ARGC-2)

17 18

print k OFS h2[k] }

© 2016 GitHub, Inc.

Terms

Privacy

Security

Status

Help

Contact GitHub

API

Training

Shop

Blog

About