How To Re-Scale The Values In A Tabular File
3
1
Entering edit mode
11.7 years ago
2011101101 ▴ 110

Thank you for your attention first.I have a file,there are some columns in the file.I need to be calculated in accordance with column.There is an example:

motif    WSB-1    WSB-2    SM-1    SM-2    PH-1    PH-2    MY-1    MY-2    total 
ATCGAGACTGGGATTTGTCACTCC    62    98    76    64    141    286    124    169    1020
GAACCGGGACTAATGGGCTGACCC    12    26    6    7    36    107    42    32    268
TATTAGTTTACAGAGGGAGTA    10    26    13    10    49    39    46    26    219
ATAGCCACCCAGTTACGTTGTGAC    8    24    8    5    26    71    33    31    206

I need the column of WSB-1 Divided by(/)100,WSB-2/200,SM-1/300,SM-2/400,PH-1/500,PH-2/600,MY-1/700,MY-2/800.

The result should be this

motif    WSB-1    WSB-2    SM-1    SM-2    PH-1    PH-2    MY-1    MY-2    total 
ATCGAGACTGGGATTTGTCACTCC    0.620     0.490     0.253     0.160     0.282     0.477     0.177     0.211     1020
GAACCGGGACTAATGGGCTGACCC    0.120     0.130     0.020     0.018     0.072     0.178     0.060     0.040     268
TATTAGTTTACAGAGGGAGTA    0.100     0.130     0.043     0.025     0.098     0.065     0.066     0.033     219
ATAGCCACCCAGTTACGTTGTGAC    0.080     0.120     0.027     0.013     0.052     0.118     0.047     0.039     206
• 2.2k views
ADD COMMENT
3
Entering edit mode
11.7 years ago
zx8754 12k

If you want to keep the header

awk '{OFS="\t"; if (NR==1) print $0; else print $1,$2/100,$3/200,$4/300,$5/400,$6/500,$7/600,$8/700,$9/800,$10};' input.txt

motif    WSB-1    WSB-2    SM-1    SM-2    PH-1    PH-2    MY-1    MY-2    total
ATCGAGACTGGGATTTGTCACTCC        0.62    0.49    0.253333        0.16    0.282  0.476667 0.177143        0.21125 1020
GAACCGGGACTAATGGGCTGACCC        0.12    0.13    0.02    0.0175  0.072   0.1783330.06    0.04    268
TATTAGTTTACAGAGGGAGTA   0.1     0.13    0.0433333       0.025   0.098   0.065  0.0657143        0.0325  219
ATAGCCACCCAGTTACGTTGTGAC        0.08    0.12    0.0266667       0.0125  0.052  0.118333 0.0471429       0.03875 206
ADD COMMENT
2
Entering edit mode
11.7 years ago
AGS ▴ 250
awk 'NR>1' yourfile | awk '{print $1"\t"$2/100"\t"$3/200"\t"$4/300"\t"$5/400"\t"$6/500"\t"$7/600"\t"$8/700"\t"$9/800"\t"$10}'

ATCGAGACTGGGATTTGTCACTCC    0.62    0.49    0.253333    0.16    0.282    0.476667    0.177143    0.21125    1020
GAACCGGGACTAATGGGCTGACCC    0.12    0.13    0.02        0.0175    0.072    0.178333    0.06        0.04    268
TATTAGTTTACAGAGGGAGTA        0.1     0.13    0.0433333    0.025    0.098    0.065        0.0657143    0.0325    219
ATAGCCACCCAGTTACGTTGTGAC    0.08    0.12    0.0266667    0.0125    0.052    0.118333    0.0471429    0.03875    206
ADD COMMENT
1
Entering edit mode
11.7 years ago
brentp 24k

In python:

from toolshed import reader

for i, d in enumerate(reader("-", header="ordered")):
    if i == 0: print "\t".join(d.keys())
    vals = d.values()
    vals[2:-1] = ["%.3f" % (j * v / 100.) for j, v \
                    in enumerate(map(float, vals[2:-1]), 1)]
    print "\t".join(vals)

reads from stdin and writes to stdout. awk is better until you want to do something slightly different or add/remove columns.

ADD COMMENT

Login before adding your answer.

Traffic: 858 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6