Alignment with bowtie2.
194759
def align(fastq_file, pair_file, ref_file, names, align_dir, data,
          extra_args=None):
    
    config = data["config"]
    analysis_config = ANALYSIS.get(data["analysis"].lower())
    assert analysis_config, "Analysis %s is not supported by bowtie2" % (data["analysis"])
    out_file = os.path.join(align_dir, "{0}-sort.bam".format(dd.get_sample_name(data)))
    if data.get("align_split"):
        final_file = out_file
        out_file, data = alignprep.setup_combine(final_file, data)
        fastq_file, pair_file = alignprep.split_namedpipe_cls(fastq_file, pair_file, data)
    else:
        final_file = None
    if not utils.file_exists(out_file) and (final_file is None or not utils.file_exists(final_file)):
        with postalign.tobam_cl(data, out_file, pair_file is not None) as (tobam_cl, tx_out_file):
            cl = [config_utils.get_program("bowtie2", config)]
            cl += extra_args if extra_args is not None else []
            cl += ["-q",
                   "-x", ref_file]
            cl += analysis_config.get("params", [])
            if pair_file:
                cl += ["-1", fastq_file, "-2", pair_file]
            else:
                cl += ["-U", fastq_file]
            if names and "rg" in names:
                cl += ["--rg-id", names["rg"]]
                for key, tag in [("sample", "SM"), ("pl", "PL"), ("pu", "PU"), ("lb", "LB")]:
                    if names.get(key):
                        cl += ["--rg", "%s:%s" % (tag, names[key])]
            cl += _bowtie2_args_from_config(config, cl)
            cl = [str(i) for i in cl]
            cmd = "unset JAVA_HOME && " + " ".join(cl) + " | " + tobam_cl
            do.run(cmd, "Aligning %s and %s with Bowtie2." % (fastq_file, pair_file))
    return out_file
931666
def alignment_a(self):
        
        from molmod.transformations import Rotation
        new_x = self.matrix[:, 0].copy()
        new_x /= np.linalg.norm(new_x)
        new_z = np.cross(new_x, self.matrix[:, 1])
        new_z /= np.linalg.norm(new_z)
        new_y = np.cross(new_z, new_x)
        new_y /= np.linalg.norm(new_y)
        return Rotation(np.array([new_x, new_y, new_z]))
1036200
def aligned(e1, e2):
    
    return (
        any(close(c1, c2) for c1, c2 in zip(e1.bbox, e2.bbox))
        or x_center_aligned(e1, e2)
        or y_center_aligned(e1, e2)
    )
915817
def align(value):
        
        if value.value:
            _assert_is_type('shape.value', value.value, str_types)
            if value.value not in PropertySet._valid_align:
                raise ValueError(value.value + ' is not a valid alignment')
732769
private static void updateAlignment(DataLine dataLine, Align alignment)
    {
        if (dataLine.isControlSupported(Type.PAN))
        {
            final FloatControl pan = (FloatControl) dataLine.getControl(Type.PAN);
            switch (alignment)
            {
                case CENTER:
                    pan.setValue(0.0F);
                    break;
                case RIGHT:
                    pan.setValue(1.0F);
                    break;
                case LEFT:
                    pan.setValue(-1.0F);
                    break;
                default:
                    throw new LionEngineException(alignment);
            }
        }
    }
79510
public static final void align(SeekableByteChannel ch, long align) throws IOException
    {
        ch.position(alignedPosition(ch, align));
    }
1041256
public void setAlignment(int alignment) {
        super.setAlignment(alignment);
        for(int i = 0; i < this.content.length; i++) {
            if(this.content[i] instanceof Paragraph) {
                ((Paragraph) this.content[i]).setAlignment(alignment);
            } else if(this.content[i] instanceof Table) {
                ((Table) this.content[i]).setAlignment(alignment);
            } else if(this.content[i] instanceof Image) {
                ((Image) this.content[i]).setAlignment(alignment);
            }     
        }
    }
