Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's a stab at what I think you wanted (though your requirements were kind of difficult to follow):</p> <pre><code>def extract_bio_data(input_path, output_path): #open the output file and write it's headers output_file = open(output_path, 'w') output_file.write('\t'.join(('position', 'min_value', 'rows_skipped')) + '\n') #map column indexes (after popping the row number) to the number of rows to skip col_index = { 0: 15, 1: 16, 2: 17 } skip_to_position = 0 for line in open(input_path, 'r'): #remove the '&gt; ' from the beginning of the line and strip newline characters off the end line = line[2:].strip() #if the line contains no data, skip it if line == '': continue #split the columns on whitespace (change this to split('\t') for splitting only on tabs) columns = line.split() #extract the row number/position of this data position = int(columns.pop(0)) #this is where we skip rows/positions if position &lt; skip_to_position: continue #if two columns share the minimum value, this will be the first encountered in the list min_index = columns.index(min(columns, key=float)) #this is an integer version of the 'column name' which corresponds to the number of rows that need to be skipped rows_to_skip = col_index[min_index] #write data to your new file (row number, minimum value, number of rows skipped) output_file.write('\t'.join(str(x) for x in (position, columns[min_index], rows_to_skip)) + '\n') #set the number of data rows to skip from this position skip_to_position = position + rows_to_skip if __name__ == '__main__': in_path = r'c:\temp\test_input.txt' out_path = r'c:\temp\test_output.txt' extract_bio_data(in_path, out_path) </code></pre> <p>Things that weren't clear to me:</p> <ol> <li>Is there really "> " at the beginning of each line or is that a copy/paste error? <ul> <li>I assumed it wasn't an error.</li> </ul></li> <li>Did you want "7.6" or "-7.6" written to the new file? <ul> <li>I assumed you wanted the original value.</li> </ul></li> <li>Did you want to skip rows in the file? or positions based on the first column? <ul> <li>I assumed you wanted to skip positions.</li> </ul></li> <li>You say you want to delete data from the original file. <ul> <li>I assumed that skipping positions was sufficient.</li> </ul></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload