Last active
May 30, 2018 05:49
-
-
Save timbitz/617edccec80e3d90f2bbc87a6d155969 to your computer and use it in GitHub Desktop.
principal_ratio.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# run function from split line | |
def tabs_principal_ratio(tabs): | |
if tabs[-2] != "NA" and tabs[-3] != "NA" and tabs[-2] != "Exc_Paths" and tabs[-3] != "Inc_Paths": | |
return principal_ratio( tabs[-2], tabs[-3] ) | |
# run function from last and second to last columns (must be validated already) | |
def principal_ratio( incl_col, excl_col ): | |
def arr_of_psi( string ): | |
ret = [] | |
coms = string.split(',') | |
for i in coms: | |
ret.append(float(i.split(':')[-1])) | |
return ret | |
arr = arr_of_psi(incl_col) | |
arr.extend(arr_of_psi(excl_col)) | |
arr.sort(reverse=True) | |
if len(arr) >= 2 and arr[0] != 1.0 and arr[1] != 0.0: | |
return arr[0] / arr[1] | |
else: | |
return None | |
# this works too. | |
def main(): | |
with open("output.psi", "r") as ins: | |
for line in ins: | |
l = line.rstrip('\n') | |
tabs = l.split('\t') | |
val = tabs_principal_ratio( tabs ) | |
if val != None: | |
print val | |
# this definintely works. | |
def test(): | |
print principal_ratio( '2-3-4:0.9649', '4-6:0.05333' ) | |
print principal_ratio( '2-3-4-6-7:0.4708', '2-4-6-7:0.4598,2-7:0.06942' ) | |
test() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment