Get dH using Oobatake method in units cal/mol.

    Args:
        seq (str, Seq, SeqRecord): Amino acid sequence
        temp (float): Temperature in degrees C

    Returns:
        float: dH in units cal/mol
480964
def calculate_oobatake_dH(seq, temp):
    

    seq = ssbio.protein.sequence.utils.cast_to_str(seq)

    dH = 0
    temp += 273.15
    T0 = 298.15
    for aa in seq:
        H0 = oobatake_dictionary[aa]['dH'] * 1000
        dH += H0
    return dH + _sum_of_dCp(seq) * (temp - T0)
293490
def cal_p(self, v, temp):
        
        return self.cal_pst(v) + self.cal_pth(v, temp)
1094659
def calculate_oobatake_dG(seq, temp):
    

    dH = calculate_oobatake_dH(seq, temp)
    dS = calculate_oobatake_dS(seq, temp)
    dG = dH - (temp + 273.15) * dS

    # 563.552 - a correction for N- and C-terminal group (approximated from 7 examples in the paper)
    return dG - 563.552
1341677
def write_seq_as_temp_fasta(seq):
    
    sr = ssbio.protein.sequence.utils.cast_to_seq_record(seq, id='tempfasta')
    return write_fasta_file(seq_records=sr, outname='temp', outdir=tempfile.gettempdir(), force_rerun=True)
1195673
def get_seq(self,obj,default=None):
        """"""
        if is_sequence(obj):
            return obj
        if is_number(obj): return [obj]
        if obj is None and default is not None:
            log.warning('using default value (%s)'%(default))
            return self.get_seq(default)
        raise ValueError('expected sequence|number but got %s'%(type(obj)))
1065431
def extract_pp_helices(in_pdb):
    
    t_phi = -75.0
    t_phi_d = 29.0
    t_psi = 145.0
    t_psi_d = 29.0

    pph_dssp = subprocess.check_output(
        [global_settings['dssp']['path'], in_pdb])
    dssp_residues = []
    go = False
    for line in pph_dssp.splitlines():
        if go:
            res_num = int(line[:5].strip())
            chain = line[11:13].strip()
            ss_type = line[16]
            phi = float(line[103:109].strip())
            psi = float(line[109:116].strip())
            dssp_residues.append((res_num, ss_type, chain, phi, psi))
        else:
            if line[2] == '#':
                go = True
            pass
    pp_chains = []
    chain = []
    ch_on = False
    for item in dssp_residues:
        if (item[1] == ' ') and (
            t_phi - t_phi_d < item[3] < t_phi + t_phi_d) and (
            t_psi - t_psi_d < item[4] < t_psi + t_psi_d):
            chain.append(item)
            ch_on = True
        else:
            if ch_on:
                pp_chains.append(chain)
                chain = []
                ch_on = False
    pp_chains = [x for x in pp_chains if len(x) > 1]
    pp_helices = []
    with open(in_pdb, 'r') as pdb:
        pdb_atoms = split_pdb_lines(pdb.read())
    for pp_helix in pp_chains:
        chain_id = pp_helix[0][2]
        res_range = [x[0] for x in pp_helix]
        helix = []
        for atom in pdb_atoms:
            if (atom[2] == "CA") and (
                    atom[5] == chain_id) and (
                    atom[6] in res_range):
                helix.append(tuple(atom[8:11]))
        pp_helices.append(helix)
    return pp_helices
511218
def _get_counts_in_1x(data_is_basepairs):
    
    read_length = float(getattr(config, 'preseq', {}).get('read_length', 0))
    genome_size = getattr(config, 'preseq', {}).get('genome_size')
    if genome_size:
        try:
            genome_size = float(genome_size)
        except ValueError:
            presets = {'hg19_genome': 2897310462,
                       'hg38_genome': 3049315783,
                       'mm10_genome': 2652783500}
            if genome_size in presets:
                genome_size = presets[genome_size]
            else:
                log.warn('The size for genome ' + genome_size + ' is unknown to MultiQC, ' +
                         'please specify it explicitly or choose one of the following: ' +
                         ', '.join(presets.keys()) + '. Falling back to molecule counts.')
                genome_size = None

    if genome_size:
        if data_is_basepairs:
            return genome_size
        elif read_length:
            return genome_size / read_length
    else:
        return None
