#NEWLINE# def seqid_parse( seqid , sep = [ '-' , '_' ] , stdpf = True ) : #NEWLINE# #INDENT# '\n    This function tries to parse seqid (1st col in bed files)\n    return prefix, numeric id, and suffix, for example:\n\n    >>> seqid_parse(\'chr1_random\')\n    (\'Chr\', \'1\', \'_random\')\n    >>> seqid_parse(\'AmTr_v1.0_scaffold00001\', \'\', stdpf=False)\n    (\'AmTr_v1.0_scaffold\', \'00001\', \'\')\n    >>> seqid_parse(\'AmTr_v1.0_scaffold00001\')\n    (\'Sca\', \'00001\', \'\')\n    >>> seqid_parse(\'PDK_30s1055861\')\n    (\'C\', \'1055861\', \'\')\n    >>> seqid_parse(\'PDK_30s1055861\', stdpf=False)\n    (\'PDK\', \'1055861\', \'\')\n    >>> seqid_parse("AC235758.1", stdpf=False)\n    (\'AC\', \'235758.1\', \'\')\n    ' #NEWLINE# if ( ( 'mito' in seqid ) or ( 'chloro' in seqid ) ) : #NEWLINE# #INDENT# return ( seqid , '' , '' ) #NEWLINE# #UNINDENT# numbers = re . findall ( '\\d+\\.*\\d*' , seqid ) #NEWLINE# if ( not sep ) : #NEWLINE# #INDENT# return ( seqid , '' , '' ) #NEWLINE# #UNINDENT# id = numbers [ ( - 1 ) ] #NEWLINE# lastnumi = seqid . rfind ( id ) #NEWLINE# suffixi = ( lastnumi + len ( id ) ) #NEWLINE# suffix = seqid [ suffixi : ] #NEWLINE# if ( sep is None ) : #NEWLINE# #INDENT# sep = [ '' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( type ( sep ) == str ) : #NEWLINE# #INDENT# sep = [ sep ] #NEWLINE# #UNINDENT# #UNINDENT# prefix = seqid [ : lastnumi ] #NEWLINE# if ( not stdpf ) : #NEWLINE# #INDENT# sep = '|' . join ( sep ) #NEWLINE# atoms = re . split ( sep , prefix ) #NEWLINE# if ( len ( atoms ) == 1 ) : #NEWLINE# #INDENT# prefix = atoms [ 0 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# prefix = atoms [ ( - 2 ) ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if re . findall ( 'chr' , prefix , re . I ) : #NEWLINE# #INDENT# prefix = 'Chr' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if re . findall ( 'sca' , prefix , re . I ) : #NEWLINE# #INDENT# prefix = 'Sca' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if re . findall ( 'supercontig' , prefix , re . I ) : #NEWLINE# #INDENT# prefix = 'SCg' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if re . findall ( 'ctg|contig' , prefix , re . I ) : #NEWLINE# #INDENT# prefix = 'Ctg' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if re . findall ( 'BAC' , prefix , re . I ) : #NEWLINE# #INDENT# prefix = 'BAC' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# prefix = 'C' #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return ( prefix , id , suffix )