def get_dict_from_unfiltered_with_sequences(self) -> dict: try: dict_with_genes = {} mongo_dao_retriever = GeneDAO( MongoClient(Constants.MONGODB_HOST, Constants.MONGODB_PORT), Constants.MONGODB_DB_NAME, Constants.MONGODB_COLLECTION_UNFILTERED) dict_with_genes = mongo_dao_retriever.get_all_gene_objects_as_dict( ) deep_copy_dict_with_genes = deepcopy(dict_with_genes) for id_gene, sequence in deep_copy_dict_with_genes.items(): if sequence is None: del dict_with_genes[id_gene] return dict_with_genes except Exception as error: print('Caught exception getting unfiltered sequences (to dict):' + repr(error))
def get_list_of_ids_from_mongo_without_sequence(self) -> list: list_of_just_ids = None try: list_of_just_ids = [] mongo_dao_retriever = GeneDAO( MongoClient(Constants.MONGODB_HOST, Constants.MONGODB_PORT), Constants.MONGODB_DB_NAME, Constants.MONGODB_COLLECTION_UNFILTERED) list_of_gene_objets = mongo_dao_retriever.get_all_gene_objects_as_list( ) for gene_object in list_of_gene_objets: if gene_object.sequence is None: gene_id = gene_object.gene_id list_of_just_ids.append(gene_id) return list_of_just_ids except Exception as error: print( 'Caught exception when getting all ids from mongo as list without sequence (unfiltered): ' + repr(error))
def delete_filtered_collection(self) -> None: try: mongo_dao_retriever_filtered = GeneDAO( MongoClient(Constants.MONGODB_HOST, Constants.MONGODB_PORT), Constants.MONGODB_DB_NAME, Constants.MONGODB_COLLECTION_FILTERED) mongo_dao_retriever_filtered.delete_collection() except Exception as error: print('Caught exception when removing filtered collection' + repr(error))
def insert_filtered_dict_in_filtered_collection( self, filtered_dict: dict) -> None: try: mongo_dao_manager = GeneDAO( MongoClient(Constants.MONGODB_HOST, Constants.MONGODB_PORT), Constants.MONGODB_DB_NAME, Constants.MONGODB_COLLECTION_FILTERED) mongo_dao_manager.insert_gene_document_from_non_object_dict( filtered_dict) except Exception as error: print( 'Caught exception while inserting filtered sequences in mongo collection' + repr(error))
def update_genes_from_dict(self, dict_of_genes: dict) -> None: try: if dict_of_genes is not None: mongo_dao_retriever = GeneDAO( MongoClient(Constants.MONGODB_HOST, Constants.MONGODB_PORT), Constants.MONGODB_DB_NAME, Constants.MONGODB_COLLECTION_UNFILTERED) for id_ncbi, sequence in dict_of_genes.items(): ncbi_object_to_update = GeneDTO() ncbi_object_to_update.gene_id = id_ncbi ncbi_object_to_update.sequence = sequence mongo_dao_retriever.update_gene_element_from_object( ncbi_object_to_update, False) except Exception as error: print( 'Caught exception when getting all ids from mongo as list: ' + repr(error))
def export_filtered_genes_collection_to_fasta(self, fasta_name: str) -> None: try: mongo_dao_retriever = GeneDAO( MongoClient(Constants.MONGODB_HOST, Constants.MONGODB_PORT), Constants.MONGODB_DB_NAME, Constants.MONGODB_COLLECTION_FILTERED) list_of_seqrecords = mongo_dao_retriever.get_list_of_seqrecords_from_collection( ) if list_of_seqrecords is None: print(Constants.MSG_WARNING_FILTERED_COLLECTION_EMPTY) raise Exception SeqIO.write(list_of_seqrecords, fasta_name + ".fasta", "fasta") except Exception as error: print( 'Caught exception when exporting all data to fasta from filtered collection: ' + repr(error))