812981
function cornerLine(p, quadrant, size) {

  switch (quadrant) {
    case Const.top_left: return new Pair(p).to(p.$add(size, size));
    case Const.top_right: return new Pair(p).to(p.$add(-size, size));
    case Const.bottom_left: return new Pair(p).to(p.$add(size, -size));
    case Const.bottom_right: return new Pair(p).to(p.$add(-size, -size));
    case Const.top: return new Pair(p).to(p.$add(0, size));
    case Const.bottom: return new Pair(p).to(p.$add(0, -size));
    case Const.left: return new Pair(p).to(p.$add(size, 0));
    default: return new Pair(p).to(p.$add(-size, 0));
  }
}
160815
def _align_with_substrings(self, chains_to_skip = set()):
        ''''''
        for c in self.representative_chains:
            # Skip specified chains
            if c not in chains_to_skip:
                #colortext.pcyan(c)
                #colortext.warning(self.fasta[c])
                fasta_sequence = self.fasta[c]

                substring_matches = {}

                for uniparc_id, uniparc_sequence in sorted(self.uniparc_sequences.iteritems()):
                    uniparc_sequence = str(uniparc_sequence)
                    idx = uniparc_sequence.find(fasta_sequence)
                    if idx != -1:
                        substring_matches[uniparc_id] = 0
                    elif len(fasta_sequence) > 30:
                        idx = uniparc_sequence.find(fasta_sequence[5:-5])
                        if idx != -1:
                            substring_matches[uniparc_id] = 5
                        else:
                            idx = uniparc_sequence.find(fasta_sequence[7:-7])
                            if idx != -1:
                                substring_matches[uniparc_id] = 7
                    elif len(fasta_sequence) > 15:
                        idx = uniparc_sequence.find(fasta_sequence[3:-3])
                        if idx != -1:
                            substring_matches[uniparc_id] = 3

                self.substring_matches[c] = substring_matches

        # Restrict the matches to a given set of UniParc IDs. This can be used to remove ambiguity when the correct mapping has been determined e.g. from the SIFTS database.
        colortext.pcyan('*' * 100)
        pprint.pprint(self.substring_matches)
        if self.restrict_to_uniparc_values:
            for c in self.representative_chains:
                #print('HERE!')
                #print(c)
                if set(map(str, self.substring_matches[c].keys())).intersection(set(self.restrict_to_uniparc_values)) > 0:
                    # Only restrict in cases where there is at least one match in self.restrict_to_uniparc_values
                    # Otherwise, chains which are not considered in self.restrict_to_uniparc_values may throw away valid matches
                    # e.g. when looking for structures related to 1KTZ (A -> P10600 -> UPI000000D8EC, B -> P37173 -> UPI000011DD7E),
                    #      we find the close match 2PJY. However, 2PJY has 3 chains: A -> P10600, B -> P37173, and C -> P36897 -> UPI000011D62A
                    restricted_matches = dict((str(k), self.substring_matches[c][k]) for k in self.substring_matches[c].keys() if str(k) in self.restrict_to_uniparc_values)
                    if len(restricted_matches) != len(self.substring_matches[c]):
                        removed_matches = sorted(set(self.substring_matches[c].keys()).difference(set(restricted_matches)))
                        # todo: see above re:quiet colortext.pcyan('Ignoring {0} as those chains were not included in the list self.restrict_to_uniparc_values ({1}).'.format(', '.join(removed_matches), ', '.join(self.restrict_to_uniparc_values)))
                    self.substring_matches[c] = restricted_matches
        #pprint.pprint(self.substring_matches)
        #colortext.pcyan('*' * 100)

        # Use the representatives' alignments for their respective equivalent classes
        for c_1, related_chains in self.equivalence_fiber.iteritems():
            for c_2 in related_chains:
                self.substring_matches[c_2] = self.substring_matches[c_1]
977217
protected void adjustHomographSign( PairLineNorm p , DMatrixRMaj H ) {

		CommonOps_DDRM.transpose(H,H_t);

		double val = GeometryMath_F64.innerProd(p.l1, H_t, p.l2);

		if( val < 0 )
			CommonOps_DDRM.scale(-1, H);
	}
