Sliding window


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Sliding window
# 1  
Old 02-12-2011
Sliding window

Very simple problem I am not able to solve. I have been trying to modify the following code:
Code:
awk '{t=$1; c = x}{for (i = 1; i <= length; i += wn)print t FS"" substr($2, i, mx) > ("block" ++c)}' mx=100 wn=100 infile.txt

What I am tryng to acccomplish, I have a bunch of files where the first number at the top is the number of sequences followed by the length of the sequences. Then, the first column is the SequenceID followed by the actual sequence, something like this:
Quote:
4 50
GADEN5572 AGGCTATAGGCTAAATTTCCCTTTCCCTGTTCCTTCCCTATTTCCCTTTGT
GAJFA4268 AGGCTATAGGCTAAATTTCCCTTTCCCTGTTCCTTCCCTATTTCCCTTTGT
GAMLT1199 AGGCTATAGGCTAAATTTCCCTTTCCCTGTTCCTTCCCTATTTCCCTTTGT
GAOCA1250 AGGCTATAGGCTAAATTTCCCTTTCCCTGTTCCTTCCCTATTTCCCTTTGT
I need to grab the first, let say 20 characters and create a file named block1.txt something like this:
Quote:
4 20
GADEN5572 AGGCTATAGGCTAAATTTCC
GAJFA4268 AGGCTATAGGCTAAATTTCC
GAMLT1199 AGGCTATAGGCTAAATTTCC
GAOCA1250 AGGCTATAGGCTAAATTTCC
Now the second number in the top is = 20 which corresponds to the length of the sequences. Then, I need to 'slide' the window let say 10 characters and grab the following 20 characters and create a second file named block2.fas, so on and so forth.
Quote:
4 20
GADEN5572 CTTTCCCTGTTCCTTCCCTA
GAJFA4268 CTTTCCCTGTTCCTTCCCTA
GAMLT1199 CTTTCCCTGTTCCTTCCCTA
GAOCA1250 CTTTCCCTGTTCCTTCCCTA
I am attaching a little example of the input file and the first 2 output (block) files.
Thanks a lot!

Last edited by Xterra; 02-13-2011 at 11:59 AM..
# 2  
Old 02-13-2011
So what's wrong with the code?

Get 20 characters with 10 characters back slide (same as your sample output)
Code:
awk '{t=$1; c = x}{for (i = 1; i <= length; i += wn)print t FS"" substr($2, i, mx) > ("block" ++c)}' mx=20 wn=10 infile.txt

Get the output as the attach files (block1.txt, block2.txt, etc)
Code:
awk '{t=$1; c = x}{for (i = 1; i <= length; i += wn)print t FS"" substr($2, i, mx) > ("block" ++c)}' mx=50 wn=10 infile.txt

# 3  
Old 02-13-2011
The very first line!

I need to include at the very top of each output (block?) file the number of sequences (12 in this particular case) followed by the length of the sequences (in my example 20).
I just do not know how to do it!
I will be very thankful if someone can help me with this problem!
Thanks in advance!
# 4  
Old 02-13-2011
first awk for title.
Code:
awk 'NR==1{s=$1}{l=length($2)>l?length($2):l}END {for (i = 1; i <= l; i += wn) print s FS mx > ("block" ++c)}'  mx=50 wn=10 infile.txt

awk 'NR>1 {t=$1;c = x; for (i = 1; i <= length($2); i += wn)print t FS"" substr($2, i, mx) >> ("block" ++c)}' mx=50 wn=10 infile.txt

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Toggle between xterm window and standard terminal window

Is it possible to toggle back and forth between an xterm invoked from one tty, and a shell invoked from a different tty? I am running Centos 7 with KDE and booting in non-graphic mode. After logging in on the default window (/dev/tty1) , I can then use ALT-F2 to access a new window (/dev/tty2),... (1 Reply)
Discussion started by: rhgscty
1 Replies

2. UNIX for Dummies Questions & Answers

Search and replace with a sliding window

Hi Unix Gurus, I have a file with data like: >header_1 TCCCCGA >header_2 CCAATTGGGTA The data to work with starts from the next line after '>header_xx'. (1) I want to search the three letter patterns 'CHH' or 'DDG' and replace C and G by exclamation ! so that CHH becomes !HH and DDG... (3 Replies)
Discussion started by: Fahmida
3 Replies

3. Shell Programming and Scripting

How do add values in a vector using a sliding window?

Greetings. I have a vector of numbers such as the following: 1 75 79 90 91 92 109 120 167 198 203 204 206 224 230 236 240 (4 Replies)
Discussion started by: Twinklefingers
4 Replies

4. Shell Programming and Scripting

Sliding window for string manipulation

I have a sting of "0"s and "1"s that I need to analyze. I need to look at each "1" and determine if it is in a neighborhood that is enriched for "1"s which means it is one of at least three "1"s in a 4 character window. My desired output is a count of "1"s in an enriched area. For Example Input... (1 Reply)
Discussion started by: monstrousturtle
1 Replies

5. UNIX for Dummies Questions & Answers

"Sliding window" with variables

I'm doing a little work that involves computing the average completion time of the last 5 of many file decompressions. It's not too tough, but I'm wondering if maybe there's a better way to write it. This is a bash script; here's the current idea: ctime5=$ctime4 ctime4=$ctime3 ctime3=$ctime2... (2 Replies)
Discussion started by: treesloth
2 Replies

6. Shell Programming and Scripting

Sliding window for sequencing data

Hi! I have some sequencing data that I have aligned using maq software Now, I have data that looks like this each line is a 'tag' chr1 10001 chr1 10002 chr1 10005 chr1 10007 chr1 10008 chr1 10008 chr1 10008 chr1 10019 chr1 10019 chr1 10020 What I really want to find out is how... (1 Reply)
Discussion started by: biobio
1 Replies

7. Shell Programming and Scripting

Script help: sliding time windows

I have a script like this ... #!/bin/ksh database=$(echo $@ | sed 's/.*-S \(*\).*/\1/') instance=$(grep $database /var/opt/oracle/oratab | awk -F : '{print $1}') command=$(echo $@ | sed "s/$database/$instance/") echo $command if I execute this script in ksh or bash it works fine . ... (3 Replies)
Discussion started by: talashil
3 Replies

8. Red Hat

Maximizing X window without Window Switcher

Hi everyone! I have a strange situation. I'm running an NX remote Gnome desktop session. On the remote machine, there is a whole load of unsaved data in a window. A problem that I've been having with this NX session is that I can't load Gnome Applets, including the Window Switcher. So.. when I... (0 Replies)
Discussion started by: alexandicity
0 Replies

9. Windows & DOS: Issues & Discussions

window 2000 professional not pinging my window 98 system.

Hello, We someone help me resolve this problem. I have window 2000 professional, windows 98 and Unixware 7.0.1 on the network. I was able to establish connection with all. However, l was unable to ping window 98 from window 2000 professional. I was able to ping the window 2000 from the window... (10 Replies)
Discussion started by: kayode
10 Replies

10. Programming

about X-window

Please, recommend anyone books about programming for X-window. (0 Replies)
Discussion started by: serge
0 Replies
Login or Register to Ask a Question