prototype/nplinker/pairedomics/downloader.py
def _resolve_genbank_accession(self, genbank_id):
        """
        Super hacky way of trying to resolve the GenBank accession into RefSeq accession.
        """
        logger.info('Attempting to resolve RefSeq accession from Genbank accession {}'.format(genbank_id))
        # genbank id => genbank seq => refseq

        # The GenBank accession can have several formats:
        # 1: BAFR00000000.1
        # 2: NZ_BAGG00000000.1
        # 3: NC_016887.1
        # Case 1 is the default.
        if '_' in genbank_id:
            # case 2
            if len(genbank_id.split('_')[-1].split('.')[0]) == 12:
                genbank_id = genbank_id.split('_')[-1]
            # case 3
            else:
                genbank_id = genbank_id.lower() 

        # Look up genbank ID
        try:
            url = NCBI_GENBANK_LOOKUP_URL.format(genbank_id)
            resp = httpx.get(url)
            soup = BeautifulSoup(resp.content, 'html.parser')
            ids = soup.find('dl', {'class': 'rprtid'})
            for field_idx, field in enumerate(ids.findChildren()):
                if field.getText().strip() == 'GI:':
                    seq_id = ids.findChildren()[field_idx + 1].getText().strip()
                    break

            # Look up assembly
            url = NCBI_ASSEMBLY_LOOKUP_URL.format(seq_id)
            resp = httpx.get(url)
            soup = BeautifulSoup(resp.content, 'html.parser')
            title_href = soup.find('p', {'class': 'title'}).a['href']
            refseq_id = title_href.split('/')[-1].split('.')[0]
            return refseq_id
        except Exception as e:
            logger.warning('Failed resolving GenBank accession {}, error {}'.format(genbank_id, e))

        return None

        Super hacky way of trying to resolve the GenBank accession into RefSeq accession.
        
Super hacky way of trying to resolve the GenBank accession into RefSeq accession.
Super hacky way of trying to resolve the GenBank accession into RefSeq accession .
def _resolve_genbank_accession(self, genbank_id):
        logger.info('Attempting to resolve RefSeq accession from Genbank accession {}'.format(genbank_id))
        if '_' in genbank_id:
            if len(genbank_id.split('_')[-1].split('.')[0]) == 12:
                genbank_id = genbank_id.split('_')[-1]
            else:
                genbank_id = genbank_id.lower() 
        try:
            url = NCBI_GENBANK_LOOKUP_URL.format(genbank_id)
            resp = httpx.get(url)
            soup = BeautifulSoup(resp.content, 'html.parser')
            ids = soup.find('dl', {'class': 'rprtid'})
            for field_idx, field in enumerate(ids.findChildren()):
                if field.getText().strip() == 'GI:':
                    seq_id = ids.findChildren()[field_idx + 1].getText().strip()
                    break
            url = NCBI_ASSEMBLY_LOOKUP_URL.format(seq_id)
            resp = httpx.get(url)
            soup = BeautifulSoup(resp.content, 'html.parser')
            title_href = soup.find('p', {'class': 'title'}).a['href']
            refseq_id = title_href.split('/')[-1].split('.')[0]
            return refseq_id
        except Exception as e:
            logger.warning('Failed resolving GenBank accession {}, error {}'.format(genbank_id, e))
        return None
def _resolve_genbank_accession ( self , genbank_id ) : logger . info ( 'Attempting to resolve RefSeq accession from Genbank accession {}' . format ( genbank_id ) ) if '_' in genbank_id : if len ( genbank_id . split ( '_' ) [ - 1 ] . split ( '.' ) [ 0 ] ) == 12 : genbank_id = genbank_id . split ( '_' ) [ - 1 ] else : genbank_id = genbank_id . lower ( ) try : url = NCBI_GENBANK_LOOKUP_URL . format ( genbank_id ) resp = httpx . get ( url ) soup = BeautifulSoup ( resp . content , 'html.parser' ) ids = soup . find ( 'dl' , { 'class' : 'rprtid' } ) for field_idx , field in enumerate ( ids . findChildren ( ) ) : if field . getText ( ) . strip ( ) == 'GI:' : seq_id = ids . findChildren ( ) [ field_idx + 1 ] . getText ( ) . strip ( ) break url = NCBI_ASSEMBLY_LOOKUP_URL . format ( seq_id ) resp = httpx . get ( url ) soup = BeautifulSoup ( resp . content , 'html.parser' ) title_href = soup . find ( 'p' , { 'class' : 'title' } ) . a [ 'href' ] refseq_id = title_href . split ( '/' ) [ - 1 ] . split ( '.' ) [ 0 ] return refseq_id except Exception as e : logger . warning ( 'Failed resolving GenBank accession {}, error {}' . format ( genbank_id , e ) ) return None
Super hacky way of trying to resolve the GenBank accession into RefSeq accession.
Super hacky way of trying to resolve the GenBank accession into RefSeq accession .
"""
        Super hacky way of trying to resolve the GenBank accession into RefSeq accession.
        """ # genbank id => genbank seq => refseq # The GenBank accession can have several formats: # 1: BAFR00000000.1 # 2: NZ_BAGG00000000.1 # 3: NC_016887.1 # Case 1 is the default. # case 2 # case 3 # Look up genbank ID # Look up assembly
self
genbank_id