I'm trying to do the Kmap for F(A,B,C,D)= A’B’C’D’+AC’D’+B’CD’+A’BCD+BC’D . I'm getting a little confused because not all the variable groupings have the same number of variables. some have 4 and some have 3. is this equivalent to F(A,B,C,D) = F(0,2,4,5,7) ? I don't know if you have to do something extra if theres a variable missing. like in the 2nd grouping (AC'D') theres no B. so do we have to do something to compensate for the missing term or is this just 4.
I'm not sure where those numbers 0,4,2,5,7 are coming from, a Karnaugh map (assuming that's what you meant) simply specifies the truth output for given inputs.
If a term is missing, then it has no effect on the outcome so either of its two possible values will affect the truth output. So, in essence, the following two expressions are identical:
AC'D' <=> A(B)C'D' + A(B')C'D'
If more than one term is missing, then you simply allow for more than two possibilities (2n, where n is the number of missing terms). So A would also be:
ABCD + ABCD' + ABC'D + ABC'D' + AB'CD + AB'CD' + AB'C'D + AB'C'D'
(A matched against the 23 = 8 possibilities for the B, C and D variables).
Hence the map for your particular function:
A'B'C'D' + AC'D' + B'CD' + A'BCD+BC'D
would be, for term one A'B'C'D':
AB:00 01 10 11
CD:00 T . . .
01 . . . .
10 . . . .
11 . . . .
or'ed with term two AC'D', equivalent to ABC'D + AB'C'D:
AB:00 01 10 11
CD:00 . . T T
01 . . . .
10 . . . .
11 . . . .
or'ed with term three B'CD', which expands to AB'CD + A'B'CD:
AB:00 01 10 11
CD:00 . . . .
01 . . . .
10 T . T .
11 . . . .
and, finally, or'ed with term four BC'D, equal to ABC'D + A'BC'D:
AB:00 01 10 11
CD:00 . . . .
01 . T . T
10 . . . .
11 . . . .
Combining all these gives you:
AB:00 01 10 11
CD:00 T . T T
01 . T . T
10 T . T .
11 . . . .
A term with 3 variables just means that it covers 2 cells in the Karnaugh map.
AB 00 01 11 10
CD
00 XX YYYYYY
01
11
10
So XX is A'B'C'D' and YYYYYY is AC'D'.
The point in AC'D' is that the value of B is irrelevant, so it can be 1 or 0, so there are 2 cells.
Good luck
Where the variables are missing call the don't care condition. If you are making a truth table for the expression, you don't care if the variables can take both 0 or 1 as per reduce the expression. Or use X (cross) for them
Related
In Python, we break a long line of code into multiple code lines with backslash like this.
a = 5
b = 11
print(str(a) + " plus " + \
str(b) + " is " + \
str(a + b))
# prints "5 plus 11 is 16"
How do we do that in NetLogo?
NetLogo doesn't care about multiple lines except for comments (the comment marker ; only lasts to the end of the line). All of these are the same:
to testme
; single line
let a 25 print a
; command per line
let b 20
print b
; unreadable
let
c
15
print
c
end
I am sorry ton ask this kind of stupid question but I could not find it by myself... I learned perl a while ago and I am a little lost.
I want to convert this kind of output :
Palindromes of: seq1
Sequence length is: 24
Start at position: 1
End at position: 24
Minimum length of Palindromes is: 6
Maximum length of Palindromes is: 12
Maximum gap between elements is: 6
Number of mismatches allowed in Palindrome: 0
Palindromes:
1 aaaaaaaaaaa 11
|||||||||||
24 ttttttttttt 14
Palindromes of: seq2
Sequence length is: 15
Start at position: 1
End at position: 15
Minimum length of Palindromes is: 6
Maximum length of Palindromes is: 12
Maximum gap between elements is: 6
Number of mismatches allowed in Palindrome: 0
Palindromes:
1 aaaaaac 7
|||||||
15 ttttttg 9
Into a gff or bed file :
seq1 1 24
seq2 1 15
I found a perl module to do it : https://metacpan.org/pod/Bio::Tools::GFF
This is my little script :
#!/usr/bin/perl
use strict;
use warnings 'all';
use Bio::Tools::EMBOSS::Palindrome;
use Bio::Tools::GFF;
my $filename = "truc.pal";
# a simple script to turn palindrome output into GFF3
my $parser = Bio::Tools::EMBOSS::Palindrome->new(-file => $filename);
my $out = Bio::Tools::GFF->new(-gff_version => 3,
-file => ">$filename.gff");
while( my $seq = $parser->next_seq ) {
for my $feat ( $seq->get_SeqFeatures ) {
$out->write_feature($feat);
}
}
This is the result :
##gff-version 3
seq1 palindrome similarity 14 24 . - 1 allowed_mismatches=0;end=24;maximum gap=6;maximum_length=12;minimum_length=6;seqlength=24;start=1
seq2 palindrome similarity 9 15 . - 1 allowed_mismatches=0;end=15;maximum gap=6;maximum_length=12;minimum_length=6;seqlength=15;start=1
The issue is : I want to have it the result the start and the end of the palindrome and the specific position in the last line.
Exemple of what I want:
##gff-version 3
seq1 palindrome similarity 1 24 . - 1 mismatches=0;gap_positions=11-14;gap_size=3
seq2 palindrome similarity 1 15 . - 1 mismatches=0;gap_positions=7-9;gap_size=2
Thank you in advance.
I have a %tw date format variable in Stata. I want to generate a monthly week variable. Like in the example below, the variable Date2 has 1999w14 now I want to generate 1999mayw1 in Stata. How can I approach this
Date2 date2
1999w14 1999mayw1
1999w14 1999mayw1
1999w14 1999mayw1
1999w14 1999mayw1
1999w14 1999mayw1
1999w14 1999mayw1
1999w14 1999mayw1
1999w14 1999mayw1
1999w15 1999mayw2
1999w15 1999mayw2
1999w15 1999mayw2
1999w15 1999mayw2
1999w15 1999mayw2
1999w15 1999mayw2
1999w15 1999mayw2
Stata has no concept of the first week in a given month. How could it? Weeks don't map neatly on to months, or even vice versa, unless you are talking about February in non-leap years which has exactly 4 weeks, but starting on different days in different years.
If you have some particular concept of a week, e.g. that it starts on Monday, then tell us what it is.
Stata week 1 always starts on 1 January, 2 on 8 January, and so forth, and week 52 always has either 8 or 9 days. If your data match those definitions, fine. Otherwise you may need to do some reading to work out what matches your problem.
If you issue the command below in Stata, you will get clickable links to .pdf versions.
. search week, sj
Search of official help files, FAQs, Examples, SJs, and STBs
SJ-12-4 dm0065_1 . . . . . Stata tip 111: More on working with weeks, erratum
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
Q4/12 SJ 12(4):765 (no commands)
lists previously omitted key reference
SJ-12-3 dm0065 . . . . . . . . . . Stata tip 111: More on working with weeks
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
Q3/12 SJ 12(3):565--569 (no commands)
discusses how to convert data presented in yearly and weekly
form to daily dates and how to aggregate such data to months
or longer intervals
SJ-10-4 dm0052 . . . . . . . . . . . . . . . . Stata tip 68: Week assumptions
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
Q4/10 SJ 10(4):682--685 (no commands)
tip on Stata's solution for weeks and on how to set up
your own alternatives given different definitions of the
week
That said, if you're content to take your data as Stata weeks, you can convert to months and label as you wish. This script requires that you download labmask from the Stata Journal site (start with search labmask, sj).
clear
set obs 10
gen wdate = yw(1999, _n)
format wdate %tw
list
gen mdate = mofd(dofw(wdate))
format mdate %tm
bysort mdate (wdate) : gen week = _n
gen label = string(mdate, "%tm") + "w" + string(week)
clonevar wdate2 = wdate
* install from Stata Journal site after -search labmask-
labmask wdate2, values(label)
list, sepby(mdate)
+-----------------------------------------------+
| wdate mdate week label wdate2 |
|-----------------------------------------------|
1. | 1999w1 1999m1 1 1999m1w1 1999m1w1 |
2. | 1999w2 1999m1 2 1999m1w2 1999m1w2 |
3. | 1999w3 1999m1 3 1999m1w3 1999m1w3 |
4. | 1999w4 1999m1 4 1999m1w4 1999m1w4 |
5. | 1999w5 1999m1 5 1999m1w5 1999m1w5 |
|-----------------------------------------------|
6. | 1999w6 1999m2 1 1999m2w1 1999m2w1 |
7. | 1999w7 1999m2 2 1999m2w2 1999m2w2 |
8. | 1999w8 1999m2 3 1999m2w3 1999m2w3 |
9. | 1999w9 1999m2 4 1999m2w4 1999m2w4 |
|-----------------------------------------------|
10. | 1999w10 1999m3 1 1999m3w1 1999m3w1 |
+-----------------------------------------------+
I am trying to generate a new variable using the stored result r(mean) from the command sum.
I have a continuous variable 'age'.
So,
sum age
g age0=age–r(mean)
The problem is that this gives the error
unknown function age–r()
r(133);.
Works for me:
. sysuse auto, clear
(1978 Automobile Data)
. su mpg
Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
mpg | 74 21.2973 5.785503 12 41
. gen mpg0 = mpg - r(mean)
. su mpg0
Variable | Obs Mean Std. Dev. Min Max
-------------+---------------------------------------------------------
mpg0 | 74 -4.03e-08 5.785503 -9.297297 19.7027
Watch for strange characters, i.e. that the minus sign really is a hyphen [sic].
I have two files, file1.traj and file2.traj. Both these files contain identical data and the data are arranged in same format in them.
The first line of both files is a comment. At line 7843 of both files there is cartesian coordinate X, Y and Z. And at line 15685
there is another cartesian coordinate X, Y and Z. The number of lines in between two cartesian coordinates are 7841.
What I want to do is copy ONLY the X Y Z coordinates from file1.traj to file2.traj throughout the whole file.
I tried to use paste command but I cant do for specified line alone.
Here i showed the data format in the file. I used the number for clarity purpose.
line.1 trajectory generated by ptraj
line.2 5.844 4.178 7.821 6.423 4.054 8.578 6.606 4.907 6.827 7.557
line.3 4.385 6.722 6.877 6.384 7.283 5.950 6.884 7.565 7.668 6.282
line.2 8.474 7.721 7.127 8.928 7.628 7.205 6.259 8.589 6.712 6.110
line.3 7.712 8.602 6.643 8.151 8.654 7.495 6.940 7.183 4.871 6.108
line.4 7.887 4.864 7.755 7.814 3.754 8.697 7.267 3.724 7.081 7.633
line.5 2.478 6.246 8.089 2.604 8.026 8.853 3.943 6.623 5.754 4.529
.
.
.
. 1.516 41.749 54.260 0.108 41.176 54.536 -0.626 40.627 53.818 -0.303
. 41.920 42.179 3.556 3.251 41.623 3.530 2.472 42.558 2.678 3.304
. 44.723 1.496 5.937 44.339 1.355 6.803 44.866 0.614 5.593 52.401
line.7842 86.323 2.974 52.385 85.816 3.785 51.879 85.808 2.359
line.7843 104.140 159.533 88.303
line.7844 4.792 5.052 8.317 5.279 4.463 8.898 5.663 5.341 7.220 6.267
line.7845 4.438 7.137 6.477 6.566 7.627 5.857 7.407 7.936 7.301 6.170
. 8.741 7.647 7.020 9.023 7.315 7.107 6.475 8.171 6.435 6.413
. 7.823 8.416 6.704 8.208 8.473 7.582 6.560 7.126 5.141 5.816
.
.
.
. 52.050 7.905 42.026 38.561 1.747 39.847 39.375 2.235 39.972 38.634
. 1.382 38.965 0.810 0.477 39.394 0.717 -0.349 39.867 0.222 1.081
. 39.847 43.073 5.033 2.756 43.387 5.428 1.942 42.256 4.598 2.511
line.15683 47.302 4.261 7.071 47.801 4.632 7.799 47.256 4.968 6.428 54.279
line.15684 0.498 3.477 53.964 0.612 2.580 53.500 0.612 4.021
line.15685 104.140 159.533 88.303
line.15686 4.970 4.868 7.979 5.342 4.250 8.612 5.988 5.450 7.184 6.903
line 15687 4.861 7.246 6.381 6.921 7.550 5.526 7.597 7.536 6.953 7.009
.
.
Is there any possibility to use awk or sed?
Using AWK you can do it,i don't think its perfect answer ,but its tricky
sushanth#mymachine:~$ cat file1.txt
104.140 159.533 88.303
5.844 4.178 7.821 6.423 4.054 8.578 6.606 4.907 6.827 7.557
4.385 6.722 6.877 6.384 7.283 5.950 6.884 7.565 7.668 6.282
8.474 7.721 7.127 8.928 7.628 7.205 6.259 8.589 6.712 6.110
104.140 159.533 88.303
7.712 8.602 6.643 8.151 8.654 7.495 6.940 7.183 4.871 6.108
7.887 4.864 7.755 7.814 3.754 8.697 7.267 3.724 7.081 7.633
2.478 6.246 8.089 2.604 8.026 8.853 3.943 6.623 5.754 4.529
here i have used print only lines of 35 characters or longer using awk
sushanth#mymachine:~$ cat file1.txt | awk 'length < 35' > file2.txt
104.140 159.533 88.303
104.140 159.533 88.303