hughesadam_87 54 Junior Poster

The cached property is definatly the best suggestion. If not using that, I would get in the habit of using try: except in these situations. That is syntactially simple and very common, so others reading your code will be able to deduce your intent from the code.

hughesadam_87 54 Junior Poster

I can't really digest the entirety of your code just by looking at it, but another thing you might wanna look into is the polymonial support in numpy. There are some functions, mostly for fitting polynomicals of Nth order to other curves, that might be useful to you. For example:
http://docs.scipy.org/doc/numpy/reference/generated/numpy.poly1d.html

hughesadam_87 54 Junior Poster
outstring=' '.join([str(i) for i in range(0,105,5)])
file.write(outstring)

Also, it's a good habit not to use the word "file" as this is a python reserved file. I'd recommend outfile or just o.

hughesadam_87 54 Junior Poster

If you use numpy, then you want to avoid iterating item by item. In fact, the whole reason to use numpy, is that you don't have to do this. If you do do this, you get no speed increase over plain python (the speed increase is about 1000-fold btw).

You can do linear regression out of the box in python already:

http://glowingpython.blogspot.com/2012/03/linear-regression-with-numpy.html

If you are making your own for a class or something, you still want to avoid itearting over the array itself. It does take some practice to get used to this.

Gribouillis commented: nice help and link +13
hughesadam_87 54 Junior Poster

Can you put all the zipped values into its own list.

allvalues=[zip(ar1.values, br1.values, ar0.values, br0.values), zip(ar2.values, br2.values, ar1.values, br1.values) ... etc]

Then iterate over just this:

for zippedvals in allvalues:
   for w,x,y,z in zippedvals:
        val = (sqrt((w.data**2)+(x.data**2)))-(sqrt((y.data**2)+(z.data**2)))
        files[0].write(('%6.20f\n') % (val))
hughesadam_87 54 Junior Poster

I actually added that while I was waiting for responses. I have the c2o or o2c as choices. cups2ounces or ounces2cups. Is that not needed? I am just new :\

Also you are saying to start with a "if" statement?

I'm saying you define two variables, c2o and o2c and then never use them.

Yes. Your code would literally only change at the bottom:

main()

becomes:

if __name__=='__main__':
    main()

The code should run fine and you won't notice any differences.

hughesadam_87 54 Junior Poster

The error was actually in the textbox, I had posted some numbered, indentied bullets, which was conflicting with the markdown syntax.

Sorry.

Gribouillis commented: This diagnostic may help other members. +13
hughesadam_87 54 Junior Poster

This code was inspired after several discussions on the forum, and I'm especially indebted to PyTony for all of his help with these aspects.

The motivation behind this code is quite simple. I wanted a robust, light and general way of storing CSV data that could be used over and over again and had to have the following properties:

The user sets fields and defaults values, and then field typecasting was automatically employed.
The data is stored in a regular, lightweight type (In this case a mutable namedtuple)
The data is managed by a custom dictionary object.

The MutableNamedTuple class is written by another author (http://code.activestate.com/recipes/500261/) via the factory function "recordtype" and can be used as if it were an official NamedTuple object. Lines 8-137 are this source code, and in practical use cases, one would usually save it in a separate module and import it.

The user merely has to change the stict_fields to whatever datatype is intended to be store. This variable implicitly stores types, so the user does not have to do it. Defaults can also be placed in this variable. Once set, a mutablenamedtuple will be generated, and from that, the program makes a subclass called Record, which is effectively a mutablenamedtuple with extra typchecking.

Record objects then behave similar to named tuples. They are exceedingly easy to interface to file I/O and sqlite modules(http://docs.python.org/library/collections.html#collections.namedtuple_).

The RecordManager class is a custom dictionary that is responsible for storing all Record objects. …

TrustyTony commented: Good effort, even has little too much automagic things +12
hughesadam_87 54 Junior Poster

Hi guys,

I was working with the pandas package and was so impressed with how simple something was that I had to share. Have you ever worked with csv data (in excel for example) and wanted to import the data to python, take either a column average or row average, then plot it? For example, imagine I have data formatted like:

    file1   file2   file3
500 50.0    53.3    43.0
550 23.1    32.0    32.5
600 23.0    23.0    35.0    
700 42.0    31.0    44.0

Pandas is a library for handling ordered series data and is GREAT for managing it. It essentially created containers that act as labeled numpy arrays. If I want to read this data in froma file and take the average along the rows (by slicing through names), and output a plot, it is this simple.

from pandas import read_csv
from matplotlib.pyplot import plt

data=read_csv('filename', sep='\t', header=0, index_col=0)
sliceavg=data.ix[550:700].mean(axis=0)

plt.plot(sliceavge)
plt.show()

Pretty impressive if you ask me.

I thought this was such a simple thing to do that I had to share and give some love to this libary. If you work with series data, start using this asap.

Gribouillis commented: thanks for sharing +13
hughesadam_87 54 Junior Poster

You need to post an attempted effort before anyone will help you with homework.

hughesadam_87 54 Junior Poster

You can really do anything with Python; however, I'd be interested to know what is "the skill"

hughesadam_87 54 Junior Poster

I'm not sure but I'm guessing that something like that would differ for each device, and of course there's the possibility that it may have a domain-specific like language connected to it. I'm intrigued by the idea though. Not to digress but on a semi-related topic I recently came across this http://pyrorobotics.org/

That is interesting. I guess I'm somewhat disheartened to find that out, but it does make sense that a developer would only write system-specific code for a device. One way I can probably do it is that spectrometers can output files in real time. I'm sure I can write a program in python to monitor the output directory, grab the new data files, append them to a large matrix, replot etc...

hughesadam_87 54 Junior Poster

Hi,

That game sounds like a good motivator to get started. I wrote a text-based rock paper scissor game to learn early on.

Your best bet is really not a book, but a good online tutorial. I don't remember the ones I followed; however, this one looks good.

http://docs.python.org/release/2.5.2/tut/tut.html

Read along, slowly, and do every single example you find. Soon you'll understand how to do what you want. Also, since you're interested in games, once you're comfortable with basic operations in python, consider learning how to make graphical user interfaces in tandem. That way, you'll acquire both skill sets; however, keep in mind that GUI's are more difficult to write because they require a good intuition about python structures in general, so don't get frustrated at first.

I'd recommend tkinter as your GUI development toolkit:

http://www.pythonware.com/library/tkinter/introduction/

hughesadam_87 54 Junior Poster

penguin,

One thing you should be careful of when posting in this forum is that not everyone knows the context of your problem. Python is a multi-dimensional language which can be used to do anything from writing letters to solving partial differential equations. As such, when posting, you need to to outline a proper context for your problem and show some effort to have solved it. I don't think most people on this forum are likely to be biologists with the same background as you, so you should do the following:

Post a sample of your data, in this case DNA sequence data.
Explain what it is you are trying to do. In this case, I think many people on this forum will easily understand what an open reading frame is without the biological context.
Third, and probably key, is to demonstrate that you have put in some effort on your own to solve the problem, so that you don't give off the vibe that you want someone else to do the work for you.

You may also consider looking into the BioPython addon, which is a free package for Bio analysis which may already have this feature built in. If not, then post more information here and we can help.

TrustyTony commented: Good balance of expression! Continue same way! +3