예제 #1
0
def get_organism_type_by_strain(fkStrain):
    """
    check the organism type and verify if any errors exists

    :param fkStrain: FK strain of the organism

    :type fkStrain: int

    :return: error code or type of the organism (1 bacterium - 2 phage)
    :rtype int

    :note: -1 - more than one organism with this strain
           -2 - No organism with this strain
           -3 - Other errors
           

    """
    listOrganism = Organism.get_organism_by_fk_strain(fkStrain)
    qtyOrganism = len(listOrganism)
    if qtyOrganism > 1:
        return -1
    elif qtyOrganism == 0:
        return -2
    elif qtyOrganism == 1:
        return listOrganism[0].fk_type
    else:
        return -3
예제 #2
0
def get_bacterium_taxonomy_designation_by_id_bacterium(bacterium_id: int):
    """
    return the strain, specie, and genus of the bacterium given it id

    :return list with the respective taxonomy
    :rtype list[str,str,str]

    """

    organism_obj = Organism.get_organism_by_id(bacterium_id)
    fk_strain = organism_obj.fk_strain

    strain_obj = Strain.get_strain_by_id(fk_strain)
    fk_specie = strain_obj.fk_specie
    strain_designation = strain_obj.designation

    specie_obj = Specie.get_specie_by_id(fk_specie)
    fk_genus = specie_obj.fk_genus
    specie_designation = specie_obj.designation

    genus_id = specie_obj.fk_genus
    genus_obj = Genus.get_genus_by_id(fk_genus)
    genus_designation = genus_obj.designation

    list_taxonomy = [strain_designation, specie_designation, genus_designation]

    return list_taxonomy
예제 #3
0
def get_acc_by_organism(id_organism: int):
    """
    return all the couple in the old db given the level id and ignore those obtain by Greg

    :return List with the couples
    :rtype List(Couple)

    """
    organism_obj = Organism.get_organism_by_id(id_organism)
    acc_number = organism_obj.acc_num
    return acc_number
def getBacteriumStrainSpecieDesignationById(id_bacterium):
    organism_obj = Organism.get_organism_by_id(id_bacterium)
    id_strain = organism_obj.fk_strain
    strain_obj = Strain.get_strain_by_id(id_strain)

    id_specie = strain_obj.fk_specie

    specie_obj = Specie.get_specie_by_id(id_specie)
    specie_designation = specie_obj.designation

    strain_designation = strain_obj.designation

    taxonomy_bacterium = 'Specie: ' + specie_designation + ' Strain: ' + strain_designation

    return taxonomy_bacterium
예제 #5
0
def get_phage_name_by_id(phage_id: int):
    """
    return the name of the phage according to it id

    :return phage name
    :rtype str

    """

    organism_obj = Organism.get_organism_by_id(phage_id)
    fk_strain = organism_obj.fk_strain

    strain_obj = Strain.get_strain_by_id(fk_strain)
    strain_designation = strain_obj.designation

    return strain_designation
예제 #6
0
    print("---------------")
    #print(line)
    bact_id = line[1]['bact_ident']
    bact_name = line[1]['bactphage']
    p68_lysis = line[1]['P68']
    p44AHJD_lysis = line[1]['44AHJD']
    p3A_lysis = line[1]['3A']
    p71_lysis = line[1]['71P']
    p77_lysis = line[1]['77P']
    pK_lysis = line[1]['K']
    pSb1_lysis = line[1]['Sb-1']
    print(bact_id)
    print(bact_name)
    print(p77_lysis)
    print(pK_lysis)
    dict_value = Organism.get_organism_id_by_strain_like(bact_name)
    print(dict_value)

    id_bact = bact_id
    id_type_interaction = 1
    type_interaction = True
    id_level_interaction = 4

    #def __init__(self, id_couple, interact_pn,  fk_bacteria, fk_phage, fk_type_inter, fk_level_interact, fk_lysis_inter = -1, fk_source_data = -1):

    #Check if any couple exists
    id_phage = 10107
    if p68_lysis != 'No':
        print("3333333")
        print(p68_lysis)
        id_lysis = dict_lysis_type[p68_lysis]
예제 #7
0
def obtainphageACCnumberFromOldDBId(id_bacteriophage_old_db: int):
    organism_obj = Organism.get_organism_by_id(id_bacteriophage_old_db)
    acc_number = organism_obj.acc_num
    return acc_number
예제 #8
0
def obtainBacteriumIdFromOldDBId(id_bacterium_old_db: int):
    organism_obj = Organism.get_organism_by_id(id_bacterium_old_db)
    fk_strain_old_db = organism_obj.fk_strain
    return fk_strain_old_db
def getPhageDesignationById(id_phage):
    organism_obj = Organism.get_organism_by_id(id_phage)
    id_strain = organism_obj.fk_strain
    strain_obj = Strain.get_strain_by_id(id_strain)
    strain_designation = strain_obj.designation
    return strain_designation