450820
def get_combo_subseq_within_2_5D(protein, props, within, filter_resnums=None):
        """"""
        if not protein.representative_structure:
            log.error('{}: no representative structure, cannot search for subseq'.format(protein.id))
            return {'subseq_len': 0, 'subseq': None, 'subseq_resnums': []}

        all_resnums = []
        for prop in props:
            tmp_results = protein.get_generic_subseq_within_2_5D(prop_name=prop, within=within,
                                                         filter_resnums=filter_resnums)
            all_resnums.extend(tmp_results['subseq_resnums'])
        final_resnums = list(set(all_resnums))
        sub_id = '{}-{}->{}_within_{}_{}_extracted'.format(protein.representative_structure.id,
                                                           protein.representative_chain,
                                                           protein.representative_sequence.id,
                                                           within, props)
        new_sp = protein.representative_sequence.get_subsequence(resnums=final_resnums, new_id=sub_id,
                                                                 copy_letter_annotations=False)
        return {'subseq_len': len(final_resnums), 'subseq': new_sp, 'subseq_resnums': final_resnums}
987325
def _read_seq_from_fasta(self, fasta, offset, nr_lines):
        
        fasta.seek(offset)
        lines = [fasta.readline().strip() for _ in range(nr_lines)]
        return "".join(lines)
1054676
def get_variance(seq):
    
    m = get_mean(seq)
    return sum((v-m)**2 for v in seq)/float(len(seq))
1299613
def sequence(self):
        
        seq = [x.mol_code for x in self._monomers]
        return ' '.join(seq)
71295
def getScan(self, specId, peptide=None):
        
        sql = self.base_sql + " where sh.SpectrumID = %d and p.Sequence = '%s'"%(int(specId),peptide)
        self.cur.execute(sql)
        i = self.cur.fetchone()
        if not i:
            return None
        scan = self.parseFullScan(i)
        scan.spectrumId = specId
        return scan
876481
def show_seq(clus_obj, index):
    """"""
    current = clus_obj.clus
    clus_seqt = clus_obj.seq
    clus_locit = clus_obj.loci

    itern = 0
    for idc in current.keys():
        itern += 1
        timestamp = str(idc)
        seqListTemp = ()
        f = open("/tmp/"+timestamp+".fa","w")
        for idl in current[idc].loci2seq.keys():
            seqListTemp = list(set(seqListTemp).union(current[idc].loci2seq[idl]))
        maxscore = 0
        for s in seqListTemp:
            score = calculate_size(clus_seqt[s].freq)
            maxscore = max(maxscore,score)
            clus_seqt[s].score = score
            seq = clus_seqt[s]
            f.write(">"+s+"\n"+seq.seq+"\n")
        f.close()

        locilen_sorted = sorted(current[idc].locilen.iteritems(), key = operator.itemgetter(1),reverse = True)
        lmax = clus_locit[locilen_sorted[0][0]]
        f = open("/tmp/"+timestamp+".bed","w")
        f.write("%s\t%s\t%s\t.\t.\t%s\n" % (lmax.chr,lmax.start,lmax.end,lmax.strand))
        f.close()
        os.system("bedtools  getfasta -s -fi "+index+" -bed /tmp/"+timestamp+".bed -fo /tmp/"+timestamp+".pre.fa")
        os.system("bowtie2-build /tmp/"+timestamp+".pre.fa  /tmp/"+timestamp+".pre.ind >/dev/null 2>&1")
        os.system("bowtie2 --rdg 7,3 --mp 4 --end-to-end --no-head --no-sq  -D 20 -R 3 -N 0 -i S,1,0.8 -L 3 -f /tmp/"+timestamp+".pre.ind /tmp/"+timestamp+".fa -S /tmp/"+timestamp+".map  >>bowtie.log 2>&1")
        f = open("/tmp/"+timestamp+".map","r")
        seqpos = {}
        minv = 10000000
        for line in f:
            line = line.strip()
            cols = line.split("\t")
            seqpos[cols[0]] = int(cols[3])
            if minv>int(cols[3]):
                minv = int(cols[3])
        f.close()
        seqpos_sorted = sorted(seqpos.iteritems(), key = operator.itemgetter(1),reverse = False)
        showseq = ""
        showseq_plain = ""
        for (s,pos) in seqpos_sorted:
            ratio = (clus_seqt[s].score*1.0/maxscore*100.0)
            realScore = (math.log(ratio,2)*2)
            if realScore<0:
                realScore = 0
            # "score %s max %s  ratio %s real %.0f" % (clus_seqt[s].score,maxscore,ratio,realScore)
            ##calculate the mean expression of the sequence and change size letter
            showseq_plain += "<br>%s<a style = \"font-size:%.0fpx;\"href = javascript:loadSeq(\"%s\")>%s</a>" % ("".join("." for i in range(pos-1)),realScore+10,s,clus_seqt[s].seq)
            #showseq+ = seqviz.addseq(pos-1,clus_seqt[s].len,clus_seqt[s].seq)
        #current[idc].showseq = showseq
        current[idc].showseq_plain = showseq_plain
        os.system("rm /tmp/"+timestamp+"*")
    clus_obj.clus = current
    clus_obj.seq = clus_seqt
    return clus_obj
956157
def assessOligo(seq):
    '''
    

    '''
    hairpin_out = calcHairpin(seq)
    homodimer_out = calcHomodimer(seq)
    return (hairpin_out, homodimer_out)
1229445
def sequence_molar_extinction_280(seq):
    
    if 'X' in seq:
        warnings.warn(_nc_warning_str, NoncanonicalWarning)
    return sum([residue_ext_280[aa] * n for aa, n in Counter(seq).items()])
1273575
def write_sequences_to_fasta(path, seqs):
    
    from Bio import SeqIO
    from Bio.Seq import Seq
    from Bio.SeqRecord import SeqRecord

    path = Path(path)
    records = []

    for id, seq in seqs.items():
        record = SeqRecord(Seq(seq), id=id, description='')
        records.append(record)

    SeqIO.write(records, str(path), 'fasta')
822974
private Group getNewGroup(String recordName,Character aminoCode1, long seq_id,String groupCode3) {

		Group g = ChemCompGroupFactory.getGroupFromChemCompDictionary(groupCode3);
		if ( g != null && !g.getChemComp().isEmpty()) {
			if ( g instanceof AminoAcidImpl) {
				AminoAcidImpl aa = (AminoAcidImpl) g;
				aa.setId(seq_id);
			} else if ( g instanceof NucleotideImpl) {
				NucleotideImpl nuc =  (NucleotideImpl) g;
				nuc.setId(seq_id);
			} else if ( g instanceof HetatomImpl) {
				HetatomImpl het = (HetatomImpl)g;
				het.setId(seq_id);
			}
			return g;
		}



		Group group;
		if ( recordName.equals("ATOM") ) {
			if (StructureTools.isNucleotide(groupCode3))  {
				// it is a nucleotide
				NucleotideImpl nu = new NucleotideImpl();
				group = nu;
				nu.setId(seq_id);

			} else if (aminoCode1==null || aminoCode1 == StructureTools.UNKNOWN_GROUP_LABEL){
				HetatomImpl h = new HetatomImpl();
				h.setId(seq_id);
				group = h;

			} else {
				AminoAcidImpl aa = new AminoAcidImpl() ;
				aa.setAminoType(aminoCode1);
				aa.setId(seq_id);
				group = aa ;
			}
		}
		else {
			if (StructureTools.isNucleotide(groupCode3))  {
				// it is a nucleotide
				NucleotideImpl nu = new NucleotideImpl();
				group = nu;
				nu.setId(seq_id);
			}
			else if (aminoCode1 != null ) {
				AminoAcidImpl aa = new AminoAcidImpl() ;
				aa.setAminoType(aminoCode1);
				aa.setId(seq_id);
				group = aa ;
			} else {
				HetatomImpl h = new HetatomImpl();
				h.setId(seq_id);
				group = h;
			}
		}
		return  group ;
	}