Python: find the minimum in all rows


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Python: find the minimum in all rows
# 1  
Old 05-16-2013
Python: find the minimum in all rows

I am using Biopython to process an alignment in fasta format. I need to slice the sequences where there is the first stop codon. So I divided my alignment in codons and found the stop.
I then found the first codon position using enumerate().
But I found the minimum for each row. However I need to find the minimum (storing it where it won't be reset when it does the next row), determine which of those is smallest. So that I can slice all the sequences in the same place.

Code:
from Bio import AlignIO
stop = ["TAA"]
alignment = AlignIO.read('/Users/....', 'fasta')
for row in alignment:
	codons=[]
	codons = [str(row.seq[i:i+3]) for i in range(0,len(row.seq),3)]
	pstop = min([x for x,y in enumerate(codons) if y in stop])
	print pstop

pstop gives me the min for each row and I want to get the min of those min
to slice everything according to that min.
Thanks you very much for your help!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Find the minimum value of the column with respect to other column

Hi All, I would like get the minimum value in the certain column with respect to other column. For example, I have a text file like this. ATOM 1 QSS SPH S 0 -2.790 -1.180 -2.282 2.28 2.28 ATOM 1 QSS SPH S 1 -2.915 -1.024 -2.032 2.31 2.31 ATOM 1 ... (4 Replies)
Discussion started by: bala06
4 Replies

2. Shell Programming and Scripting

awk to find maximum and minimum from column and store in other column

Need your support for below. Please help to get required output If column 5 is INV then only consider column1 and take out duplicates/identical rows/values from column1 and then put minimum value of column6 in column7 and put maximum value in column 8 and then need to do subtract values of... (7 Replies)
Discussion started by: as7951
7 Replies

3. Shell Programming and Scripting

Find minimum and maximum values based on column with associative array

Hello, I need to find out the minimum and maximum values based on specific column, and then print out the entire row with the max value. Infile.txt: scf6 290173 290416 . + X_047241 T_00113118-1 scf6 290491 290957 . + X_047241 T_00113118-2 scf6 290898 290957 . + X_047241 T_00113119-3 scf6... (2 Replies)
Discussion started by: yifangt
2 Replies

4. Shell Programming and Scripting

How to find a minimum value of a row?

input 1 2 3 4 5 2 8 2 1 1 1 4 2 1 5 4 4 4 2 1 3 2 2 6 7 4 5 4 5 5 5 4 3 3 5 I woud like to print a min of each row such that my output would look like 1 1 1 2 3 (5 Replies)
Discussion started by: johnkim0806
5 Replies

5. Shell Programming and Scripting

In a row, replace negative sign and find minimum value among four columns

Hi Friends, I have an input file like this chr1 100 200 1 2 3 4 chr1 150 200 4 5 6 7 chr2 300 400 9 6 7 1 chr2 300 410 -10 21 -11 13 chr3 700 900 -21 -22 130 165 Now, my output file is chr1 100 200 1 chr1 150 200 4 chr2 300 400 1 chr2 300 410 10 chr3 700 900 21 Remove... (5 Replies)
Discussion started by: jacobs.smith
5 Replies

6. Shell Programming and Scripting

Find minimum value different from zero

Hello, I have this file file1.csv Element1;23-10-2012;1,450;1,564;1,428 Element2;23-10-2012;1,448;1,565;1,427 Element3;23-10-2012;1,453;1,570;1,424 Element4;23-10-2012;1,428;1,542;1,405 Element5;23-10-2012;1,461;;1,453 Element6;23-10-2012;1,438;1,555;1,417... (6 Replies)
Discussion started by: saba01
6 Replies

7. Shell Programming and Scripting

Finding minimum value out of specific rows

Hi all, I am having multiple files with the pattern given below: I need to find the minimum value of 5th column if column 1 is x and 2nd column is awh or vbn or ... (20 different strings). the output must be like: Kindly help me to figure out this prob.... Thanks in... (4 Replies)
Discussion started by: CAch
4 Replies

8. Shell Programming and Scripting

Find the minimum value

Hi there I have generated a column containing 100.000 values. Sample: 94.971 101.468 73.120 100.601 102.329 I need to find the minimum value in this file and I must know which row it is in (no sorting). I hope you can help! Thanks! (16 Replies)
Discussion started by: cno
16 Replies

9. Shell Programming and Scripting

Find the minimum number

Input 10 8 20 8 10 9 20 9 10 12 20 19 10 10 20 40 Output1 10 8 2 20 8 12 10 9 1 20 9 11 10 12 -2 20 19 1 10 10 0 20 40 -20 Output2 10 9 ... (0 Replies)
Discussion started by: repinementer
0 Replies

10. Shell Programming and Scripting

Merge two rows using awk or python

Hi, Suppose I have a space delimited file like this: Serial# 1970 1971 1972 1973 1974 193532 21 2 X X X 200201 20 30 X X 40 200201 X X 13 15 X 393666 66 3 X X 5 ... (2 Replies)
Discussion started by: grossgermany
2 Replies
Login or Register to Ask a Question
LONG-ORFS(1)						      General Commands Manual						      LONG-ORFS(1)

NAME
long-orfs -- Find/Score potential genes in genome-file using the probability model in icm-file SYNOPSIS
tigr-long-orgs [genome-file options] DESCRIPTION
Program long-orfs takes a sequence file (in FASTA format) and outputs a list of all long "potential genes" in it that do not overlap by too much. By "potential gene" I mean the portion of an orf from the first start codon to the stop codon at the end. The first few lines of output specify the settings of various parameters in the program: Minimum gene length is the length of the smallest fragment considered to be a gene. The length is measured from the first base of the start codon to the last base *before* the stop codon. This value can be specified when running the program with the -g option. By default, the program now (April 2003) will compute an optimal length for this parameter, where "optimal" is the value that produces the greatest number of long ORFs, thereby increasing the amount of data used for training. Minimum overlap length is a lower bound on the number of bases overlap between 2 genes that is considered a problem. Overlaps shorter than this are ignored. Minimum overlap percent is another lower bound on the number of bases overlap that is considered a problem. Overlaps shorter than this percentage of *both* genes are ignored. The next portion of the output is a list of potential genes: Column 1 is an ID number for reference purposes. It is assigned sequentially starting with 1 to all long potential genes. If overlap- ping genes are eliminated, gaps in the numbers will occur. The ID prefix is specified in the constant ID_PREFIX . Column 2 is the position of the first base of the first start codon in the orf. Currently I use atg, and gtg as start codons. This is easily changed in the function Is_Start () . Column 3 is the position of the last base *before* the stop codon. Stop codons are taa, tag, and tga. Note that for orfs in the reverse reading frames have their start position higher than the end position. The order in which orfs are listed is in increasing order by Max {OrfStart, End}, i.e., the highest numbered position in the orf, except for orfs that "wrap around" the end of the sequence. When two genes with ID numbers overlap by at least a sufficient amount (as determined by Min_Olap and Min_Olap_Percent ), they are elimi- nated and do not appear in the output. The final output of the program (sent to the standard error file so it does not show up when output is redirected to a file) is the length of the longest orf found. Specifying Different Start and Stop Codons: To specify different sets of start and stop codons, modify the file gene.h . Specifically, the functions: Is_Forward_Start Is_Reverse_Start Is_Start Is_Forward_Stop Is_Reverse_Stop Is_Stop are used to determine what is used for start and stop codons. Is_Start and Is_Stop do simple string comparisons to specify which patterns are used. To add a new pattern, just add the comparison for it. To remove a pattern, comment out or delete the comparison for it. The other four functions use a bit comparison to determine start and stop patterns. They represent a codon as a 12-bit pattern, with 4 bits for each base, one bit for each possible value of the bases, T, G, C or A. Thus the bit pattern 0010 0101 1100 represents the base pattern [C] [A or G] [G or T]. By doing bit operations (& | ~) and comparisons, more complicated patterns involving ambiguous reads can be tested efficiently. Simple patterns can be tested as in the current code. For example, to insert an additional start codon of CAT requires 3 changes: 1. The line || (Codon & 0x218) == Codon should be inserted into Is_Forward_Start , since 0x218 = 0010 0001 1000 represents CAT. 2. The line || (Codon & 0x184) == Codon should be inserted into Is_Reverse_Start , since 0x184 = 0001 1000 0100 represents ATG, which is the reverse-complement of CAT. Alternately, the #define constant ATG_MASK could be used. 3. The line || strncmp (S, "cat", 3) == 0 should be inserted into Is_Start . OPTIONS
-g n Set minimum gene length to n. Default is to compute an optimal value automatically. Don't change this unless you know what you're doing. -l Regard the genome as linear (not circular), i.e., do not allow genes to "wrap around" the end of the genome. This option works on both glimmer and long-orfs . The default behavior is to regard the genome as circular. -o n Set maximum overlap length to n. Overlaps shorter than this are permitted. (Default is 0 bp.) -p n Set maximum overlap percentage to n%. Overlaps shorter than this percentage of *both* strings are ignored. (Default is 10%.) SEE ALSO
tigr-glimmer3 (1), tigr-adjust (1), tigr-anomaly (1), tigr-build-icm (1), tigr-check (1), tigr-codon-usage (1), tigr-compare-lists (1), tigr-extract (1), tigr-generate (1), tigr-get-len (1), tigr-get-putative (1), http://www.tigr.org/software/glimmer/ Please see the readme in /usr/share/doc/tigr-glimmer for a description on how to use Glimmer3. AUTHOR
This manual page was quickly copied from the glimmer web site by Steffen Moeller moeller@debian.org for the Debian system. LONG-ORFS(1)