Sponsored Content
Top Forums Shell Programming and Scripting Perl - quick inverse of a number range Post 302540404 by pn8830 on Wednesday 20th of July 2011 01:44:46 PM
Old 07-20-2011
Quote:
Originally Posted by bartus11
It might not be very pretty or short, but try it anyway:
Code:
perl -e '@x=(10,15,20,30,45,50);printf "0-";for ($i=0;$i<$#x;$i+=2){printf "%d,%d-",$x[$i]-1,$x[$i+1]+1};printf "60\n"'

Aghh... you beat me by a second!

Thanks a lot! It looks like you used the same approach as me. The only difference is that I had to loop through the array twice to take care of a situation when source ranges look like 10-15, 15-17, 20-30, 45-50.

There are two adjacent ranges (10-15, 15-17) that are actually 10-17. So if they are not take care of the result would be

0-9,16-14,18-19,31-44,51-60 oops...

Regards,
Pavel.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Quick perl question

Hey everyone, I am a newbie with perl, and I just have a quick question that may seem really stupid. Like I said, I'm new, so please bear w/ me :) I'm trying to make a really simple program where there are two inputs. First one is just a string, and the next one is a number. Once the user... (7 Replies)
Discussion started by: jason_v
7 Replies

2. Shell Programming and Scripting

validate number range

Hi If I want to read user input and want to validate if it is a numeric number in some range of 1-100 what would be the best way? Sabina (5 Replies)
Discussion started by: sabina
5 Replies

3. UNIX for Dummies Questions & Answers

Quick question about set number

In my .exrc file I have line numbers turned on but it adds an indent. I don't like this, is there a way to have the line numbers at the left edge of my terminal instead of indented? Here's my .exrc 1 set ignorecase noslowopen report=0 autoindent showmatch showmode nu 2 set... (4 Replies)
Discussion started by: ebadamageplan
4 Replies

4. Shell Programming and Scripting

Number range for SSNs

Hi All. I have a file that has an ID Number field....some of the ID Numbers are actual SSNs. ...does anyone know the range that SSNs may be...this is what I have found so far poking around SSN info sites.... greater than 001-01-0000 and less than 770-00-0000. Does anyone know this to be... (1 Reply)
Discussion started by: lyoncc
1 Replies

5. Shell Programming and Scripting

Closest Number from a Range of Numbers

out of a range of numbers, how can i pick out the number that is the closest to any arbitrary/random number that a user supplies? say the range of numbers are between 1 - 90000. but that doesn't mean each number exist between 1 - 90000. the range of numbers could be for example: 1, 3, 4, 6,... (6 Replies)
Discussion started by: SkySmart
6 Replies

6. Shell Programming and Scripting

how can I detect number series range

Hi I have one source file and content of source file as follows; 3 00 3 01 3 02 3 07 3 09 3 10 3 15 3 16 3 17 3 18 3 40 3 45 3 500 3 501 3 502 3 70 3 80 (8 Replies)
Discussion started by: kocaturk
8 Replies

7. Shell Programming and Scripting

Range of number from 0.1 to 10.0

Is there a way to create a loop that will output number starting from 0.1 to 10.0 0.1 0.2 0.3 0.4 0.5 .. ... 10.0 This is what i tried. for i in {1..50}; do printf -v i '%02d' $i ; echo "$i"; done That will print 01 02 03 .. .. 50 (9 Replies)
Discussion started by: vietrice
9 Replies

8. Shell Programming and Scripting

If statement test against number range [0-9]

Is it possible to test against a varible within a ranges in a if statement. ex. if ];then echo "not in range" else echo "number within range" fi (8 Replies)
Discussion started by: leemalloy
8 Replies

9. UNIX for Dummies Questions & Answers

Using sed to replace a range of number

Trying to use SED to replace numbers that fall into a range but can't seem to get the logic to work and am wondering if SED will do this. I have a file with the following numbers 3 26 20 5. For the numbers that are greater than zero and less than 25, SED would add the word range after the... (7 Replies)
Discussion started by: jimmyf
7 Replies

10. Shell Programming and Scripting

sed one Liner inverse range match-help required

cat test.txt a c d e g (2 Replies)
Discussion started by: TomG
2 Replies
Bio::Range(3pm) 					User Contributed Perl Documentation					   Bio::Range(3pm)

