Archive for January, 2010
Python Crash Course — 4/5ths done!
This week is going to be crowded enough for me that I’m going to cancel this week’s class. On the bright side, the classes have gone better than I thought it would. We will continue on February 9th.
The very first class ended up being too short, with the advanced students feeling that it moved too slowly. The second and third classes ended up being just the right speed– with the exception that the example fill-in-the-blank script from the third class was too difficult.
The difficulty rose when I too quickly introduced dictionaries whose values are lists.
The fourth class held last week was excellent– I completely ditched slides that week and produced five fill-in-the-blank scripts that were just the right tempo for everyone. I had a good mix of BIC (Bioinformatics Club), iGEM and chemistry graduate students– all who attended got something out of the hour which was my objective.
We only had time for four out of the five scripts with the remaining script as a bonus that everyone could take home and try.
Now, it’s back to Structural Bioinformatics homework… It’s quite a daunting assignment to be true (having just formally shaken hands with Singular Value Decomposition), but the parts that are Python (particularly the bonus question) are familiar enough for comfort.
Update: General Anesthesia – Risk for Women, Canada.
This is a more balanced article about the issue found in The Hamilton Spectator.
“Disclosure of pelvic exams in question” (Joanna Frketich); found at the following address.
http://www.thespec.com/News/Local/article/714924
Summary, origin of the phenomenon, contrasts with previously posted article:
- A study was published (found here, “Education” — http://www.sogc.org/jogc/currentissue_e.aspx – accessed Jan 2010)
- Pelvic exams are integral to some surgeries, part of determining proper treatment
- A pelvic exam is performed three times, once by each a doctor, a resident, a medical student
- Contrast to Mr. Picard’s article posted previously indicating a ‘parade’ of students
- The actual problem is whether or not the single student on the team has been given direct consent
- Whereas what is thought of as implied is that the team is given consent as a whole (opinions, practices will change)
- Article goes on to indicate that this consent for each individual should be (will become) the norm
Thoughts, Conclusion:
Med students should be taught to practice — My feeling is that communication is the primary problem: the ratio of women polled that were asked explicit consent for medical students to perform the pelvic exam should have been greater.
The latter article by Frketich revisits the problem but discusses it far more calmly (so as to not break the brains of her readers). It even cites several women healthcare professionals for the inside scoop– something we didn’t get with the former article. We end up with a picture that states what we have always taken for granted in Canada– that when a problem is discovered, it is fixed– in this case, it’s communication between healthcare professionals and patients.
As mentioned in my previous post– it is an object of pride that Canada has excellent healthcare– which is the reason for the dismay, my personal dismay at even the subtle hint let alone a full blown implication of “something this wrong” with the system. If you become a surgery patient at any point, keep informed and ask the right questions: “Who’s going to be operating on me?”, “Who’s going to do the pelvic examination?”. This is the solution that taps the original problem stated: that women just didn’t know what happened for lack of communication.
Notes:
- Former article by Andre Picard titled “Time to end pelvic exams done without consent” found in the following.
- http://www.theglobeandmail.com/life/health/time-to-end-pelvic-exams-done-without-consent/article1447337/
BCC’d to the same individuals contacted yesterday.
[...] Ed’s Blog … other posts by KittyCATBear [...]
General Anesthesia – Risk for Women, Canada.
Update: Please see this post written the next day after looking into the matter a bit more. It’s unfortunate that the article in The Globe and Mail below had such an alarmist slant to it.
Update: Continuing to research issue– see a list of teaching hospitals in Canada: http://www.caho-hospitals.com/member_hospitals.aspx — I need to find out more: Is it true? How widespread is the problem; etc.
Sent from me to many friends via e-mail with BCC earlier today.
Hi All,
This story is deeply disturbing. Women who are under general
anesthetic in hospital recovery rooms can be subject to routine
examination by med students without consent in Canada. This is a
strict violation of everything a scientist would believe with respect
to human health and dignity.Please have a look and figure out if what action you’d like to take.
Spreading the word, figuring out who knows what and the extent of the
problem are good steps (self-education, personal preventative measures
etc.).Conversely, if you can verify that this is a myth– that can also be
good (puts minds at ease).At the very least, bringing up a petition or a stronger public
presence of the problem are both possible.Thanks,
Eddie Ma
Generic Functions in C# and Java
>>> Attached: ( Main.java — in Java | Main.cs — in C# ) <<<
Updated: (1) Made code more readable. (2) Removed unnecessary package (Java) and namespace (C#) and added a function that returns a generic type as well. (3) Attached compilable demo source code in separate files.
The most fun and productive concept in object oriented programming is generics — for me anyway. In C, one could deploy generics hazardously with code that casts the contents of memory addresses with a putative struct. The first field gives away what that chunk of memory is supposed to be at run time (usually, it’s a typdef int or an enum). I still do that when it’s called for, but it’s quite delicate and often leads to insidious bugs that don’t crash immediately. At least one would know what code to suspect when crashes do happen.
In C# and Java, two languages that derive from C — we find full safe support of generics. Generic classes (the things that collections are made of) are interesting, and I’m sure most who have used either of these languages have already played with them and have found them useful. One of the things that don’t receive a healthy dose of spotlight is Generic Functions (“Generic Methods” if you like).
I’ll compare two segments of code, one in C# and one in Java that do exactly the same thing — demonstrate two trivial functions printArrayList() and getElement(). The function printArrayList() prints out the contents of an ArrayList (Java) or a List (C#). The function getElement() retrieves an element from a list. This shows how single generic functions can operate on collections, each with a different defined type without the need for unsafe casting. The only assumption the code makes is that each object in a list implements the toString() method (needed for the printing function).
Note naming convention: In Java, methods are just members of an object, so they are named in lowercase. In C#, methods are capitalized. We will refer to methods by the Java convention here to keep things consistent.
Setting Up in Main…
Let’s declare and fill a few lists for this demonstration. Three generic list objects, cow, dog and elephant are constructed in a for loop. Each gets ten elements. Each list contains objects of a particular type; cow contains integers, dog contains doubles and elephant contains strings.
| Java Code | C# Code |
ArrayList<Integer> cow = new ArrayList(); ArrayList<Double> dog = new ArrayList(); ArrayList<String> elephant = new ArrayList(); |
List<int> cow = new List(); List<double> dog = new List(); List<string> elephant = new List(); |
Notice that Java does not autobox the type in the angel brackets so you can’t give it the primitives int and double. In C#, this is allowed plus string is also a primitive. Remember: In both Java and C#, primitives are emulated — they are first class objects that are only different from other objects in that they are pass-by-value rather than pass-by-reference.
Appending ten items to each list. Shown below is the Java version — in C#, change “add()” to “Add()”.
for(int i = 0; i < 10; i ++) {
cow.add(3 * i);
dog.add(0.25 * i);
if(i % 2 == 0)
elephant.add("Even");
else
elephant.add("Odd");
}
The below is the code we want to make work — We’ll call printArrayList() to print out all of the elements in each list, then we’ll call getElement() to return a specific element from each list. Notice that this is the Java version below — in C#, we capitalize method names and use Console.Writeline() instead of System.out.println().
System.out.println("== Generic List Printer ==");
printArrayList(cow);
printArrayList(dog);
printArrayList(elephant);
System.out.println();
System.out.println("== Generic Element Accessing ==");
int cow_at_7 = getElement(cow, 7);
double dog_at_2 = getElement(dog, 2);
String elephant_at_4 = getElement(elephant, 4);
System.out.println("Cow at 7 = " + cow_at_7);
System.out.println("Dog at 2 = " + dog_at_2);
System.out.println("Elephant at 4 = " + elephant_at_4);
Note that in C#, we may use the keyword “var” instead of typing out the types for cow_at_7, dog_at_2, and elephant_at_4 — the compiler infers the type for us. This is different from unsafely casting with “Object”, as the compiler infers the narrowest possible type and substitutes in that correct type.
Onto the methods …
Below is the Java version of printArrayList().
static <A> void printArrayList(ArrayList<A> animalList) {
for(A a : animalList)
System.out.print(a + "\t");
System.out.println();
}
Below is the C# version of PrintArrayList().
static void PrintArrayList<A>(List<A> animalList) {
foreach(A a in animalList)
Console.Write(a + "\t");
Console.WriteLine();
}
Notice that printArrayList() is a method that specifies a generic type <A>, but only in its argument list. In Java, <A> appears before the function’s type and in C#, this appears after the function name. In this case, it’s obvious what we would do if we have functions that return specific types — we just substitute the type where the keyword “void” is. So what happens when we want to return the generic type? That’s what getElement() will demonstrate.
Below is the Java version of getElement().
static <A> A getElement(ArrayList<A> what, int which) {
return what.get(which);
Below is the C# version of GetElement().
static A GetElement<A>(List<A> what, int which) {
return what[which];
Yes, these are both trivial functions, as you could have easily called ArrayList.get() in Java and List[] in C# respectively — but it does the job in this demonstration. In the Java version, the generic type <A> is placed before the type of the function, A. Don’t let that confuse you, just recall how we specified the return type when it wasn’t the generic type. In C#, we place the generic type <A> after the function name just as before.
Below is the output you should expect if you run the main function.
C# Output
== Generic List Printer == 0 3 6 9 12 15 18 21 24 27 0 0.25 0.5 0.75 1 1.25 1.5 1.75 2 2.25 Even Odd Even Odd Even Odd Even Odd Even Odd == Generic Element Accessing == Cow at 7 = 21 Dog at 2 = 0.5 Elephant at 4 = Even
The Java output is the same, except the values that are doubles are always printed with a trailing “.0″ even if it is numerically equal to an integer.
First UWiGEM modeling meeting: Wed. Jan. 21 @6pm
Update: The Gleave Library, B1-273 has been booked for this occasion!
Brief: The two software projects that will precede the main body of Waterloo iGEM 2010 will be discussed on Wednesday January 21 from 6pm to 8pm. I will update this post once a room booking has been confirmed.
Related topic here on the Waterloo iGEM Discussion Board.
Fight e-mail address typos with MD5 hashes :P
Silly: One day, Dave messaged me and said that his e-mails weren’t getting through to me. I was puzzled as he was using the g-talk service, meaning he has my valid g-mail handle. As it turns out, the device he was on didn’t have copy and paste available for that field, and he simply couldn’t see the ‘t’ in my address.
Incidentally, that’s one dysfunction of the human visual system I’d like to purge– reading something over and over, only to make exactly the same lexicographical mistake each time. It’s an evil broken heuristic… remember kids, it’s a ‘feature’, not a ‘bug’.
I then messaged him the MD5 hash of my e-mail address along with the one for the incorrect address…
Correct: 2f776881db0ca037c145e74a6c41721c Incorrect: 35c56bee61e9914929f4a3242d44c339
Don’t worry, there’s no practical value in doing this
Note: to get the MD5 of an arbitrary string on a *nix system, just type this in the terminal…
echo "arbitrary string" | MD5
It almost amuses me as much as catting arbitrary binary files…
Ed's Big Plans