Multiple selection and Merge Selection
Wang-Lin-boop opened this issue · 5 comments
can we use collectresidues to select multiple region of protein? such as :
domain = collectresidues(chain, res -> (13 <= resnumber(res) <= 436) || (504 <= resnumber(res) <= 534), allselector)
or try to merge different selections to a new selection?
Yes you can do it as you have by using ||
in the selector. You can merge selections by defining them as functions:
selector1(res) = 13 <= resnumber(res) <= 436
selector2(res) = 504 <= resnumber(res) <= 534
combinedselector(res) = selector1(res) || selector2(res)
domain = collectresidues(chain, combinedselector)
I deleted the allselector
as it doesn't do anything here.
yeah, I have found this method about ||
.
and I wanna select many fragments and merge them into one domain.
firstly, I test it in REPL:
for domain_range in split(domain_vec,",")
frag_N = parse(Int64,split(domain_range,"-")[1])
frag_C = parse(Int64,split(domain_range,"-")[2])
( length(domain_selection) == 0 ) && (domain_selection = "($frag_N <= resnumber(res) <= $frag_C)" )
( length(domain_selection) == 0 ) || (domain_selection = "$(domain_selection) || ( $frag_N <= resnumber(res) <= $frag_C)" )
end
println(domain_selection)
# (13 <= resnumber(res) <= 436) || ( 13 <= resnumber(res) <= 436) || ( 504 <= resnumber(res) <= 534) || ( 655 <= resnumber(res) <= 682)
domain_str = collectresidues(chain, res -> ("$(domain_selection)"), allselector)
writepdb("$output_dir/$pdb_name-$model_num-$chain_id-$domain_id.pdb", domain_str)
however, an error occured that:
nested task error: TypeError: non-boolean (var"#12#13") used in boolean context
I think that it may be caused by the inappropriate statement construction. Even after I replace the res -> ("$(domain_selection)")
to Meta.parse("res -> (\"$(domain_selection)\")") |> eval
or res -> ( eval(domain_selection) )
, it still doesn't work....
I would just form a Vector
or Set
of all residue numbers in the domain (domain_res
) and then do:
domain_selector(res) = resnumber(res) in domain_res
wow, a great idea!
for domain_ddd in readlines("$index_dir/$pdb_name-$model_num-$chain_id-domain.info")
domain_id = split(domain_ddd,":")[1]
domain_vec = split(domain_ddd,":")[2]
com_id = 0
domain_selection = []
for domain_range in split(domain_vec,",")
frag_N = parse(Int64,split(domain_range,"-")[1])
frag_C = parse(Int64,split(domain_range,"-")[2])
for resi in frag_N:frag_C
push!(domain_selection, resi)
end
end
domain_str = collectresidues(chain, res -> resnumber(res) in domain_selection , allselector)
writepdb("$output_dir/$pdb_name-$model_num-$chain_id-$domain_id.pdb", domain_str)
end
It works now! Thanks, Greener~