def addInteractionsNewDB(interaction_type: bool, bacterium_id: int, phage_id: int, level_id: int, lysis_id: int, persone_responsible: int, source_data_id: int, validity_id: bool): couple_obj = CoupleJson(interaction_type=interaction_type, bacteriophage=phage_id, bacterium=bacterium_id, level=level_id, lysis=lysis_id, person_responsible=persone_responsible, source_data=source_data_id, validity=validity_id) couple_obj_json = couple_obj.setCouple() return couple_obj_json
def matrixSimilarityScript(file_name: str, path: str, organism_id: int, is_phage=False): """ | Create a matrix of similarity with many organisms. | In this version, get all the couples with organism id (according with a | specific level of lysis). | Calculates the similarity between all the different organisms in the couples :Remark: To compare other organisms, modifie the content of list_organism_to_compare :param file_name: name of the similarity matrix :param path: where save the matrix :param organism_id: id of the organism to find couples :param is_phage: to differenciate bacterium and phages :type file_name: str :type path: str :type organism_id: int :type is_phage: boolean """ lysis_type = constants.ALL_CLEAR_LYSIS file_name = file_name path = path organism_dict = {} # Get couple from specific bacterie if is_phage == False: organism_dict['bacterium'] = organism_id else: organism_dict['bacteriophage'] = organism_id # Get all the couples with the organism gave in parameter liste_couple = (CoupleJson.getCouplesByFilterParameter(organism_dict)) # Select couple according with the lysis attribute liste_couple_final = [] for couple in liste_couple: if couple.lysis in lysis_type: liste_couple_final.append(couple) list_organism_to_compare = [] for couple in liste_couple_final: if is_phage == False: # check if there is no duplicate phage in the list if couple.bacteriophage not in list_organism_to_compare: list_organism_to_compare.append(couple.bacteriophage) else: # check if there is no duplicate phage in the list if couple.bacterium not in list_organism_to_compare: list_organism_to_compare.append(couple.bacterium) # Change the contents of list_organism_to_compare to compare other organisms # list_organism_to_compare = general_functions.getCouplesLysis(lysis_type) createSimilarityMatrix(list_organism_to_compare, file_name, path, not is_phage)
def getAllOfCouples(): """ | Get all couples from DB Inphinity :return: all couples from DB Inphinity :rtype: list """ list_couples = CoupleJson.getAllAPI() return list_couples
def relationGraphOrganism(organism_id: int, is_phage=False): """ | Draw a relation graph between phages and bacteria according | to the organism_id and clear lysis attribute. :Remark: Change the list_couple_final for other comparisons :param organism_id: lysis :param is_phage: if the organism is a phage :type organism_id: int :type is_phage: boolean """ # Choose what type of lysis we want lysis_type = constants.ALL_CLEAR_LYSIS # Get couple from specific bacterie organism_dict = {} # Research bact or phage by ID if is_phage == False: organism_dict['bacterium'] = organism_id else: organism_dict['bacteriophage'] = organism_id liste_couple = (CoupleJson.getCouplesByFilterParameter(organism_dict)) # Select couple in function of the lysis liste_couple_final = [] for couple in liste_couple: if couple.lysis in lysis_type: liste_couple_final.append(couple) # Defining two correlation tables between phages and bacteriums phages = [] bacterium = [] for couple in liste_couple_final: phages.append( BacteriophageJson.getByID(couple.bacteriophage).designation ) # Get designation and phage id # Get the name of bacterium (strain designation + species designation) and his id strain_id = BacteriumJson.getByID(couple.bacterium).strain strain_designation = StrainJson.getByID(strain_id).designation specie_designation = SpecieJson.getByID( StrainJson.getByID(strain_id).specie).designation bacterium.append(specie_designation + '-' + strain_designation + '\n' + str(couple.bacterium)) # Draw network graph draw_graph(phages, bacterium, liste_couple_final, graph_name='graph', is_png=False)
def getCouplesLevelOne(): """ Return all the couples with an interaction of level 1 :return: list of couples :rtype: list(CoupleJson) """ dict_parameters_couple = {} dict_parameters_couple['level'] = 1 list_couples = CoupleJson.getCouplesByFilterParameter( dict_parameters_couple) return list_couples
def getCoupleTyById(id_couple: int): """ return a interaction type of a given couple ID :param id_couple: id of the couple :type id_couple: int :return: type of the couple :rtype: int """ dict_parameters_couple = {} dict_parameters_couple['id'] = id_couple couple_obj = CoupleJson.getCouplesByFilterParameter(dict_parameters_couple) type_interaction = couple_obj.interaction_type return type_interaction
from objects_API.FamilyJ import FamilyJson from objects_API.GenusJ import GenusJson from objects_API.StrainJ import StrainJson from objects_API.CoupleJ import CoupleJson conf_obj = ConfigurationAPI() conf_obj.load_data_from_ini() AuthenticationAPI().createAutenthicationToken() family_obj = FamilyJson.getByID(147) genus_obj = GenusJson.getByID(98) strain_obj = StrainJson.getByID(17144) print(family_obj) print(genus_obj) print(strain_obj) list_couple = CoupleJson.getAllAPI() list_family = FamilyJson.getAllAPI() list_gesy = GenusJson.getAllAPI() list_strain = StrainJson.getAllAPI() list_couple_ddi = DomainInteractionPairJson.getAllAPI() list_db_names = DomainSourceInformationJson.getAllAPI() list_locationsDDI_source = DomainInteractionSourceJson.getAllAPI() print(len(list_couple_ddi)) #list_couples = getAllCouples() print('hello')
def getAllCouples(): list_couple = CoupleJson.getAllAPI() return list_couple
def createFeaturesFile(file_name: str, path: str, organism_id: int = None, is_phage: bool = False): """ | Create a csv file with organisms features. | The organisms to compare are choosen according to the organism_id param. | Takes all couples with organism_id and select only the couples Clear Lysis. | Then extracts features from the remaining organisms. | If no organism_id referenced take the organisms in list_couple The features are : - mean of all amino acids - mean of all chemical elements - weight of the organism - iso eletrical point - aromaticity :param file_name: name of csv file :param path: path to save the file :param organism_id: id of organism :param is_phage: if true, compare bacteria. If false, compare bacteriophages :type file_name: str :type path: str :type organism_id: int :type is_phage: boolean """ # Choose what type of lysis we want lysis_type = constants.ALL_CLEAR_LYSIS file_name = file_name path = path # Get the phages of all the couples with an interaction type # list_couple = network.getCouplesInteraction(CoupleJson.getAllAPI(), interaction_type=True) # Get the phages of specific couples liste_couple = general_functions.getCouplesLysis(lysis_type) # Get couple from specific bacterie organism_dict = {} # Research bact or phage by ID if is_phage == False and organism_id != None: organism_dict['bacterium'] = organism_id liste_couple = (CoupleJson.getCouplesByFilterParameter(organism_dict)) elif organism_id != None: organism_dict['bacteriophage'] = organism_id liste_couple = (CoupleJson.getCouplesByFilterParameter(organism_dict)) if organism_id != None: # Select couple in function of the lysis liste_couple_final = [] for couple in liste_couple: if couple.lysis in lysis_type: liste_couple_final.append(couple) else: liste_couple_final = liste_couple # phages to extract features will be here list_phages = [] for couple in liste_couple_final: if not couple.bacteriophage in list_phages: list_phages.append(couple.bacteriophage) phages_amino_acids = OrderedDict() for couple in liste_couple_final: if not couple.bacteriophage in phages_amino_acids.keys(): phage_amino_acid_dict = getFeaturesForAPhage( BacteriophageJson.getByID(couple.bacteriophage), active_percentage=False, get_features=True) phages_amino_acids[BacteriophageJson.getByID( couple.bacteriophage).designation] = phage_amino_acid_dict # Source : # ADAM SMITH [Pseudonyme], 2015. This is beyond simple if you can use pandas. # Stackoverflow [en ligne]. 16 Juillet 2015 à 16h38. # [Consulté le 3 Avril 2019]. Disponible à l'adresse : https://stackoverflow.com/questions/31436783/writing-dictionary-of-dictionaries-to-csv-file-in-a-particular-format df1 = pd.DataFrame.from_dict(data=phages_amino_acids, orient="index") df1.to_csv(os.path.join(path, file_name)) df1 = df1.rename_axis('Phages designation', axis='columns') df1.to_csv(os.path.join(path, file_name), index_label='Phages designation') ending_message = "file " + file_name + " saved in " + path print(ending_message)
# id_phage = couple_element.fk_phage acc_bacteriophage = obtainphageACCnumberFromOldDBId(id_phage) id_new_phage_db = -1 if id_phage in dict_convert_phages_id: id_new_phage_db = dict_convert_phages_id[id_phage] else: try: id_new_phage_db = getBacteriophageByACCNEWDB(acc_bacteriophage) except: id_new_phage_db = -1 if id_new_phage_db != -1 and id_new_bacterium_db != -1: try: couple_obj = CoupleJson.getByBacteriumPhageIds( id_new_bacterium_db, id_new_phage_db) except: count_error += 1 interaction_type_cp = couple_element.interact_pn id_bacterium_cp = id_new_bacterium_db id_phage_cp = id_new_phage_db validity_id_cp = 4 #not validate level_interaction_cp = 2 source_data_cp = 1 person_responsible_cp = 3 couple_obj_json = CoupleJson( interaction_type=interaction_type_cp, bacteriophage=id_phage_cp, bacterium=id_bacterium_cp, level=level_interaction_cp,
def getAllCouplesByParameters(parameter_dic: dict): list_couples = CoupleJson.getCouplesByFilterParameter(parameter_dic) return list_couples