NAME
Bio::Range - Pure perl RangeI implementation SYNOPSIS
$range = Bio::Range->new(-start=>10, -end=>30, -strand=>+1); $r2 = Bio::Range->new(-start=>15, -end=>200, -strand=>+1); print join(', ', $range->union($r2)), " "; print join(', ', $range->intersection($r2)), " "; print $range->overlaps($r2), " "; print $range->contains($r2), " "; DESCRIPTION
This provides a pure perl implementation of the BioPerl range interface. Ranges are modeled as having (start, end, length, strand). They use Bio-coordinates - all points >= start and <= end are within the range. End is always greater-than or equal-to start, and length is greather than or equal to 1. The behaviour of a range is undefined if ranges with negative numbers or zero are used. So, in summary: length = end - start + 1 end >= start strand = (-1 | 0 | +1) FEEDBACK
Mailing Lists User feedback is an integral part of the evolution of this and other Bioperl modules. Send your comments and suggestions preferably to one of the Bioperl mailing lists. Your participation is much appreciated. bioperl-l@bioperl.org - General discussion http://bioperl.org/wiki/Mailing_lists - About the mailing lists Support Please direct usage questions or support issues to the mailing list: bioperl-l@bioperl.org rather than to the module maintainer directly. Many experienced and reponsive experts will be able look at the problem and quickly address it. Please include a thorough description of the problem with code and data examples if at all possible. Reporting Bugs Report bugs to the Bioperl bug tracking system to help us keep track the bugs and their resolution. Bug reports can be submitted via the web: https://redmine.open-bio.org/projects/bioperl/ AUTHOR - Heikki Lehvaslaiho Email heikki-at-bioperl-dot-org APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ Constructors new Title : new Usage : $range = Bio::Range->new(-start => 100, -end=> 200, -strand = +1); Function: generates a new Bio::Range Returns : a new range Args : -strand (defaults to 0) and any two of (-start, -end, -length), the third will be calculated unions Title : unions Usage : @unions = Bio::Range->unions(@ranges); Function: generate a list of non-intersecting Bio::Range objects from a list of Bio::Range objects which may intersect Returns : a list of Bio::Range objects Args : a list of Bio::Range objects Member variable access These methods let you get at and set the member variables start Title : start Function : return or set the start co-ordinate Example : $s = $range->start(); $range->start(7); Returns : the value of the start co-ordinate Args : optionally, the new start co-ordinate Overrides: Bio::RangeI::start end Title : end Function : return or set the end co-ordinate Example : $e = $range->end(); $range->end(2000); Returns : the value of the end co-ordinate Args : optionally, the new end co-ordinate Overrides: Bio::RangeI::end strand Title : strand Function : return or set the strandedness Example : $st = $range->strand(); $range->strand(-1); Returns : the value of the strandedness (-1, 0 or 1) Args : optionally, the new strand - (-1, 0, 1) or (-, ., +). Overrides: Bio::RangeI::strand length Title : length Function : returns the length of this range Example : $length = $range->length(); Returns : the length of this range, equal to end - start + 1 Args : if you attempt to set the length an exception will be thrown Overrides: Bio::RangeI::Length toString Title : toString Function: stringifies this range Example : print $range->toString(), " "; Returns : a string representation of this range Boolean Methods These methods return true or false. $range->overlaps($otherRange) && print "Ranges overlap "; overlaps Title : overlaps Usage : if($r1->overlaps($r2)) { do stuff } Function : tests if $r2 overlaps $r1 Args : a range to test for overlap with Returns : true if the ranges overlap, false otherwise Inherited: Bio::RangeI contains Title : contains Usage : if($r1->contains($r2) { do stuff } Function : tests whether $r1 totally contains $r2 Args : a range to test for being contained Returns : true if the argument is totally contained within this range Inherited: Bio::RangeI equals Title : equals Usage : if($r1->equals($r2)) Function : test whether $r1 has the same start, end, length as $r2 Args : a range to test for equality Returns : true if they are describing the same range Inherited: Bio::RangeI Geometrical methods These methods do things to the geometry of ranges, and return triplets (start, end, strand) from which new ranges could be built. intersection Title : intersection Usage : ($start, $stop, $strand) = $r1->intersection($r2) Function : gives the range that is contained by both ranges Args : a range to compare this one to Returns : nothing if they do not overlap, or the range that they do overlap Inherited: Bio::RangeI::intersection union Title : union Usage : ($start, $stop, $strand) = $r1->union($r2); : ($start, $stop, $strand) = Bio::Range->union(@ranges); Function : finds the minimal range that contains all of the ranges Args : a range or list of ranges Returns : the range containing all of the ranges Inherited: Bio::RangeI::union perl v5.14.2 2012-03-02 Bio::Range(3pm)
All times are GMT -4. The time now is 05:42 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy