Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
salisbury shake
Dec 27, 2011

Pollyanna posted:

Thanks, guys. Yeah, I think I might just go the object route instead. Regex is a loving nightmare and I'll take any alternative to it.

The file is basically a header for the first line (which I remove) and any number of lines of a variable number of characters. It's a text file. As far as I can see there's no case where the total character count is not evenly divisible by 3, so I should be able to just split it up into thirds. That would make it infinitely easier to work with. I'll prolly end up with a long list of codons that I can just iterate over, return the index of the first ATG it finds and the index of the first STOP codon it finds, truncate the list down to that bit, and translate everything from there.

List comprehensions kinda scare me :ohdear:

It's been a while since I've taken a biology course, but can you have multiple start codons between the initial start codon and the stop codon when translating a sequence?

Adbot
ADBOT LOVES YOU

OnceIWasAnOstrich
Jul 22, 2006

You can have as many ATGs are you want between a start codon and as top codon, if they are not the start of translation they are the same as any other non-stop codon. However to detect open reading frames correctly you want to start an overlapping sequence at every ATG.

Using objects for this problem seems like crazy overkill. If you aren't worried about worst-case quadratic time solutions and super-efficiency then all you have to do is iterate through the string (and the reverse complement if you care about that) and check whether s[i:i+3]=='ATG' and when you hit one enter another loop that that iterates through the rest of the string in 3s until you hit a stop codon. Something like that that uses a generator would work without being a giant mess of list comprehenions. This may or may not work, I haven't tested it. It also doesn't automatically check the reverse complement.

Python code:
data = 'AGCCATGTAGCTAACTCAGGTTACATGGGGATGACCCCGCGACTTGGATTAGAGTCTCTTTTGGAATAAGCCTGAATGATCCGAGTAGCATCTCAG'

stop_codons = set(['TAG','TAA','TGA'])

def find_orfs(data):
  for i in xrange(len(data)):
    if data[i:i+3]=='ATG':
        out = data[i:i+3]
        for j in xrange(i+3,len(data)-1,3):
            if not data[j:j+3] in stop_codons:
                out+=data[j:j+3]
            else:
                yield out
                break
If this isn't for homework then you want to be using BioPython because it will handle your FASTA files for you properly, as well as automatically translate things for you.

I have similar feelings about regex, and I expressed them at an informal meeting of a bunch of bioinformatics people and they all thought I was crazy and didn't understand how I could do bioinfo without regex, but jokes on them I already have plenty of papers.

If I really cared about efficiency I might do something like a linear time string matching to find all of the start codons and all of the stop codons and place them into six buckets based on which reading frame they are in and then simply match all start codon indices with the next largest stop codon and extract the sequence from there. Anyone think of a more efficient way to do it than that?

OnceIWasAnOstrich fucked around with this message at 15:22 on Oct 7, 2013

sharktamer
Oct 30, 2011

Shark tamer ridiculous
I've got a slightly strange problem here. It would probably require an extremely over-engineered solution, but maybe someone knows of a way I can do this without too much effort.

I'm writing a module for the willie irc bot that will basically make a pun out of certain things people say. For example:

quote:

<sharktamer> I'm doing well today.
<MrSpence> More like I'm doing SMELL today.

but a lot less PC.

It's a dumb idea, I'm just having fun with making the bot do stuff. At the moment I'm doing it using regex on the "[^aeiou ]ell" in the case above. However, English is weird and words that are spelled the same don't always rhyme and vice-a-verse-a.

Maybe someone has ideas for how I can make this more powerful?

SurgicalOntologist
Jun 17, 2004

SurgicalOntologist posted:

Are there any free, preferably open-source libraries similar to the proprietary Vizard? It's a virtual reality library, where you can (e.g.) create objects from 3D models, then link a camera object to an external input (e.g., motion tracker) to let the user explore a virtual space. It's very simple to use, but also very expensive (I'd be looking at $4k for a single-use academic license).

Asking again... anyone? Even something that accomplishes part of this would be helpful (at least in terms of getting a sense of feasibility).

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

sharktamer posted:

I've got a slightly strange problem here. It would probably require an extremely over-engineered solution, but maybe someone knows of a way I can do this without too much effort.

I'm writing a module for the willie irc bot that will basically make a pun out of certain things people say. For example:


but a lot less PC.

It's a dumb idea, I'm just having fun with making the bot do stuff. At the moment I'm doing it using regex on the "[^aeiou ]ell" in the case above. However, English is weird and words that are spelled the same don't always rhyme and vice-a-verse-a.

Maybe someone has ideas for how I can make this more powerful?

Use a phonetic dictionary to compare how poo poo is actually pronounced. Here's one: http://www.speech.cs.cmu.edu/cgi-bin/cmudict

fritz
Jul 26, 2003

OnceIWasAnOstrich posted:

If you aren't worried about worst-case quadratic time solutions and super-efficiency

Isn't that going to come back to bite you when your data starts to get big? (and I assume the data will, given y'all got sequences)

Red Mike
Jul 11, 2011
Apparently PyCharm now has a (free) community version out for 3.0. Lacks a bunch of features, but still might be useful. Here's a comparison table.

I still have my open-source license for 2.7, so I'll probably keep using that for a while, and it looks like there still is an open-source license deal for professional.

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug

Red Mike posted:

I still have my open-source license for 2.7, so I'll probably keep using that for a while, and it looks like there still is an open-source license deal for professional.

Most things that JetBrains makes (not IntelliJ) have licenses that "expire" instead of being locked to a major product version. I use the term "expire" loosely -- software that you're using will never stop working but you can't use new versions that are released after your license's "entitled to free upgrades/updates" cutoff.

If you view your license details in PyCharm (Help -> About) and your upgrade entitlement includes 3.0's release date of 2013-09-24, you can use your 2.7 license for 3.0 also.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Lysidas posted:

Most things that JetBrains makes (not IntelliJ) have licenses that "expire" instead of being locked to a major product version. I use the term "expire" loosely -- software that you're using will never stop working but you can't use new versions that are released after your license's "entitled to free upgrades/updates" cutoff.

If you view your license details in PyCharm (Help -> About) and your upgrade entitlement includes 3.0's release date of 2013-09-24, you can use your 2.7 license for 3.0 also.

Their promo last year where you could get PyCharm professional for $25 because the Mayan end of the world was coming was a great plan on their part.

I'll get 3.0, but my license expires in December, and there's no way I'll go back to not using PyCharm, so I'll have to be stuck on a version thats slowly getting older or pony up for another license at full price.

Unless someone else predicts the end of the world soon.

the
Jul 18, 2004

by Cowcaster
Let's say I have a series of objects that are labeled point1, point2, point 3, etc...

I want to do something like:

Python code:
for i in range(0,16,1):
    point[i] = blah blah blah
But I can't do that, since that refers to the ith part in point. I'm trying to refer to each point1, point2, point3 while I cycle through the for loop. Anyone?

Nippashish
Nov 2, 2005

Let me see you dance!

the posted:

I'm trying to refer to each point1, point2, point3 while I cycle through the for loop. Anyone?

Please avoid wanting to do that.

good jovi
Dec 11, 2000

the posted:

But I can't do that, since that refers to the ith part in point. I'm trying to refer to each point1, point2, point3 while I cycle through the for loop. Anyone?

This is a sign that you should be storing your data differently. Consider storing the points inside an array called "points" so that points[i] is the point you want.

Dren
Jan 5, 2001

Pillbug
must resist evil urge to tell him how to do it

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
Even having the urge to say it makes you a bad person.

Again, the, keep your points in a list.

QuarkJets
Sep 8, 2008

Thermopyle posted:

Their promo last year where you could get PyCharm professional for $25 because the Mayan end of the world was coming was a great plan on their part.

I'll get 3.0, but my license expires in December, and there's no way I'll go back to not using PyCharm, so I'll have to be stuck on a version thats slowly getting older or pony up for another license at full price.

Unless someone else predicts the end of the world soon.

I'm still having trouble getting motivated to try PyCharm simply because there aren't any open source projects that I'm particularly interested in contributing to. Anyone have any good suggestions?

Dominoes
Sep 20, 2007

the posted:

Let's say I have a series of objects that are labeled point1, point2, point 3, etc...

I want to do something like:

Python code:
for i in range(0,16,1):
    point[i] = blah blah blah
But I can't do that, since that refers to the ith part in point. I'm trying to refer to each point1, point2, point3 while I cycle through the for loop. Anyone?
What does blah blah blah do, and what do the points look like?

QuarkJets posted:

I'm still having trouble getting motivated to try PyCharm simply because there aren't any open source projects that I'm particularly interested in contributing to. Anyone have any good suggestions?
cx_freeze!

Dominoes fucked around with this message at 20:53 on Oct 8, 2013

the
Jul 18, 2004

by Cowcaster
To answer everyone, the overall problem has me tracking 16 molecules in a large grid.

Currently, each molecule has it's own array that spans 2 columns (x and y coordinates) and each row being it's position at a certain time.

I want to write a script that "creates" all 16 molecules evenly spaced in a large grid. I already have the coordinates created, but currently I have something gross:

Python code:
boxsize = 10.
boxdiv = (10-10*0.1)/2
x = numpy.linspace(-boxdiv,boxdiv,16)
y = numpy.linspace(-boxdiv,boxdiv,16)
dt = 0.1
time = 4

ttime = numpy.arange(0,time+0.00001,dt)
point1 = numpy.zeros((ttime.size,2))
point1[0,0] = x[0]
point1[0,1] = y[0]
What that does right now is create zeroes for all of the possible time steps for point1, and also specify what it's starting time position is, being the zeroth row in point1. point2 would be at x[0]y[1], point3 at x[0]y[2], etc. So I need to do it for all 16 points.

Later, I run a loop over the entire time, and I should end up with an array for point1 that has 2 columns, it's coordinates, and rows for the entire time ran for.

the fucked around with this message at 23:35 on Oct 8, 2013

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug
So what's wrong with

Python code:
points = []
boxsize = 10.0
boxdiv = (10 - 10 * 0.1) / 2
x = numpy.linspace(-boxdiv, boxdiv, 16)
y = numpy.linspace(-boxdiv, boxdiv, 16)
dt = 0.1
time = 4

ttime = numpy.arange(0,time+0.00001,dt)
for i in range(16):  
    point = numpy.zeros((ttime.size,2))
    point[0, 0] = x[i]
    point[0, 1] = y[i]
    points.append(point)
?

Your point1 is now points[0] and so on.

(maybe stealth) EDIT: the possessive form is "its", not "it's" goddamnit

the
Jul 18, 2004

by Cowcaster

Lysidas posted:

So what's wrong with


?

Your point1 is now points[0] and so on.

(maybe stealth) EDIT: the possessive form is "its", not "it's" goddamnit

So is that basically making a "3-D" array? I was thinking of trying to do something like that, but I can't really wrap my head around it. But, yeah.

Optimally I guess I'd want to do the largest array being the collection of all points, the second level being each point, and for each point I'd have a 400x2 or whatever array of the coordinate point as it changes over time.

edit: So if I do this, how do I refer to specific array positions within each one?

points[1] gives me the second point, but how do I refer to the second time position within that point?

the fucked around with this message at 00:18 on Oct 9, 2013

Ashex
Jun 25, 2007

These pipes are cleeeean!!!
I'm refactoring a python script I wrote earlier this year for work. In a nutshell, it's a bunch of functions that install stuff that are called at the bottom using try/catch.

I discovered today that when an error is thrown it will be passed to catch but for some reason it tries to loop back through try again.

Anyone know what's going on? I'm executing commands using subprocess.check_call and when it throws an exception the script exits as expected. It's other things like a access denied error when trying to write a file or an invalid url being used with urlib2 that cause it to loop back through try.

Ashex fucked around with this message at 02:17 on Oct 9, 2013

Dominoes
Sep 20, 2007

Ashex posted:

I'm refactoring a python script I wrote earlier this year for work. In a nutshell, it's a bunch of functions that install stuff that are called at the bottom using try/catch.

I discovered today that when an error it thrown it will be passed to catch but for some reason it tries to loop back through try again.

Anyone know what's going on? I'm executing commands using subprocess.check_call and when it throws an exception the script exits as expected. It's other things like a access denied error when trying to write a file or an invalid url being used with urlib2 that cause it to loop back through try.
Post code.

Ashex
Jun 25, 2007

These pipes are cleeeean!!!
Alright, here's an example with just one function being used. In this case it's when creating the directory, didn't add anything to check if it exists so an error is thrown if it's there as expected.

code:
logging.basicConfig(level=logging.DEBUG,filename=workdir + '\\stack_deploy.log',format='%(asctime)s %(levelname)s %(message)s')

def buildpropads():
    prop = []
    for section_name in parser.sections():
        if 'adsproperties' in section_name:
            for name, value in parser.items(section_name):
                config = '%s=%s' % (name, value)
                prop.append(config)
            break
    propfile = '\n'.join(prop)
    return propfile

def adsinstall():
    adsoptions = dict(parser.items('adsoptions'))
    sourcedir = os.path.join(spotroot, adsoptions['sourcedir'])
    filedir = os.path.join(workdir, adsoptions['sourcedir'])
    os.makedirs(filedir)
    os.chdir(filedir)
    copy2dir(os.path.join(sourcedir, 'install64.exe'), filedir)
    sourcefile = os.path.join(filedir, 'install64.exe')
    prop = buildpropads()
    f = open("ads_properties.txt", "w")
    f.write(prop)
    f.close()
    logging.debug(('"' + sourcefile + '" -f "' + os.path.join(filedir, '\ads_properties.txt"')))
    subprocess.check_call('"' + sourcefile + '" -f "' + os.path.join(filedir, '\ads_properties.txt"'))


try: 
    logging.info("Installing Advanced Data Services")
    adsinstall()
except:
    logging.error("An error occurred!\n")
    logging.exception('')
    sys.exit(1)
Edit: This may not be the script after all, I'm build testing with vagrant so I'm executing this via a batch script. When the script runs successfully it loops when called through batch, if I run it directly in the VM then everything is cake.

Ashex fucked around with this message at 04:01 on Oct 9, 2013

loose-fish
Apr 1, 2005
Regarding GUIs:

It's really sad that GTK3 isn't more portable because I quite like working with PyGObject under Linux.

I haven't done too much with QT, but it seemed a bit more complicated to get a simple GUI running.
What do you guys like about QT (portability and native look are very nice of course) and how do you usually design your GUIs (code vs. designer)?

I don't really like Glade, I can never get things arranged quite right and I like using custom (derived) widgets...

Also: gently caress TkInter!

Bloodborne
Sep 24, 2008

Just getting into learning, right now going through the Learn Python the Hard Way course.

My question right now is for the first language beginners, what was your first project in Python? Did you have a goal in mind for something you wanted to accomplish?

QuarkJets
Sep 8, 2008

Dominoes posted:

What does blah blah blah do, and what do the points look like?

cx_freeze!

That sounds less like a Python project and more like a configuration management nightmare with some Python development on the side

evilentity
Jun 25, 2010

Goonicus posted:

Just getting into learning, right now going through the Learn Python the Hard Way course.

My question right now is for the first language beginners, what was your first project in Python? Did you have a goal in mind for something you wanted to accomplish?

When i started learning python 2 years ago, ive wrote pretty big gui application for company i work for. That was a huge mistake. Wayyy too complicated for first project. Im refactoring it now :v:

Your best bet is to try to fix an itch of yours. Automate some mundane task, create a blog. Something reasonably complex, but not too much. Go nuts and learn.

Dominoes
Sep 20, 2007

loose-fish posted:

I haven't done too much with QT, but it seemed a bit more complicated to get a simple GUI running.
What do you guys like about QT (portability and native look are very nice of course) and how do you usually design your GUIs (code vs. designer)?
QT was PITA to learn, mostly due to the lack of good Python tutorials for it. I stumbled through it through a mix of pulling what I could from antiquated tutorials, and asking questions here and on stack overflow. I didn't realized it at the time, but a great starting point is the examples folder in your PYQT/Pyside(?) directory. Look through those, and look up things you don't understand in the official QT docs. The docs describe the basic purpose of each widget or tool, and what they can do. I found them confusing initially. Once you figure out the basics, and understand how to convert from the C examples, the docs are great. I think the most confusing thing for me was code layout, and OOP. The PyQt docs seemed kinda useless.

Designer vs code... it's technique. Try both and figure out what you like about each. I use designer for laying out complex windows, and code simple ones. Designer makes experimenting with layouts quick and easy, and keeps your GUI code separate. There are many things you can't do (or can't do without configuring) in Designer, so your GUI will often be split between the file Designer made and your own code that interacts with it.

I love QT, after getting comfortable with it. It's easy and fast to make GUI with. Designer's great. It has useful tools outside the GUI, like its own threading system, and timers. I don't like how packaging binaries with it requires large libraries, causing simple programs to take up 30mb+.

Has anyone found a use for the Signal/Slot editor in Designer?

Goonicus posted:

Just getting into learning, right now going through the Learn Python the Hard Way course.

My question right now is for the first language beginners, what was your first project in Python? Did you have a goal in mind for something you wanted to accomplish?
My first project was an automated stock screener/portfolio management tool/algorithmic trader. It started out short and basic, but evolved in a somewhat complex, multi-module project.

Dominoes fucked around with this message at 14:46 on Oct 9, 2013

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

loose-fish posted:

Regarding GUIs:

It's really sad that GTK3 isn't more portable because I quite like working with PyGObject under Linux.

Yeah, it's quite unfortunate. Due to the way our toolchain works, it's really hard to actually build GTK+ on Windows with introspection support.

loose-fish posted:

I don't really like Glade, I can never get things arranged quite right and I like using custom (derived) widgets...

I don't know anybody who likes glade. That said, the GTK+ APIs are hard to make it easy to integrate custom widgets into an editor like that. Part of what we landed this cycle to help them out is composite widget templates, which is a super easy way to say "this widget is a combination of these other widgets".

There's also now a small, dedicated team on Glade, and they're fixing it up quite nicely.

tef
May 30, 2004

-> some l-system crap ->

Goonicus posted:

Just getting into learning, right now going through the Learn Python the Hard Way course.

My question right now is for the first language beginners, what was your first project in Python? Did you have a goal in mind for something you wanted to accomplish?

I was in a third year university course, on a large project, working with someone who hadn't been majoring in computer science. So instead of Java, I picked python. My first project was a machine translation algorithm from german to english.

the
Jul 18, 2004

by Cowcaster
I'm trying to make a series of loops that assigns something like this:

0 - 0,0
1 - 0,1
2 - 0,2
3 - 0,3
4 - 1,0
5 - 1,1
6 - 1,2
7 - 1,3
8 - 2,0
9 - 2,1
10 - 2,2
11 - 2,3
12 - 3,0
13 - 3,1
14 - 3,2
15 - 3,3

Where I loop through an array 16, and I have two size 4 arrays that I need to assign the values from them as above.

I had something like:
code:
for i in (0,16,1):
   for j in (0,4,1):
      for k in (0,4,1):
But that ends up assigning the last value of j and k to each i.

Telarra
Oct 9, 2012

Might not be useful for you in the general case, but I'll just point out that for the example values you've given, j == i // 4, and k == i % 4.

the
Jul 18, 2004

by Cowcaster

Moddington posted:

Might not be useful for you in the general case, but I'll just point out that for the example values you've given, j == i // 4, and k == i % 4.

Is this a "mod" thing? Someone has tried to explain that to me before, but I have difficulty understanding it.

Tavistock
Oct 30, 2010



Try using these itertools.permutations() and "for x, y in enumerate(???):". Just play around in a console with those and you'll figure out how to do what you want.

the
Jul 18, 2004

by Cowcaster
Update: This works:

Python code:
boxsize = 10.
boxdiv = (10-10*0.1)/2
num = 16
snum = numpy.int(numpy.sqrt(num))
x = numpy.linspace(-boxdiv,boxdiv,snum)
y = numpy.linspace(-boxdiv,boxdiv,snum)
dt = 0.1
time = 4
ttime = numpy.arange(0,time+0.00001,dt)

p = numpy.zeros((num,ttime.size,2))

for i in range(0,snum,1):
    for j in range(0,snum,1):
        p[(i+j*snum),0,0] = x[i]
        p[(i+j*snum),0,1] = y[j]

loose-fish
Apr 1, 2005

Suspicious Dish posted:

I don't know anybody who likes glade. That said, the GTK+ APIs are hard to make it easy to integrate custom widgets into an editor like that. Part of what we landed this cycle to help them out is composite widget templates, which is a super easy way to say "this widget is a combination of these other widgets".

That sounds neat, I'm gonna try that the next time I futz around with GUI stuff.

SurgicalOntologist
Jun 17, 2004

Moddington posted:

Might not be useful for you in the general case, but I'll just point out that for the example values you've given, j == i // 4, and k == i % 4.

Cool I didn't know about the // operator, what's it called?

Dominoes
Sep 20, 2007

SurgicalOntologist posted:

Cool I didn't know about the // operator, what's it called?
Floor division.

Kumquat
Oct 8, 2010

SurgicalOntologist posted:

Cool I didn't know about the // operator, what's it called?

Floor Division

Telarra
Oct 9, 2012

the posted:

Is this a "mod" thing? Someone has tried to explain that to me before, but I have difficulty understanding it.

The % operator? Yeah, it's called the 'modulus' or 'mod' operator, and it's one of the two operators for integer division: floor division gives you the quotient, and modulus gives you the remainder.

Telarra fucked around with this message at 21:27 on Oct 9, 2013

Adbot
ADBOT LOVES YOU

Bloodborne
Sep 24, 2008

evilentity posted:

Automate some mundane task, create a blog. Something reasonably complex, but not too much. Go nuts and learn.

Yep, this is what I was thinking. Maybe something Active Directory or Exchange based? I'm not even sure how powerful Python is to be honest.

  • Locked thread