[go: up one dir, main page]

Menu

[78dfa4]: / liftover.awk  Maximize  Restore  History

Download this file

56 lines (55 with data), 1.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#awk [-vinverse=1] -f liftover.awk ref.agp chr_pos_file >chr_pos_file.liftover
#liftover genomic coordinates based on an agp file
#if using vinverse=1, coordinates are mapped backwards
#coordinates not found from the agp are kept untouched
BEGIN{
FS="\t"
OFS="\t"
}
(NR==FNR && /^[^#]/) {
if (inverse) {
tmp = $1
$1 = $6
$6 = tmp
tmp = $2
$2 = $7
$7 = tmp
tmp = $3
$3 = $8
$8 = tmp
}
++ni[$6]
start1[$6, ni[$6]] = $7
stop1[$6, ni[$6]] = $8
start2[$6, ni[$6]] = $2
stop2[$6, ni[$6]] = $3
chr[$6, ni[$6]] = $1
orientation[$6, ni[$6]] = $9
}
(NR!=FNR && /^[^#]/) {
if ($1 in ni) {
if ($2+0 != 0)
$2=$2+0 #postion*
for (i = 1; i <= ni[$1]; ++i)
if ($2 >= start1[$1, i] && $2 <= stop1[$1, i]) {
if (orientation[$1, i] == "-") {
$2 = stop2[$1, i] - ($2 - start1[$1, i])
$1 = chr[$1, i]
} else {
$2 = start2[$1, i] + $2 - start1[$1, i]
$1 = chr[$1, i]
}
print
next
}
print
warning[$1 "\t" $2]
} else {
print
warning[$1]
}
}
END {
for (i in warning)
print "Warning: scaffold " i " not in agp file2" >"/dev/stderr"
}