complement

Complement a DNA sequence

萝らか妹 提交于 2020-01-10 19:33:27
问题 Suppose I have a DNA sequence. I want to get the complement of it. I used the following code but I am not getting it. What am I doing wrong ? s=readline() ATCTCGGCGCGCATCGCGTACGCTACTAGC p=unlist(strsplit(s,"")) h=rep("N",nchar(s)) unlist(lapply(p,function(d){ for b in (1:nchar(s)) { if (p[b]=="A") h[b]="T" if (p[b]=="T") h[b]="A" if (p[b]=="G") h[b]="C" if (p[b]=="C") h[b]="G" } 回答1: Use chartr which is built for this purpose: > s [1] "ATCTCGGCGCGCATCGCGTACGCTACTAGC" > chartr("ATGC","TACG",s)

python3: How to get logical complement (negation) of a binary number, eg. '010' => '101'?

时光总嘲笑我的痴心妄想 提交于 2020-01-04 06:05:40
问题 Maybe I'm missing something but I can't find a straightforward way to accomplish this simple task. When I go to negate a binary number through the "~" operator it returns a negative number due to the two's complement: >>> bin(~0b100010) # this won't return '0b011101' '-0b100011' What about if I just want to switch 0s into 1s and vice-versa, like in classic logical complement? 回答1: >>> bin(0b111111 ^ 0b100010) '0b11101' >>> 回答2: YOU's answer as a function: def complement(n): size = len(format

Elements in a set that are not elements of another set (relative complement) [duplicate]

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-24 06:36:14
问题 This question already has answers here : Matlab arrays operation (3 answers) Closed 6 years ago . In matlab , how can I implement the following? Say that I have some set A and another set B , both of which have some elements. How can I write a function that returns only the values of B that are not in A (relative complement of A in B B\A ? Thanks. 回答1: use setdiff dif = setdiff( A, B ) 来源: https://stackoverflow.com/questions/14770613/elements-in-a-set-that-are-not-elements-of-another-set

Is two's complement notation of a positive number the same number?

此生再无相见时 提交于 2019-12-18 02:45:28
问题 Is two's complement notation of a positive number is same as its binary representation? 回答1: Is two's complement notation of a positive number the same number? The good example is from wiki that the relationship to two's complement is realized by noting that 256 = 255 + 1, and (255 − x) is the ones' complement of x 0000 0111=7 two's complement is 1111 1001= -7 the way it works is the msb(most significant bit) receives a negative value so in the case above -7 = 1001= -8 + 0+ 0+ 1 Edit- A

Need help understanding “getbits()” method in Chapter 2 of K&R C

∥☆過路亽.° 提交于 2019-12-17 15:25:26
问题 In chapter 2, the section on bitwise operators (section 2.9), I'm having trouble understanding how one of the sample methods works. Here's the method provided: unsigned int getbits(unsigned int x, int p, int n) { return (x >> (p + 1 - n)) & ~(~0 << n); } The idea is that, for the given number x , it will return the n bits starting at position p , counting from the right (with the farthest right bit being position 0). Given the following main() method: int main(void) { int x = 0xF994, p = 4, n

10's complement of a number statement

无人久伴 提交于 2019-12-13 03:34:05
问题 The values of a,x,y if 47x80 is the 10's complement of yaya0 is: I calculated the 10's complement of yaya0 to be 100,000-yaya0 and then. 47x80=100,000-yaya0 Now how to find values ? 回答1: 47080 + 100x = 100000 - (10000y + 1000a + 100y + 10a) 52920 = 100x + 10100y + 1010a ==> a = 2 otherwise you won`t get the 2 as tens 50900 = 100x + 10100y this can be split up in 5 = y and 9 = x + y so a = 2 x = 4 y = 5 回答2: 47x80 represents a number where 'x' is the hundreds. So does yaya0 where 'y' represent

find complement of regular expression

佐手、 提交于 2019-12-10 16:47:20
问题 There's a question on my exercise sheet to find the complement of two formulas (1) (aa|bb)* and (2) (a|b)(aa|bb)(a|b) . complement of both is in my opinion a* | b* , meaning only a 's or only b 's? 回答1: You need to go through the usual procedure: Convert regex to NFA. Convert NFA to DFA. For simple case, it is easy to convert (by hand) from regex to DFA directly. Turn all non-terminal state into terminal states and vice versa. Convert the complementing DFA to regex. This is one detailed

1s and 2s complement of a negative number

吃可爱长大的小学妹 提交于 2019-12-02 21:49:47
问题 All answers I seem to find on how to find the 1s (flip the bits of the positive) and the 2s (flip the bits of the positive binary and add 1) complement doesn't seem to answer my question. My homework assignment asks to find the complement of a negative number.. So instead of starting out with a positive, and needed to find out what its negative is, I am given a negative number and asked to find its complement. One silly thought is, do I find the positive value binary value, then flip the bits

Do we ignore overflow in Two's Complement

…衆ロ難τιáo~ 提交于 2019-12-02 13:59:26
问题 I'm trying to wrap my head around overflow within twos complement for example say I'm trying to take away these two binary numbers: 1111 1000 0100 - 010 111 001 000 I convert the 2nd binary number to it's two complement equivalent and then simply add it but I noticed it resulted in an overflow of 1, do I simply ignore the overflow? or is there a rule I must follow 1111 1000 0100 + 1010 0011 1000 = (1) 1001 1011 1100 回答1: Short answer: if you are performing arithmetic on fixed-width binary

Complement of empty index vector is empty index vector again

流过昼夜 提交于 2019-12-02 10:41:54
问题 I know this question was already posted but the answer was a trick to solve the given problem some other way, but the core question remained unanswered. The question is this. somevector <- 1:5 emptyindeces <- vector() somevector[-emptyindeces] #returns empty vector Why it is not the original vector? Is there a reason for that or am I understanding it wrong. If so whats the correct way to get the complement of an index vector. 回答1: emptyindices is logical(0) (logical vector of length = 0) and