Find flanking positions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find flanking positions
# 1  
Old 03-22-2016
Find flanking positions

I have a positions file with markers in col1 and position defined by chromosome and location in col2 and col3

Code:
m1	ch1	1
m2	ch1	5
m3	ch1	50
m4	ch2	567
m5	ch2	4567
m6	ch2	7766
m7	ch2	554433
m8	ch3	76
m9	ch3	456
m10	ch3	2315

Given a set of query marker, I would like to know what are the flanking markers (just before and just after).


If My query is

Code:
QueryMarker	Chromosome	Position
Q1	ch1	43
Q2	ch1	400
Q3	ch3	2000
Q4	ch3	5000

How can I return flanking markers from the previous file, when such information is available

Code:
QueryMarker	Chromosome	Position	Left	pos	Right	Pos
Q1	ch1	43	m2	5	m3	50
Q2	ch1	400	m3	50	m4	567
Q3	ch3	2000	m9	456	m10	2315
Q4	ch3	5000	m10	2315	NA	NA


Here is what I tried maybe a little lost in the syntax,

Code:
awk 'NR==FNR{m[$1]=$2 FS $3;next} { prev=$0; mark=0;} { for (ms in m) { if ($2 FS $3 < ms[$2 FS $3]) mark=1; nextl=ms[$1 FS $2]} ; if (mark==0); posl="NA"; print $0 , prev, posl, nextl, posl}' marker query

# 2  
Old 03-22-2016
How come your ch1 400 line is "flanked" by the ch2 567 line? If the chromosome doesn't need to match, why then wouldn't ch3 456 flank the 400 line?

---------- Post updated at 21:30 ---------- Previous update was at 21:26 ----------

SHOULD the chromosome matter, this might work:
Code:
awk '
BEGIN           {print "QueryMarker     Chromosome      Position        Left    pos     Right   Pos"}
NR == FNR       {T1[NR] = $1
                 T2[NR] = $2
                 T3[NR] = $3
                 MX     = NR
                 next
                }

                {for (m=1; m<=MX; m++)  {if (T2[m] != $2) continue
                                         if (T3[m] <= $3) continue 
                                         print $0, T1[m-1], T3[m-1], T1[m], T3[m]
                                        }
                }
' file1 OFS="\t" file2
QueryMarker     Chromosome      Position        Left    pos     Right   Pos
Q1      ch1     43      m2      5       m3      50
Q3      ch3     2000    m9      456     m10     2315

This User Gave Thanks to RudiC For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Join based on positions

I have two text files as shown below cat file1.txt Id leng sal mon 25671 34343 56565 5565 44888 56565 45554 6868 23343 23423 26226 6224 77765 88688 87464 6848 66776 23343 63463 4534 cat file2.txt Id number 25671 34343 76767 34234 23343 23423 66776 23343 (4 Replies)
Discussion started by: halfafringe
4 Replies

2. UNIX for Dummies Questions & Answers

Replace alphabets from certain positions

Hi all, I have column 2 full of values like HIVE4A-56 and HIVE4-56. I want to convert all values like HIVE4A-56 to HIVE4-56. So basically I want to delete all single alphabets before the '-' which is always preceded by a number. Values already in the desired format should remain unchanged... (4 Replies)
Discussion started by: ames1983
4 Replies

3. Shell Programming and Scripting

Obtain the names of the flanking regions

Hi I have 2 files; usually the end position in the file1 is the start position in the file2 and the end position in file2 will be the start position in file1 (flanks) file1 Id start end aaa1 0 3000070 aaa1 3095270 3095341 aaa1 3100822 3100894 aaa1 ... (1 Reply)
Discussion started by: anurupa777
1 Replies

4. Shell Programming and Scripting

Modifying a sequence using positions!

Hi.. i have two files one with positions information and another is sequence information. Now i need to read the positions and take the snps at the positions and replace that position base with the snp information in the sequence and write it in the snp information file.. for example Snp file... (6 Replies)
Discussion started by: empyrean
6 Replies

5. Shell Programming and Scripting

awk regardless positions

brw------- 1 oracle dba 49, 21 Apr 05 11:45 dprod_0000018 brw------- 1 oracle dba 49, 26 Apr 05 11:45 dprod_0000019 brw------- 1 oracle dba 43, 93 Feb 02 2011 dprod_000002 brw------- 1 oracle dba 49, 27 Apr 05 11:45 dprod_0000020... (4 Replies)
Discussion started by: Daniel Gate
4 Replies

6. Shell Programming and Scripting

sed using data in two different positions

Hi, I cannot figure out how to input a greater than command for a item of data that may be in two different positions. my input file looks like this. isup,isupmap,2011,05,10 isup,isupmap,2011,05,11 isup,isupmap,2011,05,12 pcap,2011,05,10 pcap,2011,05,11 pcap,2011,05,12 You will see... (2 Replies)
Discussion started by: imarcs
2 Replies

7. UNIX for Dummies Questions & Answers

find positions of a letter in a text file

Hi, I would like to know how can I get all the positions of a letter, let say letter C in a text file. sample input file: hcck pgog hlhhc desired output file: 2 3 13 Many thanks! (2 Replies)
Discussion started by: fadista
2 Replies

8. Shell Programming and Scripting

awk script replace positions if certain positions equal prescribed value

I am attempting to replace positions 44-46 with YYY if positions 48-50 = XXX. awk -F "" '{if (substr($0,48,3)=="XXX") $44="YYY"}1' OFS="" $filename > $tempfile But this is not working, 44-46 is still spaces in my tempfile instead of YYY. Any suggestions would be greatly appreciated. (9 Replies)
Discussion started by: halplessProblem
9 Replies

9. Shell Programming and Scripting

script to find non overlapping positions

Hi, I am a newbie in unix programming so maybe this is a simple question. I would like to know how can I make a script that outputs only the values that are not between any given start and end positions Example file1: 2 30 40 80 82 100 file2: ID1 1 ID2 35 ID3 80 ID4 81 ID6 160... (1 Reply)
Discussion started by: fadista
1 Replies
Login or Register to Ask a Question