Note that there are some explanatory texts on larger screens.

plurals
  1. POPython Conditionals Error with code
    primarykey
    data
    text
    <p>I had previously asked this question, trying to get started with this code: The command line parameters need to take 2 OR 3 parameters</p> <p>-s: this is an optional parameter, or switch, indicating that the user wwants the spliced gene sequence(introns removed). The user does not have to provide this (meaning he wants the entire gene sequence), but it he does provide it then it must be the first parameter</p> <p>input file (with the genes)</p> <p>output file (where the program will create to store the fasta file</p> <p>the file contains line like this:</p> <p>NM_001003443 chr11 + 5925152 592608098 2 5925152,5925652, 5925404,5926898,</p> <p>I then needed to make multiple conditionals to make sure that everything that was input was correct, or else the program would exit:</p> <ul> <li>The user specifies an input file name that does not end with .genes</li> <li>The user specifies an output name that does not end with either .fa or .fasta</li> <li>The user provides less than two, or more than three, parameters</li> <li>The user's first parameter starts with a dash, but is not '-s'</li> <li><p>The input file violates any of the following:</p> <ul> <li>The first line should start with a '#' symbol</li> <li>Every line should have exactly ten columns (columns separated by one or more spaces)</li> <li>Column 2 (counting from 0) should be either a + or - symbol</li> <li>Column 8 should be a tab-separated list of integers</li> <li>Column 9 should be a tab-separated list of integers, with exactly the same integers as column 8.</li> </ul></li> </ul> <p>I have written code for this, yet there is an error somewhere in it. Yet, I am unable to locate the error as of late. Could someone help me look though my code and see if an error is present somewhere? I would really appreciate it!!</p> <p>All the if statement are tabbed over in my actual code, but I had trouble importing it here...</p> <pre><code>import sys p = '(NM_\d+)\s+(chr\d+)([(\+)|(-)])\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+,\d+,)s+(\d+,\d+,)' e = '([(\+)|(-)])' def getGenes(spliced, infile, outfile): spliced = False if '-s' in sys.argv: spliced = True sys.argv.remove('s') infile, outfile = sys.argv[1:] if '.genes' not in infile: print('Incorrect input file type') sys.exit(1) if '.fa' or '.fasta' not in outfile: print('Incorrect output file type') sys.exit(1) if len(sys.argv[0]) &lt; 2 or len(sys.argv[0]) &gt; 3: print('Command line parameters missing') sys.exit(1) if sys.argv[1] != '-s': print('Invalid parameter, if spliced, must be -s') sys.exit(1) fp = open(infile, 'r') wp = open(outfile, 'r') FirstLine = fp.readline().strip() if not FirstLine.startswith('#'): print ('First line does not start with #') sys.exit(1) n = 1 for line in fp.readlines(): n += 1 cols = line.strip().split('') if len(cols) != 10: print('Lenth not equal to 10') sys.exit(1) if cols[2] != '+' or '-': print('Column 2 is not a + or - symbol') sys.exit(1) if cols[8] != '\t\d+': print('Column 8 is not a tab-separated list of integers') sys.exit(1) if cols[9] != '\t\d+' and len(cols[9]) != len(cols[8]): print('Column 9 in not a tab-separated list of integers with the exact same number of integers in column 8') sys.exit(1) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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