Friday, August 5, 2016

Data File Entries into Empty Lists

Hello All,

I have what I hope will be a simple question.
I have a text file that has a list of sample names, one per line as below:

STX2
XXX3
DXM4
etc....

I can read the file into a list:

file = open(str(filepath) + '/SampleNames.txt')
lines = file.readlines()

querylist = []
linenumber = 0

for i in lines:
    linenumber = linenumber + 1
    querylist.append(lines[linenumber - 1])

   

So I now have a list : querylist['STX2n\', 'XXX3n\', 'DXM4n\', etc....]

I need to be able to convert each item in the list into a new, standalone, empty list. Something that would appear like below once finalized:

STX2 = []
XXX3 = []
DXM4 = []

Try as I might, I've been unable to come up with a simple solution.  There is surely a function or command I don't know about that will accomplish this, as it seems pretty straight forward...

Thanks in advance for any help,

Josh Peek

**********************************************************************************
EDIT:  8/12/16

I've found what appears to be a simple solution, seen below:

for item in querylist:
   exec((item) + (' = []'))


The function exec() executes string input as python code.  So as of now, I am pulling each item in the querylist[] into the exec() function as a string and executing it.  This builds each list as I wanted.  I don't know if this is proper or not, but it seems to be working well...










Monday, August 1, 2016

Friday, July 15, 2016

I am back!

(really good to be back!)

We will meet (as usual) at HudsonAlpha - 9 am - Tuesday July 19

1) Come with questions or
2) post questions/suggestions or
3) ideas or
4) - ?

Thursday, July 7, 2016

Data Filter Help

I am trying to find a script to filter through .csv files and output data that specifically matches 645 patient numbers out of 1612 total patients.

The output can be placed into a .csv file format as well.

I was able to find a number of scripts that kind of do this but not exactly.


Tuesday, June 28, 2016

Copy and paste a file from one location to another

I am trying to copy a file (that contains various contexts) from one area and paste it in another area.

I am using the cp command --> cp  /source.of.file /destination.of.file

The operator keeps responded omitting the /source.of.file  

OR

The operator responds the /source.of.file is not a directory (however when I cd to the /source.of.file it takes me right to the correct directory.

(Additional Information: I am in a node under cluster on command line.)

Saturday, June 25, 2016

Future Meetings (please note!)

I am away June 28, July 5 and July 12 ...!

But will monitor this blog and help best way I can


Wednesday, June 22, 2016

Elizabeth Andrew's code for reading molecular coordinates from a file

#!/usr/bin/python

import sys
from pybel import *


mol = readfile("g09", "stauranthine_GC_dimer_xyz_1.out").next()

atomtotal = 0
for mol in readfile("g09", "stauranthine_GC_dimer_xyz_1.out"):
atomtotal += len(mol.atoms)


atom_number = { 1 : 'H',
6 : 'C',
7 : 'N',
8 : 'O'
}

for atom in mol:

x = atom.coords[0]
y = atom.coords[1]
z = atom.coords[2]
print atom_number[atom.atomicnum]+'\t'+str(x)+'\t'+str(y)+'\t'+str(z)

#I am having trouble getting the xyz coordinates to form right aligned even columns. Some of the coordinates have negative signs which causes the misalignment. 

Monday, June 20, 2016

All in one packages (the good, the bad, the ugly)

I remember providing instructions on installing "all in one" packages for Windows systems - like anaconda, canopy and so on -

1) The good - well, they are all in one - so no need to look around for packages to install - you have everything you need in one grand package
2) The bad - sometimes, a package in that all in one may be buggy - and you may want to use an older version (or a newer version) - well, I am sure you can install any version of any package - but it may not be that easy (!) ... I discovered for example that the latest/greatest openpyxl package (functions to read/write xlsx files) has some bugs - and I discovered (accidentally) that 1.6.2 worked as I wanted to (and not the 2.x.x versions)
3) The ugly - often you may not know in any all in one package as to where the problem is - so if you install package by package you can debug easily


Thursday, June 16, 2016

How to do X? (add your own please!)

Here is a list of "X" (please add your own) (I would be happy to share my solutions/explain them)

1) Read a data file (containing rows and columns)
2) Plot one column of data against another column of data
3) plot data from one row against another row
4) Do a linear least squares fit (e.g. Y versus X) - calculate slope, intercept
5) Do a polynomial fit (Y versus X) (plot the data)
6) Read a protein (or DNA/RNA) sequence (from a data file in fasta OR genbank or ... formats)
7) Get information about a protein (or DNA/RNA) sequence (length of sequence, C+G, etc)
8) Read/write excel file (as xlsx, csv, txt)na
9) Solve vapor/liquid equilibrium problems (Antoine's equation, Raoult's law ...)
10) Solve set of linear equations (AX = B)
11) Solve non linear equations
12) Calculate volume roots of cubic equations of state
13) Set up and solve problems in enzyme kinetics (set of ordinary differential equations, Michaelis Menten form, etc)
14) Solve problems involving filtration (Darcy's Law)

And now for some "X"'s I have a very limited experience with/written software for

15) Read an image (tiff, jpg, png) - and run filters (low pass, high pass, band pass)
16) Locate spots on an image (microarray analysis of tiff images - locate center of spot, determine background intensities)
16) BLAST sequences at the NCBI - parse output according to defined criteria
17) Align two sequences using dynamic programming techniques (SmithWaterman (local) and Needleman Wunsch (global)




Wednesday, June 15, 2016

Beginner- Questions about a code

I am trying to make a program that asks questions and allows the user to answer them. When I try to use raw_input it gives me an error. Can anyone tell me what I am doing wrong?

name = raw_input("What is your name?")
color = raw_input("What is your favorite color?")

print = ("So your name is %s and your favorite color is %s." % (name, color))

I would like for it to allow the user to enter their name and favorite color and the output include the sentence with the information.

I have read online that raw_input might not work anymore but input did not allow me to answer to questions.



June 14, 2016 (What we did) (sort of did)

I was glad to see many pythonistas - welcome.

Reminder - come with/post problems, questions - "How do do X" or "Y" in python

My objective is not to "formally" teach python - but help you help yourself with python - and sure, I (and many others) can help you get to a point where you are comfortable with writing python scripts

(if you are reading this, post on what you heard/what you would like to hear/learn)


Monday, June 13, 2016

Tuesday June 14 2016 (Change of Venue)

Just a reminder

Tomorrow (June 14, 2016) we meet in the

auditorium at the

HudsonAlpha Institute for Biotechnology

http://hudsonalpha.org/directions

(Just come on in - sign in at the desk/as guest (if you do not see anyone, just
go to the auditorium)

Friday, June 10, 2016

Friday, June 3, 2016

Atomic Matrix 1: Letters vs. Numbers?

I am building up to solve a problem out of Dr. Cerro's 244 textbook.
First thing that I'd like to do is construct an "Atomic matrix" using molecules given by the user, something sort of like this:

                     Water    Carbon dioxide   Carbon monoxide    ...etc.
Carbon             0                   1                            1

Hydrogen         2                   0                            0

Oxygen            1                   2                            1
.
.
.


So, my goal is for the program to read the input molecular formulas (i.e. H2O for water, or CO2 for carbon dioxide), and construct the matrix with the appropriate values in the appropriate locations, combining the all the input information together.

I wrote this short program a week or so ago. It takes your name, and searches for a specified character, and returns the number of times that character appears in your name:

#Using a for-loop to run iterations through the characters of a scripts
name=raw_input("What is your name? ")
print " "
let=raw_input("What letter would you like to search for? ")
highlet=let.upper()
lowlet=let.lower()
#print highlet
#print lowlet
namelen=len(name)
#print namelen
totlets=0
for num in range (0,namelen):
    check=name[num]
    #print check
    if check==highlet or check==lowlet:
        totlets=totlets+1
    #print "totlets equals %s" %totlets
print " "
print "There are %s %s\'s in your name." %(totlets,highlet)

My plan is to modify the code so that instead of a user designated character, the code will automatically sum the number of times EACH charter appears in the string, using a similar method shown above.

The issue is that some atoms within a molecule occur more then the number of characters (There are two hydrogens in water, but only one H in  "H2O") So, my program will need to also take into account the numeric character following each letter (if there is one).

All that being said, is there a way to ask the code to distinguish between letters and numbers in a string?
I considered doing something involving an if-loop after counting the characters, which would ask if the character following a given letter within the for-loop was a number using something like:

for i in range (0,len(name):
       .
       .
       .
       if name[i+1]="1" or name[i+1]="2" or name[i+1]="3" or name[i+1]="3" or name[i+1]="4"....
            totlets=totlets + name[i+1] - 1  #Since the letter before the subscript would be counted twice.

I feel like there should be an easier way of doing it, like "if the character following name[i] is a number, add that number to the total number of name[i]'s in our count so far."

I'd appreciate any advice.

Thanks,

Elijah

Saturday, May 21, 2016

Where next -? (May 24, 2016)

Ideas?

What should we talk about?

Example problems involving if then -?  while ( ) ?

anything specific in analysis of data -?


Tuesday, May 17, 2016

May 17, 016 (what we did in class)

We discussed techniques to open and read files - the difference between "space" and "tabs" and "commas" - discussed if then and also "while" ...

What else? (!)

In the pffreadcsv program, I check for "Block" in the first "column"

What if that line does not start with "Block" - ?

I can modify the read as follows

# what if Block is NOT in the first column?
# read the file line by line
nstart = 0
for i in lines:
    nstart = nstart + 1
# the split command splits the line into individual elements as it were -
# so a line that is 1,2,1200,500 will be split into 1 2 1200 and 500 using the comma as a separator
    thisline = i.split(',')
# if I want to look for a line that has 'Block' (because I happen to know the data comes after this line)
    nchars = len(thisline)
    for j in range(nchars):
        if (str(thisline[j]) == 'Block'):
            print ("In your file ", datafile, " Block shows up in line ", nstart, ' at position ', j )
            break;
        else:
            continue

So you can "look" for any character you want on that line ... (!) 

(this makes it a bit more general than what I had)

Saturday, May 14, 2016

Some reminders (!)

Our objective is to make sure that anyone/everyone who is interested in python is able to "program" using python - simple or complex.

A reminder - I do not want to stand and "lecture" - but "do" - and "enable" you do do

I anticipate that there will be many who have never written a program - and many/few who are experts at programming (may even be python!)

I do not consider myself a "programmer" - but an "engineer who has taken to python to help solve problems" (and along the way, picked up some python)

Next week - (unless I hear otherwise) - let us examine reading data files (I have placed some examples) - using "loops" and "if then else" type constructs ...

I am serious when I say "programming is fun" - so bring your questions, doubts - "how to do X" or "how to do Y" and such ...!

If anyone is curious - I expect to get something out of this - a better understanding of some core elements in python and learn through solving problems you all can bring to the table - I may not be able to solve any/all problems on the fly - but I am sure I (and we) can by persisting (!)



Friday, May 13, 2016

How to read an xy data file (actually x, y1, y2) - create an Lineweaver Burke Plot, do analysis

This script reads data, does some calculations - creates a plot

we will go over this in class ...

https://drive.google.com/a/uah.edu/folderview?id=0B8bxiKU6FEY9cmxTblVVYlcwYlU&usp=sharing


How to read a csv file

A "csv" file is a text file -

an example csv file contains data from a "microarray" experiment ...

take a look and see if it makes sense (!) - we can go over this in class

the files are here (python script and the example test.csv file)

https://drive.google.com/a/uah.edu/folderview?id=0B8bxiKU6FEY9cmxTblVVYlcwYlU&usp=sharing

(if the link does not work, please let me know!)

Thursday, May 12, 2016

May 10, 2016 (What we did)

We met in EB 134 (classroom)

I started python - started an example - about doing simple calculations - difference between integer, floating point numbers, characters

What else?

Please remind me (!)

For Tuesday May 17, 2016

1) How to read data from a file?

What else?

I have an example from enzyme kinetics I will place here ... it solves an exam problem I had given - reading in data from a file, doing some calculations

(What I took down in class)

how to read data file

(heard from Josh Peek -
how to read a csv file ...)

(I have an example - I will try and post that example - reading and looping through a csv file)

how to build a graphic display (tic tac toe)

write a program that is like tic tac toe (this will be tough!)

Tuesday, May 10, 2016

Today, someone asked about learning to program games in python. Perhaps the following link will help:
https://pythonprogramming.net/pygame-python-3-part-1-intro/

Monday, May 9, 2016

Where can you get python? (For Windows)

Here are some good python packages (all free for download)

First important question is - 2 or 3? (python 2.X and python 3.X are different in many
ways)

I have been using "2" - but let us start with "3"

(It does not matter which distribution you have OR have installed - need
python along with some commonly used packages like Numpy and Scipy and
Matplotlib (for plots))


Anaconda (python)  (This is anaconda)

Enthought (canopy) (this is canopy)

Stand alone python (stand alone python)

(64 bit OR 32 bit - does not matter)

These packages may require you to be "administrator" on Windoze machines

(If using Apple/Mac - please look for instructions on how to install python - I am told
it is easy - and may already be on the Apple/Mac - )

Welcome to Python for Fun (PFF) (Or Python and Friends)

Programming is indeed fun!

There are many ways to learn Python

1) Download python, start using it

2) Learn from working programs - Here is a site that has several textbook problems worked out using python Textbook Project for Python

3) Read books on python (and try examples from such books)

Think Python

Python Computations in Science and Engineering

4) Upload your program so others can see what you have done (get feedback, improve!)

5) Here is a story of conversion from MatLAB to Python Matlab to Python

6) Do not want to install python anywhere - but still want to use python?  There is a solution (it could cost you some change ...) try this Data Joy for Python

7) A good book/reference for python (on a website, also downloadable) Python for total beginners (it says)