예제 #1
0
파일: msa.py 프로젝트: yohell/msaview
 def run(self):
     pos = RegionSelection()
     seq = RegionSelection()
     _pos = iter(self.target.selection.positions.regions)
     _seq = iter(self.target.selection.sequences.regions)
     _areas = (a.positions for a in self.target.selection.areas.areas)
     for pos_region in sorted(chain(_pos, _areas), key=lambda r: r.start):
         pos.incorporate(pos_region)
     for seq_region in sorted(chain(_seq, _areas), key=lambda r: r.start):
         seq.incorporate(seq_region)
     if not pos.regions:
         pos.add_region(0, len(self.target))
     if not seq.regions:
         seq.add_region(0, len(self.target.sequences))
     sequences = [list() for _ in range(sum(r.length for r in seq.regions))]
     ids = [None] * len(sequences) 
     descriptions = [None] * len(sequences)
     new_index = -1
     for seq_region in seq.regions:
         for i, sequence in enumerate(self.target.sequences[seq_region.start:seq_region.start + seq_region.length]):
             new_index += 1
             sequences[new_index] = ''.join(sequence[r.start:r.start+r.length] for r in pos.regions)
             ids[new_index] = self.target.ids[seq_region.start + i]
             descriptions[new_index] = self.target.ids[seq_region.start + i]
     self.target.selection.positions.clear()
     self.target.selection.sequences.clear()
     self.target.selection.areas.clear()
     path = self.target.path.strip('*') + '*'
     self.target.set_msa(sequences, path, ids, descriptions)
예제 #2
0
파일: msa.py 프로젝트: yohell/msaview
 def run(self):
     sel = RegionSelection()
     positions = iter(self.target.selection.positions.regions)
     areas = (a.positions for a in self.target.selection.areas.areas)
     for region in sorted(chain(positions, areas), key=lambda r: r.start):
         sel.incorporate(region)
     sel.invert(len(self.target))
     sequences = []
     for sequence in self.target.sequences:
         sequences.append(''.join(sequence[r.start:r.start+r.length] for r in sel.regions))
     self.target.selection.positions.clear()
     self.target.selection.areas.clear()
     path = self.target.path.strip('*') + '*'
     self.target.set_msa(sequences, path, self.target.ids, self.target.descriptions)