1020169
function align(code) {
  if (typeof code === 'string') {
    code = code.split('\n');
  }
  var match = code[code.length-1].match(/^(\s+)\}/);
  var regex = null;
  if (match && code[0].match(/^function/)) {
    regex = new RegExp("^" + match[1]);
    return code.map(function (line) {
      return line.replace(regex, "");
    });
  }
  return code;
}
1004328
def _align_from_fastq(fastq1, fastq2, aligner, align_ref, sam_ref, names,
                      align_dir, data):
    
    config = data["config"]
    align_fn = TOOLS[aligner].align_fn
    out = align_fn(fastq1, fastq2, align_ref, names, align_dir, data)
    # handle align functions that update the main data dictionary in place
    if isinstance(out, dict):
        assert out.get("work_bam"), (dd.get_sample_name(data), out.get("work_bam"))
        return out
    # handle output of raw SAM files that need to be converted to BAM
    else:
        work_bam = bam.sam_to_bam(out, config)
        data["work_bam"] = bam.sort(work_bam, config)
        return data
898540
def align(s1, s2, gap=' ', eq=operator.eq):
    '''

    '''
    # first we compute the dynamic programming table
    m, n = len(s1), len(s2)
    table = []  # the table is extended lazily, one row at a time
    row = list(range(n+1))  # the first row is 0, 1, 2, ..., n
    table.append(list(row))  # copy row and insert into table
    for i in range(m):
        p = i
        row[0] = i+1
        for j in range(n):
            t = 0 if eq(s1[i], s2[j]) else 1
            p, row[j+1] = row[j+1], min(p+t, row[j]+1, row[j+1]+1)
        table.append(list(row))  # copy row and insert into table
    # now we trace the best alignment path from cell [m][n] to cell [0],[0]
    s1_, s2_ = '', ''

    i, j = m, n
    while i != 0 and j != 0:
        _, i, j, s1_, s2_ = min(
            (table[i-1][j-1], i-1, j-1, s1[i-1]+s1_, s2[j-1]+s2_),
            (table[i-1][j], i-1, j, s1[i-1]+s1_, gap+s2_),
            (table[i][j-1], i, j-1, gap+s1_, s2[j-1]+s2_)
        )
    if i != 0:
        s1_ = s1[:i]+s1_
        s2_ = gap*i+s2_
    if j != 0:
        s1_ = gap*j+s1_
        s2_ = s2[:j]+s2_
    return s1_, s2_
928679
public static void alignDatanodes(DatanodeInfo[] dstLocs,
      DatanodeInfo[] srcLocs) {
    for (int i = 0; i < dstLocs.length; i++) {
      for (int j = 0; j < srcLocs.length; j++) {
        if (i == j)
          continue;
        if (dstLocs[i].equals(srcLocs[j])) {
          if (i < j) {
            swap(i, j, srcLocs);
          } else {
            swap(i, j, dstLocs);
          }
          break;
        }
      }
    }
  }
141796
def align_two_alignments(aln1, aln2, moltype, params=None):
    
    #create SequenceCollection object from seqs
    aln1 = Alignment(aln1,MolType=moltype)
    #Create mapping between abbreviated IDs and full IDs
    aln1_int_map, aln1_int_keys = aln1.getIntMap()
    #Create SequenceCollection from int_map.
    aln1_int_map = Alignment(aln1_int_map,MolType=moltype)

    #create Alignment object from aln
    aln2 = Alignment(aln2,MolType=moltype)
    #Create mapping between abbreviated IDs and full IDs
    aln2_int_map, aln2_int_keys = aln2.getIntMap(prefix='seqn_')
    #Create SequenceCollection from int_map.
    aln2_int_map = Alignment(aln2_int_map,MolType=moltype)

    #Update aln1_int_keys with aln2_int_keys
    aln1_int_keys.update(aln2_int_keys)

    #Create Mafft app.
    app = Clustalw(InputHandler='_input_as_multiline_string',\
        params=params,
        SuppressStderr=True)
    app.Parameters['-align'].off()
    app.Parameters['-infile'].off()
    app.Parameters['-profile'].on()

    #Add aln_int_map as profile1
    app.Parameters['-profile1'].on(\
        app._tempfile_as_multiline_string(aln1_int_map.toFasta()))

    #Add seq_int_map as profile2
    app.Parameters['-profile2'].on(\
        app._tempfile_as_multiline_string(aln2_int_map.toFasta()))
    #Get results using int_map as input to app
    res = app()

    #Get alignment as dict out of results
    alignment = dict(ClustalParser(res['Align'].readlines()))

    #Make new dict mapping original IDs
    new_alignment = {}
    for k,v in alignment.items():
        new_alignment[aln1_int_keys[k]]=v
    #Create an Alignment object from alignment dict
    new_alignment = Alignment(new_alignment,MolType=moltype)
    #Clean up
    res.cleanUp()
    remove(app.Parameters['-profile1'].Value)
    remove(app.Parameters['-profile2'].Value)
    del(aln1,aln1_int_map,aln1_int_keys,\
        aln2,aln2_int_map,aln2_int_keys,app,res,alignment)

    return new_alignment
447423
public Collection<BindingsBean> align(String imgfile1,    String imglabel, 
                                          String hdrfile1,    String hdrlabel,
                                          String imgreffile1, String imgreflabel, 
                                          String hdrreffile1, String hdrreflabel, 
                                          String activity, 
                                          String warpfile,    String warplabel,
                                          String workflow,    String agent)  {

        AlignBindingsBean bean=new AlignBindingsBean(pFactory);

        bean.addConsumed1(pc(imgfile1));
        bean.addConsumed2(pc(hdrfile1));
        bean.addConsumed3(pc(imgreffile1));
        bean.addConsumed4(pc(hdrreffile1));

        bean.addConsumedLabel1(imglabel);
        bean.addConsumedLabel2(hdrlabel);
        bean.addConsumedLabel3(imgreflabel);
        bean.addConsumedLabel4(hdrreflabel);

        bean.addBlockInstance(pc(activity));

        bean.addProduced(pc(warpfile));
        bean.addProducedLabel(warplabel);

        bean.addParent(pc(workflow));
        bean.addAgent(pc(agent));

        BindingsBean bb=bean;
        return Collections.singleton(bb);
    }
832792
def align_pipe(fastq_file, pair_file, ref_file, names, align_dir, data):
    
    pair_file = pair_file if pair_file else ""
    # back compatible -- older files were named with lane information, use sample name now
    out_file = os.path.join(align_dir, "{0}-sort.bam".format(names["lane"]))
    if not utils.file_exists(out_file):
        out_file = os.path.join(align_dir, "{0}-sort.bam".format(dd.get_sample_name(data)))
    if data.get("align_split") or fastq_file.endswith(".sdf"):
        final_file = out_file
        out_file, data = alignprep.setup_combine(final_file, data)
        fastq_file, pair_file = alignprep.split_namedpipe_cls(fastq_file, pair_file, data)
    else:
        final_file = None
    samtools = config_utils.get_program("samtools", data["config"])
    novoalign = config_utils.get_program("novoalign", data["config"])
    resources = config_utils.get_resources("novoalign", data["config"])
    num_cores = data["config"]["algorithm"].get("num_cores", 1)
    max_mem = resources.get("memory", "1G")
    extra_novo_args = " ".join(_novoalign_args_from_config(data["config"]))
    rg_info = get_rg_info(names)
    if not utils.file_exists(out_file) and (final_file is None or not utils.file_exists(final_file)):
        with tx_tmpdir(data) as work_dir:
            with postalign.tobam_cl(data, out_file, pair_file != "") as (tobam_cl, tx_out_file):
                tx_out_prefix = os.path.splitext(tx_out_file)[0]
                cmd = ("unset JAVA_HOME && "
                       "{novoalign} -o SAM '{rg_info}' -d {ref_file} -f {fastq_file} {pair_file} "
                       "  -c {num_cores} {extra_novo_args} | ")
                cmd = (cmd + tobam_cl).format(**locals())
                do.run(cmd, "Novoalign: %s" % names["sample"], None,
                       [do.file_nonempty(tx_out_file), do.file_reasonable_size(tx_out_file, fastq_file)])
    data["work_bam"] = out_file
    return data