comparison mqppep_mrgfltr.py @ 6:922d309640db draft

"planemo upload for repository https://github.com/galaxyproteomics/tools-galaxyp/tree/master/tools/mqppep commit 9dfb7e07a3673d7de4b0a1b7e6ce1b75a8a4f42b"
author eschen42
date Fri, 11 Mar 2022 20:04:05 +0000
parents d4d531006735
children
comparison
equal deleted inserted replaced
5:d4d531006735 6:922d309640db
39 print(" with args %s" % str(args)) 39 print(" with args %s" % str(args))
40 print(" caught exception: %s" % str(e)) 40 print(" caught exception: %s" % str(e))
41 (ty, va, tb) = sys.exc_info() 41 (ty, va, tb) = sys.exc_info()
42 print(" stack trace: " + str(traceback.format_exception(ty, va, tb))) 42 print(" stack trace: " + str(traceback.format_exception(ty, va, tb)))
43 exit(-1) 43 exit(-1)
44 return None
45
46
47 def whine(func, *args, handle=lambda e: e, **kwargs):
48
49 try:
50 return func(*args, **kwargs)
51 except Exception as e:
52 print("Warning: For %s" % str(func))
53 print(" with args %s" % str(args))
54 print(" caught exception: %s" % str(e))
55 (ty, va, tb) = sys.exc_info()
56 print(" stack trace: " + str(traceback.format_exception(ty, va, tb)))
44 return None 57 return None
45 58
46 59
47 def ppep_join(x): 60 def ppep_join(x):
48 x = [i for i in x if N_A != i] 61 x = [i for i in x if N_A != i]
681 # print("'{expression}': {message}".format( 694 # print("'{expression}': {message}".format(
682 # expression = pe.expression, 695 # expression = pe.expression,
683 # message = pe.message)) 696 # message = pe.message))
684 # ) 697 # )
685 # ) 698 # )
699 if phospho_pep not in PhosphoPep_UniProtSeq_LUT:
700 raise PreconditionError(
701 phospho_pep,
702 "no matching phosphopeptide found in PhosphoPep_UniProtSeq_LUT",
703 )
686 if dephospho_pep not in DephosphoPep_UniProtSeq_LUT: 704 if dephospho_pep not in DephosphoPep_UniProtSeq_LUT:
687 raise PreconditionError( 705 raise PreconditionError(
688 dephospho_pep, 706 dephospho_pep,
689 "dephosphorylated phosphopeptide not found in DephosphoPep_UniProtSeq_LUT", 707 "dephosphorylated phosphopeptide not found in DephosphoPep_UniProtSeq_LUT",
690 )
691 if phospho_pep not in PhosphoPep_UniProtSeq_LUT:
692 raise PreconditionError(
693 dephospho_pep,
694 "no matching phosphopeptide found in PhosphoPep_UniProtSeq_LUT",
695 ) 708 )
696 if ( 709 if (
697 dephospho_pep 710 dephospho_pep
698 != PhosphoPep_UniProtSeq_LUT[(phospho_pep, DEPHOSPHOPEP)] 711 != PhosphoPep_UniProtSeq_LUT[(phospho_pep, DEPHOSPHOPEP)]
699 ): 712 ):
737 seq7s = [] 750 seq7s = []
738 seq10s_set = set() 751 seq10s_set = set()
739 seq10s = [] 752 seq10s = []
740 while i < len(ploc): 753 while i < len(ploc):
741 start = UniProtSeq.find(dephospho_pep) 754 start = UniProtSeq.find(dephospho_pep)
755 # handle case where no sequence was found for dep-pep
756 if start < 0:
757 i += 1
758 continue
742 psite = ( 759 psite = (
743 start + ploc[i] 760 start + ploc[i]
744 ) # location of phosphoresidue on protein sequence 761 ) # location of phosphoresidue on protein sequence
745 762
746 # add Phosphoresidue 763 # add Phosphoresidue
867 # valL is a list of strings 884 # valL is a list of strings
868 for val in valL: 885 for val in valL:
869 # val is a string 886 # val is a string
870 if val not in joined_set: 887 if val not in joined_set:
871 joined_set.add(val) 888 joined_set.add(val)
872 # joined_value += sep + '; '.join(map(str, val))
873 joined_value += sep + val 889 joined_value += sep + val
874 sep = "; " 890 sep = "; "
875 # joined_value is a string 891 # joined_value is a string
876 result[key] = joined_value 892 result[key] = joined_value
877 893
912 result[SEQUENCE7] = newstring 928 result[SEQUENCE7] = newstring
913 929
914 return [phospho_pep, result] 930 return [phospho_pep, result]
915 931
916 # Construct list of [string, dictionary] lists 932 # Construct list of [string, dictionary] lists
917 # where the dictionary provides the SwissProt metadata for a phosphopeptide 933 # where the dictionary provides the SwissProt metadata
934 # for a phosphopeptide
918 result_list = [ 935 result_list = [
919 catch(pseq_to_subdict, psequence) 936 whine(pseq_to_subdict, psequence)
920 for psequence in data_in[PHOSPHOPEPTIDE_MATCH] 937 for psequence in data_in[PHOSPHOPEPTIDE_MATCH]
921 ] 938 ]
922 939
923 end_time = time.process_time() # timer 940 end_time = time.process_time() # timer
924 print( 941 print(
1019 left_on=SEQUENCE7, 1036 left_on=SEQUENCE7,
1020 right_on=SITE_PLUSMINUS_7AA_SQL, 1037 right_on=SITE_PLUSMINUS_7AA_SQL,
1021 how="left", 1038 how="left",
1022 ) 1039 )
1023 1040
1024 # after merging df, select only the columns of interest - note that PROTEIN is absent here 1041 # after merging df, select only the columns of interest;
1042 # note that PROTEIN is absent here
1025 merge_df = merge_df[ 1043 merge_df = merge_df[
1026 [ 1044 [
1027 PHOSPHOPEPTIDE, 1045 PHOSPHOPEPTIDE,
1028 SEQUENCE7, 1046 SEQUENCE7,
1029 ON_FUNCTION, 1047 ON_FUNCTION,
1031 ON_PROT_INTERACT, 1049 ON_PROT_INTERACT,
1032 ON_OTHER_INTERACT, 1050 ON_OTHER_INTERACT,
1033 ON_NOTES, 1051 ON_NOTES,
1034 ] 1052 ]
1035 ] 1053 ]
1036 # combine column values of interest into one FUNCTION_PHOSPHORESIDUE column" 1054 # combine column values of interest
1055 # into one FUNCTION_PHOSPHORESIDUE column"
1037 merge_df[FUNCTION_PHOSPHORESIDUE] = merge_df[ON_FUNCTION].str.cat( 1056 merge_df[FUNCTION_PHOSPHORESIDUE] = merge_df[ON_FUNCTION].str.cat(
1038 merge_df[ON_PROCESS], sep="; ", na_rep="" 1057 merge_df[ON_PROCESS], sep="; ", na_rep=""
1039 ) 1058 )
1040 merge_df[FUNCTION_PHOSPHORESIDUE] = merge_df[ 1059 merge_df[FUNCTION_PHOSPHORESIDUE] = merge_df[
1041 FUNCTION_PHOSPHORESIDUE 1060 FUNCTION_PHOSPHORESIDUE