QA Python Tools: Difference between revisions

From Genecats
Jump to navigationJump to search
No edit summary
 
(8 intermediate revisions by the same user not shown)
Line 3: Line 3:
~/kent/python/lib/ucscGb/qa/</pre>
~/kent/python/lib/ucscGb/qa/</pre>


To properly import a package, function, or class, make sure you have the <code>~/kent/python/lib/ucscGb/</code> directory specified in your <code>PYTHONPATH</code> variable. The <code>PYTHONPATH</code> works similarly to the <code>PATH</code> variable inside of the <code>.bashrc</code> file. You can add the following line to your <code>.bashrc</code> file to import packages from the /ucscGb directory:
To properly import a package, function, or class, make sure you have the <code>~/kent/python/lib/</code> directory specified in your <code>PYTHONPATH</code> variable. The <code>PYTHONPATH</code> works similarly to the <code>PATH</code> variable inside of the <code>.bashrc</code> file. You can add the following line to your <code>.bashrc</code> file to import packages from the /ucscGb directory:
<pre>
<pre>
export PYTHONPATH=$PYTHONPATH:~/kent/python/lib/ucscGb</pre>
export PYTHONPATH=$PYTHONPATH:~/kent/python/lib/</pre>
Then, to import the package, you can use the following line:
Then, to import the package, you can use the following line:
<pre>
<pre>
Line 13: Line 13:
trackUtils.getLabels(db, track, labelType)</pre>
trackUtils.getLabels(db, track, labelType)</pre>


====<span style="color:dodgerblue">tables/trackUtils.py====
====<span style="color:dodgerblue">from ucscGB.qa.tables import trackUtils====
</span>
</span>


Line 22: Line 22:
:'''def getAttributeForTrack(attribute, db, track):'''
:'''def getAttributeForTrack(attribute, db, track):'''
:<pre>Uses tdbQuery to get an attribute where track or table == 'track' and removes label.</pre>
:<pre>Uses tdbQuery to get an attribute where track or table == 'track' and removes label.</pre>
:*Depeneds on '''runCommand''' within qaUtils.py
:*Depends on '''runCommand''' within qaUtils.py
 
====<span style="color:dodgerblue">from ucscGb.qa import qaUtils====
</span>
 
The commands that are passed through these functions use the <code>subprocess</code> class, which requires the command to be in the form of a list. The first element in the list is program to be used, e.g., <code>hgsql</code>, and all other elements are seen as arguments. For example, the following line can be used as an argument:
<pre>
["tdbQuery", "select type from %s where track='%s'" % (db, track)]</pre>
 
:'''def callHgsql(database, command):'''
:<pre>Run hgsql command using subprocess, return stdout data if no error.</pre>
:* This the only function where the <code>command</code> arguement is not a list but a string, i.e.,
::<code>"select name from knownGene where name='ENST00000619216.1'"</code>
:'''def runCommand(command):'''
:<pre>Runs command in subprocess and raises exception if return code is not 0. Returns tuple (stdoutdata, stderrdata).</pre>
 
:'''def runCommandMergedOutErr(command):'''
:<pre>Runs command in subprocess and raises exception if return code is not 0. Combines stdout and stderr into a single output. Returns stdoutdata string.</pre>
 
:'''def runCommandNoAbort(command):'''
:<pre>Runs command in subprocess. Returns tuple (stdoutdata, stderrdata) and returncode from process.</pre>

Latest revision as of 21:15, 7 February 2019

This page contains information about the different python modules and functions. The QA python scripts live in the following directory:

~/kent/python/lib/ucscGb/qa/

To properly import a package, function, or class, make sure you have the ~/kent/python/lib/ directory specified in your PYTHONPATH variable. The PYTHONPATH works similarly to the PATH variable inside of the .bashrc file. You can add the following line to your .bashrc file to import packages from the /ucscGb directory:

export PYTHONPATH=$PYTHONPATH:~/kent/python/lib/

Then, to import the package, you can use the following line:

from ucscGb.qa.tables import trackUtils

You can call a function inside of the trackUtils python script by using the following syntax:

trackUtils.getLabels(db, track, labelType)

from ucscGB.qa.tables import trackUtils

def getLabels(db, track, labelType):
Returns labels of specified 'type' (shortLabel or longLabel) for a single track, its parent, and its superTrack. Excludes 'view' labels.
  • Depends on getAttributeForTrack within tables/trackUtils.py
def getAttributeForTrack(attribute, db, track):
Uses tdbQuery to get an attribute where track or table == 'track' and removes label.
  • Depends on runCommand within qaUtils.py

from ucscGb.qa import qaUtils

The commands that are passed through these functions use the subprocess class, which requires the command to be in the form of a list. The first element in the list is program to be used, e.g., hgsql, and all other elements are seen as arguments. For example, the following line can be used as an argument:

["tdbQuery", "select type from %s where track='%s'" % (db, track)]
def callHgsql(database, command):
Run hgsql command using subprocess, return stdout data if no error.
  • This the only function where the command arguement is not a list but a string, i.e.,
"select name from knownGene where name='ENST00000619216.1'"
def runCommand(command):
Runs command in subprocess and raises exception if return code is not 0. Returns tuple (stdoutdata, stderrdata).
def runCommandMergedOutErr(command):
Runs command in subprocess and raises exception if return code is not 0. Combines stdout and stderr into a single output. Returns stdoutdata string.
def runCommandNoAbort(command):
Runs command in subprocess. Returns tuple (stdoutdata, stderrdata) and returncode from process.