Chromosomal Bin Size Adjustment


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Chromosomal Bin Size Adjustment
# 1  
Old 03-16-2016
Chromosomal Bin Size Adjustment

Dear All,

Hope you are rocking.

I was using publicly available tools to do a task to chop a region into equal number of bins. But the glitch with this tool is that it causes the last region to carry lower number of bases than requested. But I want the first bin to have the lower ones.

Here is the input

Code:
cat input
chr1 100 225 name

When I ask to give me bins such that each bin size is 10bases, the current tool gives output this way

Code:
chr1 100 110 name1
chr1 110 120 name2
chr1 120 130 name3
chr1 130 140 name4
chr1 140 150 name5
chr1 150 160 name6
chr1 160 170 name7
chr1 170 180 name8
chr1 180 190 name9
chr1 190 200 name10
chr1 200 210 name11
chr1 210 220 name12
chr1 220 225 name12

If you see the last record, it is only 5bases long
Code:
chr1 220 225 name12

But I want this record to be 10bases long and the first record
Code:
chr1 100 110 name1

to be 5bases.


So my new output becomes

Code:
chr1 100 105
chr1 105 115
chr1 115 125
chr1 125 135
chr1 135 145
chr1 145 155
chr1 155 165
chr1 165 175
chr1 175 185
chr1 185 195
chr1 195 205
chr1 205 215
chr1 215 225

Thank you in advance
# 2  
Old 03-16-2016
How did you achieve your sample output? Why don't you do a quick calculation of the base count and then use the remainder for the first record?
225 - 100 = 125, 125 mod 10 = 5:
Code:
awk 'BEGIN {print 125%10}'
5

This User Gave Thanks to RudiC For This Post:
# 3  
Old 03-16-2016
Quote:
Originally Posted by RudiC
How did you achieve your sample output? Why don't you do a quick calculation of the base count and then use the remainder for the first record?
225 - 100 = 125, 125 mod 10 = 5:
Code:
awk 'BEGIN {print 125%10}'
5

Thank you Rudic.

That sample output was coming from a publicly available tool.

Your pointer helps with the first record. How do I specify the next records to use the value "10" in this example case?

Sorry I am a bit lost.
# 4  
Old 03-16-2016
try:
Code:
awk '
{
   for (i=$2; ($2 + base * ((2 * c) + 1))<=$3; i+=base) {
      f=$2 + base * ((2 * (b++ - 1)) + 1);
      print $1, ((f<$2)? $2 : f), $2 + base * ((2 * c++) + 1);
   }
}
' base=5 infile

This User Gave Thanks to rdrtx1 For This Post:
# 5  
Old 03-16-2016
Quote:
Originally Posted by rdrtx1
try:
Code:
awk '
{
   for (i=$2; ($2 + base * ((2 * c) + 1))<=$3; i+=base) {
      f=$2 + base * ((2 * (b++ - 1)) + 1);
      print $1, ((f<$2)? $2 : f), $2 + base * ((2 * c++) + 1);
   }
}
' base=5 infile

Hi rdrtx1,

Thank you for an amazing response.

But unlike my example, the bin size is not always twice the base size. So, I changed 2*c and the code is not generating any output.

Also, is there a way to print the 4th column by appending line number at the end?

Thank you
# 6  
Old 03-16-2016
The formula was just for odd number series as per the example. Change the formula according to the series. To add the name and counter use (based on example):
Code:
print $1, ((f<$2)? $2 : f), $2 + base * ((2 * c++) + 1), $4 c;

This User Gave Thanks to rdrtx1 For This Post:
# 7  
Old 03-16-2016
Quote:
Originally Posted by rdrtx1
The formula was just for odd number series as per the example. Change the formula according to the series. To add the name and counter use (based on example):
Code:
print $1, ((f<$2)? $2 : f), $2 + base * ((2 * c++) + 1), $4 c;

Thank you for the 4th column tweak.

I understand that this task is for odd numbers only. But my problem here is that the bin size is becoming twice of the base value which is not anticipated. I want my bin size to be constant at 100 after first record being adjusted to the base value.

Makes sense?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Usage of #!/bin/sh vs #!/bin/bash shell scripts?

Some question about the usage of shell scripts: 1.) Are the commands of the base shell scripts a subset of bash commands? 2.) Assume I got a long, long script WITHOUT the first line. How can I find out if the script was originally designed für "sh" or "bash"? 3.) How can I check a given... (3 Replies)
Discussion started by: pstein
3 Replies

2. AIX

Redistribution bin required for AIX. j7r164redist.7.1.0.25.bin

Hi, I am planning to install a version of Informatica on my AIX box. It requires a specific java build in pap6470_27sr2-20141101_01(SR2). The current link for IBM 64-bit SDK for AIX®, JavaTM Technology Edition, Version 7 Release 1 has a more recent version in j7r164redist.7.1.0.75.bin. Is... (4 Replies)
Discussion started by: meetpraveens
4 Replies

3. Shell Programming and Scripting

Adjustment to current awk statement

Hello all, I have a script that currently works very well but I would like to make a change so that I could prompt for user input for a 2 digit numeric field that would represent the month instead of using the system date for the month. This is my current awk script that Don so graciously... (1 Reply)
Discussion started by: ziggy6
1 Replies

4. Shell Programming and Scripting

awk adjustment to print total

im trying to print all lines in the /var/log/syslog file that contain the pattern CRON. and after all the lines have been printed, i want a total of all the lines that contained "CRON" to be printed at the end. the below command is printing the correct lines, but it is giving me the sum of all... (1 Reply)
Discussion started by: SkySmart
1 Replies

5. OS X (Apple)

When to use /Users/m/bin instead of /usr/local/bin (& whats the diff?)?

Q1. I understand that /usr/local/bin means I can install/uninstall stuff in here and have any chance of messing up my original system files or effecting any other users. I created this directory myself. But what about the directory I didn't create, namely /Users/m/bin? How is that directory... (1 Reply)
Discussion started by: michellepace
1 Replies

6. Ubuntu

Brightness adjustment

Hi all, I am using Ubuntu 10.04 LTS in Samsung N148. I can't see any option to adjust brightness in System->Preference->monitor. Is there any shell command to adjust brightness ? I have used xgamma -gamma but it change the gamx not brightness. Cheers (7 Replies)
Discussion started by: gvj
7 Replies

7. UNIX for Dummies Questions & Answers

fuser: difference with bin/sh and bin/ksh shell script

Hi, I have a problem I don't understand with fuser. I launch a simple shell script mysleep.sh: I launch the command fuser -fu mysleep.sh but fuser doesn't return anything excepted: mysleep: Then I modify my script switching from #!/bin/sh to #!/bin/ksh I launch the command fuser -fu... (4 Replies)
Discussion started by: Peuj
4 Replies

8. HP-UX

How to disable time auto adjustment ??

We do not use ntp.conf file. However time's changed automatically. How can i disbale automatic time adjustment ? Thank you in advance. (6 Replies)
Discussion started by: v838
6 Replies

9. UNIX for Dummies Questions & Answers

/bin/sh: /usr/bin/vi: No such file or directory when doing crontab

I just set up an ftp server with Red Hat 5.2. I am doing the work, I'm baby stepping, but it seems like every step I get stuck. Currently, I'm trying to set up a crontab job, but I'm getting the following message: /bin/sh: /usr/bin/vi: No such file or directory. I see that vi exists in /bin/vi,... (3 Replies)
Discussion started by: kwalter
3 Replies
Login or Register to Ask a Question