예제 #10
0
def load_get_bacteriophage(pathFile, arrayStates):
    """
    read the CSV with the organism id, strain id and their states. This method call the other for the insertion of the bacteriophage on the database

    :param pathFile: path of teh CSV file

    :type pathFile: String

    :return: matrix with all the data
    :rtype panda dataframe

    """

    arrayProblems = [11548, 11549]
    wholeDNA = None
    dataframe = pd.read_csv(pathFile)

    for index, row in dataframe.iterrows():
        if row['organism_type'] == 4:
            row_verification = [[row['strain_db'], row['strain_api'], 2]]

            id_strain_API = row['strain_api']
            if id_strain_API not in arrayStates[:,
                                                1] and id_strain_API not in arrayProblems:
                print(row['strain_db'])
                arrayStates = np.append(arrayStates, row_verification, axis=0)
                writeCSVStateInsertion(arrayStates)

                bacteriophageList = Organism.get_organism_by_fk_strain(
                    row['strain_db'])
                assert len(bacteriophageList) == 1

                #if bacteriophageList[0].qty_proteins > bacteriophageList[1].qty_proteins:
                #    bateriophage_take = 0
                #else:
                #    bateriophage_take = 1
                bateriophage_take = 0
                bacteriophage = bacteriophageList[bateriophage_take]

                organism_code = row['strain_db']
                organism_codeAPI = row['strain_api']

                accNumber = treatAccNumber(bacteriophage.acc_num,
                                           organism_code)
                bacteriophage.acc_num = accNumber
                source_data = bacteriophage.fk_source_data
                person_responsible = bacteriophage.fk_source
                gi_number = treatGiNumber(bacteriophage.gi)
                wholeDNAObj = getWholeGenomById(bacteriophage.fk_whole_genome)
                strain = bacteriophage.fk_strain

                print(strain)

                listProts = getProteinsByOrganism(bacteriophage.id_organism)
                listContigs = getContigsByOrganis(bacteriophage.id_organism)

                if len(listContigs) > 0:
                    dictProts, dictConts = mapProteinsContigs(
                        listProts, listContigs)
                    canInsert, qtyProts = verifyQtyProtContigs(
                        len(listProts), dictProts, dictConts)
                    if canInsert == True:
                        print('Hello Contigs')
                        insertBacteriophageProteinsWholeDNAContigs(
                            bacteriophage, organism_code, wholeDNAObj,
                            dictProts, dictConts)
                    else:
                        writeCSVProteinContigNotEqual(
                            bacteriophage.id_organism, len(listProts),
                            qtyProts)
                        insertBacteriophageProteinsWholeDNA(
                            bacteriophage, organism_code, listProts,
                            wholeDNAObj)
                else:
                    print("Hello")
                    insertBacteriophageProteinsWholeDNA(
                        bacteriophage, organism_code, listProts, wholeDNAObj)

                row_verification = [row['strain_db'], row['strain_api'], 1]
                arrayStates[-1] = row_verification
                writeCSVStateInsertion(arrayStates)
예제 #11
0
def getProteinsDB(id_bacterium):
    bacteriophage = Organism.get_organism_by_id(id_bacterium)
    list_proteins = Protein.get_all_Proteins_by_organism_id(id_bacterium)
    qty_prots_DB = len(list_proteins)

    return qty_prots_DB
예제 #12
0
def load_get_bacterium(pathFile, arrayStates):
    """
    read the CSV with the organism id, strain id and their states. This method call the other for the insertion of the bacterium on the database

    :param pathFile: path of teh CSV file

    :type pathFile: String

    :return: matrix with all the data
    :rtype panda dataframe

    """
    wholeDNA = None
    dataframe = pd.read_csv(pathFile)
    for index, row in dataframe.iterrows():
        print(row['organism_type'])
        if row['organism_type'] == 1:
            row_verification = [[row['strain_db'], row['strain_api'],2]]

            id_strain_API = row['strain_api']
            if id_strain_API not in arrayStates[:, 1]:
                arrayStates = np.append(arrayStates, row_verification, axis=0)
                writeCSVStateInsertion(arrayStates)

                bacteriumList = Organism.get_organism_by_fk_strain(row['strain_db'])
                assert len(bacteriumList) == 1

                bacterium = bacteriumList[0]
                bacterium.acc_num = bacterium.acc_num + '_V2'

                #Test acc_value
                bacterium_existance = checkBacteriumExistsByAcc(bacterium.acc_num)
                #############
                if bacterium_existance is True:
                    print('This acc {0} already exists'.format(bacterium.acc_num))
                    continue



                accNumber = treatAccNumber(bacterium.acc_num)
                source_data = bacterium.fk_source_data
                person_responsible = bacterium.fk_source
                gi_number = treatGiNumber(bacterium.gi)
                wholeDNAObj = getWholeGenomById(bacterium.fk_whole_genome)
                strain = bacterium.fk_strain

                organism_code = row['strain_db']
                organism_codeAPI = row['strain_api']
                listProts = getProteinsByOrganism(bacterium.id_organism)
                listContigs = getContigsByOrganis(bacterium.id_organism)



                if len(listContigs)> 0 and len(listContigs[0].sequence) > 10:
                    dictProts, dictConts = mapProteinsContigs(listProts, listContigs)
                    canInsert, qtyProts = verifyQtyProtContigs(len(listProts),dictProts,dictConts)
                    if canInsert == True:
                        print('Hello)')
                        insertBacteriumProteinsWholeDNAContigs(bacterium, organism_codeAPI, wholeDNAObj, dictProts, dictConts)
                    elif qtyProts == 0:
                        insertBacteriumProteinsWholeDNAContigsNopositions(bacterium, organism_codeAPI, wholeDNAObj, dictProts, dictConts)
                    else:
                        writeCSVProteinContigNotEqual(bacterium.id_organism, len(listProts),qtyProts)
                else:
                    print("Hello")
                    insertBacteriumProteinsWholeDNA(bacterium, organism_codeAPI, listProts, wholeDNAObj)

                row_verification = [row['strain_db'], row['strain_api'],1]
                arrayStates[-1] = row_verification
                writeCSVStateInsertion(arrayStates)